BNX2X: Fixes atomic_cmpxchg spatch
authorBarret Rhoden <brho@cs.berkeley.edu>
Tue, 24 Feb 2015 17:24:03 +0000 (12:24 -0500)
committerBarret Rhoden <brho@cs.berkeley.edu>
Mon, 2 Mar 2015 16:59:10 +0000 (11:59 -0500)
The spatch was wrong.  Linux returns the old value on success and appears to
return the current value on failure.  No sense spatching that.

kern/drivers/net/bnx2x/akaros_compat.h
kern/drivers/net/bnx2x/bnx2x_sp.c
scripts/spatch/linux/sync.cocci

index d0c18a2..925d4cb 100644 (file)
 #define RCU_INIT_POINTER(dst, src) rcu_assign_pointer(dst, src)
 #define synchronize_rcu()
 
+#define atomic_cmpxchg(_addr, _old, _new)                                      \
+({                                                                             \
+       typeof(_old) _ret;                                                         \
+       if (atomic_cas((_addr), (_old), (_new)))                                   \
+               _ret = _old;                                                           \
+       else                                                                       \
+               _ret = atomic_read(_addr);                                             \
+       _ret;                                                                      \
+})
+
 #define unlikely(x) (x)
 #define likely(x) (x)
 #define UINT_MAX UINT64_MAX
index 0c941c1..6ef4834 100644 (file)
@@ -3718,7 +3718,7 @@ static inline bool __atomic_add_ifless(atomic_t *v, int a, int u)
                if (unlikely(c + a >= u))
                        return false;
 
-               old = atomic_cas((v), c, c + a);
+               old = atomic_cmpxchg((v), c, c + a);
                if (likely(old == c))
                        break;
                c = old;
@@ -3746,7 +3746,7 @@ static inline bool __atomic_dec_ifmoe(atomic_t *v, int a, int u)
                if (unlikely(c - a < u))
                        return false;
 
-               old = atomic_cas((v), c, c - a);
+               old = atomic_cmpxchg((v), c, c - a);
                if (likely(old == c))
                        break;
                c = old;
index 09f1797..93efcae 100644 (file)
@@ -50,11 +50,3 @@ expression VARP;
 @@
 -atomic_add(AMT, VARP)
 +atomic_add(VARP, AMT)
-
-@@
-expression VARP;
-expression OLD;
-expression NEW;
-@@
--atomic_cmpxchg(VARP, OLD, NEW)
-+atomic_cas(VARP, OLD, NEW)