cxl: Fix wrong comparison in cxl_adapter_context_get()
authorVaibhav Jain <[email protected]>
Wed, 4 Jul 2018 15:28:33 +0000 (20:58 +0530)
committerMichael Ellerman <[email protected]>
Thu, 19 Jul 2018 11:58:11 +0000 (21:58 +1000)
Function atomic_inc_unless_negative() returns a bool to indicate
success/failure. However cxl_adapter_context_get() wrongly compares
the return value against '>=0' which will always be true. The patch
fixes this comparison to '==0' there by also fixing this compile time
warning:

drivers/misc/cxl/main.c:290 cxl_adapter_context_get()
warn: 'atomic_inc_unless_negative(&adapter->contexts_num)' is unsigned

Fixes: 70b565bbdb91 ("cxl: Prevent adapter reset if an active context exists")
Cc: [email protected] # v4.9+
Reported-by: Dan Carpenter <[email protected]>
Signed-off-by: Vaibhav Jain <[email protected]>
Acked-by: Andrew Donnellan <[email protected]>
Acked-by: Frederic Barrat <[email protected]>
Signed-off-by: Michael Ellerman <[email protected]>
drivers/misc/cxl/main.c

index 334223b802eecb8ba497c4671ac9274cde36c88b..f35406be465a5a75bf9132c0cd2f1df5a360bb52 100644 (file)
@@ -282,7 +282,7 @@ int cxl_adapter_context_get(struct cxl *adapter)
        int rc;
 
        rc = atomic_inc_unless_negative(&adapter->contexts_num);
-       return rc >= 0 ? 0 : -EBUSY;
+       return rc ? 0 : -EBUSY;
 }
 
 void cxl_adapter_context_put(struct cxl *adapter)