linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: linux-kernel@vger.kernel.org
Cc: linux-arch@vger.kernel.org,
	Mathieu Lacage <mathieu.lacage@sophia.inria.fr>,
	Mathieu Lacage <mathieu.lacage@inria.fr>,
	Arnd Bergmann <arnd@arndb.de>
Subject: [PATCH 1/6] asm-generic: make atomic_add_unless a function
Date: Sat,  9 Oct 2010 21:57:47 +0200	[thread overview]
Message-ID: <1286654272-21483-2-git-send-email-arnd@arndb.de> (raw)
In-Reply-To: <1286654272-21483-1-git-send-email-arnd@arndb.de>

From: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>

atomic_add_unless is a macro so, bad things happen if the caller defines
a local variable named c, just like like the local variable c defined by
the macro. Thus, convert atomic_add_unless to a function. (bug triggered
by net/ipv4/netfilter/ipt_CLUSTERIP.c: clusterip_config_find_get calls
atomic_inc_not_zero)

Signed-off-by: Mathieu Lacage <mathieu.lacage@inria.fr>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 include/asm-generic/atomic.h |   34 +++++++++++++++++-----------------
 1 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
index e53347f..a6cc019 100644
--- a/include/asm-generic/atomic.h
+++ b/include/asm-generic/atomic.h
@@ -119,14 +119,23 @@ static inline void atomic_dec(atomic_t *v)
 #define atomic_dec_and_test(v)		(atomic_sub_return(1, (v)) == 0)
 #define atomic_inc_and_test(v)		(atomic_add_return(1, (v)) == 0)
 
-#define atomic_add_unless(v, a, u)				\
-({								\
-	int c, old;						\
-	c = atomic_read(v);					\
-	while (c != (u) && (old = atomic_cmpxchg((v), c, c + (a))) != c) \
-		c = old;					\
-	c != (u);						\
-})
+#define atomic_xchg(ptr, v)		(xchg(&(ptr)->counter, (v)))
+#define atomic_cmpxchg(v, old, new)	(cmpxchg(&((v)->counter), (old), (new)))
+
+#define cmpxchg_local(ptr, o, n)				  	       \
+	((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
+			(unsigned long)(n), sizeof(*(ptr))))
+
+#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
+
+static inline int atomic_add_unless(atomic_t *v, int a, int u)
+{
+  int c, old;
+  c = atomic_read(v);
+  while (c != u && (old = atomic_cmpxchg(v, c, c + a)) != c)
+    c = old;
+  return c != u;
+}
 
 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
 
@@ -140,15 +149,6 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
 	raw_local_irq_restore(flags);
 }
 
-#define atomic_xchg(ptr, v)		(xchg(&(ptr)->counter, (v)))
-#define atomic_cmpxchg(v, old, new)	(cmpxchg(&((v)->counter), (old), (new)))
-
-#define cmpxchg_local(ptr, o, n)				  	       \
-	((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
-			(unsigned long)(n), sizeof(*(ptr))))
-
-#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
-
 /* Assume that atomic operations are already serializing */
 #define smp_mb__before_atomic_dec()	barrier()
 #define smp_mb__after_atomic_dec()	barrier()
-- 
1.7.1

  reply	other threads:[~2010-10-09 19:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-09 19:57 [PATCH 0/6] asm-generic updates for 2.6.37 Arnd Bergmann
2010-10-09 19:57 ` Arnd Bergmann [this message]
2010-10-09 19:57   ` [PATCH 1/6] asm-generic: make atomic_add_unless a function Arnd Bergmann
2010-10-09 19:57 ` [PATCH 2/6] asm-generic: cmpxchg does not handle non-long arguments Arnd Bergmann
2010-10-09 19:57   ` Arnd Bergmann
2010-10-09 19:57 ` [PATCH 3/6] asm-generic: fcntl: make exported headers use strict posix types Arnd Bergmann
2010-10-09 19:57   ` Arnd Bergmann
2010-10-09 19:57 ` [PATCH 4/6] asm-generic: kdebug.h: Checkpatch cleanup Arnd Bergmann
2010-10-09 19:57   ` Arnd Bergmann
2010-10-09 19:57 ` [PATCH 5/6] bitops: make asm-generic/bitops/find.h more generic Arnd Bergmann
2010-10-09 19:57   ` Arnd Bergmann
2010-10-09 19:57 ` [PATCH 6/6] bitops: remove duplicated extern declarations Arnd Bergmann
2010-10-09 19:57   ` Arnd Bergmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1286654272-21483-2-git-send-email-arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.lacage@inria.fr \
    --cc=mathieu.lacage@sophia.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).