linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] asm-generic: cmpxchg: avoid warnings from macro-ized cmpxchg() implementations
@ 2015-09-19  4:42 Marek Vasut
  2015-10-01 14:06 ` Ley Foon Tan
  2015-10-14 15:01 ` Arnd Bergmann
  0 siblings, 2 replies; 4+ messages in thread
From: Marek Vasut @ 2015-09-19  4:42 UTC (permalink / raw)
  To: linux-kernel; +Cc: lftan, arnd, linux-arch, Marek Vasut, Russell King

This change is similar to e001bbae7147b111fe1aa42beaf835635f3c016e
ARM: cmpxchg: avoid warnings from macro-ized cmpxchg() implementations

A recent change in kernel/acct.c added a new warning for many
configurations using generic __xchg() implementation:

In file included from ./arch/nios2/include/asm/cmpxchg.h:12:0,
                 from include/asm-generic/atomic.h:18,
                 from arch/nios2/include/generated/asm/atomic.h:1,
                 from include/linux/atomic.h:4,
                 from include/linux/spinlock.h:406,
                 from include/linux/mmzone.h:7,
                 from include/linux/gfp.h:5,
                 from include/linux/mm.h:9,
                 from kernel/acct.c:46:
kernel/acct.c: In function 'acct_pin_kill':
include/asm-generic/cmpxchg.h:94:3: warning: value computed is not used [-Wunused-value]
  ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
   ^
include/asm-generic/cmpxchg.h:102:28: note: in expansion of macro 'cmpxchg_local'
 #define cmpxchg(ptr, o, n) cmpxchg_local((ptr), (o), (n))
                            ^
kernel/acct.c:177:2: note: in expansion of macro 'cmpxchg'
  cmpxchg(&acct->ns->bacct, pin, NULL);
  ^

The code is in fact correct, it's just a cmpxchg() call that
intentionally ignores the result, and no other code does that.  The
warning does not show up on x86 because of the way that its cmpxchg()
macro is written. This changes the asm-ggeneric implementation to use
a similar construct with a compound expression instead of a typecast,
which causes the compiler to not complain about an unused result.

Fix the other macros in this file in a similar way, and place them
just below their function implementations.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Russell King <rmk+kernel@arm.linux.org.uk>
---
 include/asm-generic/cmpxchg.h | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/include/asm-generic/cmpxchg.h b/include/asm-generic/cmpxchg.h
index 3766ab3..e5f9080 100644
--- a/include/asm-generic/cmpxchg.h
+++ b/include/asm-generic/cmpxchg.h
@@ -79,8 +79,10 @@ unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
 	}
 }
 
-#define xchg(ptr, x) \
-	((__typeof__(*(ptr))) __xchg((unsigned long)(x), (ptr), sizeof(*(ptr))))
+#define xchg(ptr, x) ({							\
+	((__typeof__(*(ptr)))						\
+		__xchg((unsigned long)(x), (ptr), sizeof(*(ptr))));	\
+})
 
 #endif /* xchg */
 
@@ -90,9 +92,10 @@ unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
 #include <asm-generic/cmpxchg-local.h>
 
 #ifndef cmpxchg_local
-#define cmpxchg_local(ptr, o, n)				  	       \
+#define cmpxchg_local(ptr, o, n) ({					       \
 	((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
-			(unsigned long)(n), sizeof(*(ptr))))
+			(unsigned long)(n), sizeof(*(ptr))));		       \
+})
 #endif
 
 #ifndef cmpxchg64_local
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] asm-generic: cmpxchg: avoid warnings from macro-ized cmpxchg() implementations
  2015-09-19  4:42 [PATCH] asm-generic: cmpxchg: avoid warnings from macro-ized cmpxchg() implementations Marek Vasut
@ 2015-10-01 14:06 ` Ley Foon Tan
  2015-10-14 15:01 ` Arnd Bergmann
  1 sibling, 0 replies; 4+ messages in thread
From: Ley Foon Tan @ 2015-10-01 14:06 UTC (permalink / raw)
  To: Marek Vasut
  Cc: linux-kernel@vger.kernel.org, Arnd Bergmann, Linux-Arch,
	Russell King

On Sat, Sep 19, 2015 at 12:42 PM, Marek Vasut <marex@denx.de> wrote:
> This change is similar to e001bbae7147b111fe1aa42beaf835635f3c016e
> ARM: cmpxchg: avoid warnings from macro-ized cmpxchg() implementations
>
> A recent change in kernel/acct.c added a new warning for many
> configurations using generic __xchg() implementation:
>
> In file included from ./arch/nios2/include/asm/cmpxchg.h:12:0,
>                  from include/asm-generic/atomic.h:18,
>                  from arch/nios2/include/generated/asm/atomic.h:1,
>                  from include/linux/atomic.h:4,
>                  from include/linux/spinlock.h:406,
>                  from include/linux/mmzone.h:7,
>                  from include/linux/gfp.h:5,
>                  from include/linux/mm.h:9,
>                  from kernel/acct.c:46:
> kernel/acct.c: In function 'acct_pin_kill':
> include/asm-generic/cmpxchg.h:94:3: warning: value computed is not used [-Wunused-value]
>   ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
>    ^
> include/asm-generic/cmpxchg.h:102:28: note: in expansion of macro 'cmpxchg_local'
>  #define cmpxchg(ptr, o, n) cmpxchg_local((ptr), (o), (n))
>                             ^
> kernel/acct.c:177:2: note: in expansion of macro 'cmpxchg'
>   cmpxchg(&acct->ns->bacct, pin, NULL);
>   ^
>
> The code is in fact correct, it's just a cmpxchg() call that
> intentionally ignores the result, and no other code does that.  The
> warning does not show up on x86 because of the way that its cmpxchg()
> macro is written. This changes the asm-ggeneric implementation to use
> a similar construct with a compound expression instead of a typecast,
> which causes the compiler to not complain about an unused result.
>
> Fix the other macros in this file in a similar way, and place them
> just below their function implementations.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Russell King <rmk+kernel@arm.linux.org.uk>
> ---
Tested with arch/nios2.

Regards
Ley Foon

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] asm-generic: cmpxchg: avoid warnings from macro-ized cmpxchg() implementations
  2015-09-19  4:42 [PATCH] asm-generic: cmpxchg: avoid warnings from macro-ized cmpxchg() implementations Marek Vasut
  2015-10-01 14:06 ` Ley Foon Tan
@ 2015-10-14 15:01 ` Arnd Bergmann
  2015-10-15 14:25   ` Marek Vasut
  1 sibling, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2015-10-14 15:01 UTC (permalink / raw)
  To: Marek Vasut; +Cc: linux-kernel, lftan, linux-arch, Russell King

On Saturday 19 September 2015 06:42:21 Marek Vasut wrote:
> This change is similar to e001bbae7147b111fe1aa42beaf835635f3c016e
> ARM: cmpxchg: avoid warnings from macro-ized cmpxchg() implementations
> 
> A recent change in kernel/acct.c added a new warning for many
> configurations using generic __xchg() implementation:
> 
> In file included from ./arch/nios2/include/asm/cmpxchg.h:12:0,
>                  from include/asm-generic/atomic.h:18,
>                  from arch/nios2/include/generated/asm/atomic.h:1,
>                  from include/linux/atomic.h:4,
>                  from include/linux/spinlock.h:406,
>                  from include/linux/mmzone.h:7,
>                  from include/linux/gfp.h:5,
>                  from include/linux/mm.h:9,
>                  from kernel/acct.c:46:
> kernel/acct.c: In function 'acct_pin_kill':
> include/asm-generic/cmpxchg.h:94:3: warning: value computed is not used [-Wunused-value]
>   ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
>    ^
> include/asm-generic/cmpxchg.h:102:28: note: in expansion of macro 'cmpxchg_local'
>  #define cmpxchg(ptr, o, n) cmpxchg_local((ptr), (o), (n))
>                             ^
> kernel/acct.c:177:2: note: in expansion of macro 'cmpxchg'
>   cmpxchg(&acct->ns->bacct, pin, NULL);
>   ^
> 
> The code is in fact correct, it's just a cmpxchg() call that
> intentionally ignores the result, and no other code does that.  The
> warning does not show up on x86 because of the way that its cmpxchg()
> macro is written. This changes the asm-ggeneric implementation to use
> a similar construct with a compound expression instead of a typecast,
> which causes the compiler to not complain about an unused result.
> 
> Fix the other macros in this file in a similar way, and place them
> just below their function implementations.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Russell King <rmk+kernel@arm.linux.org.uk>


Applied to my asm-generic tree, thanks!

	Arnd

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] asm-generic: cmpxchg: avoid warnings from macro-ized cmpxchg() implementations
  2015-10-14 15:01 ` Arnd Bergmann
@ 2015-10-15 14:25   ` Marek Vasut
  0 siblings, 0 replies; 4+ messages in thread
From: Marek Vasut @ 2015-10-15 14:25 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: linux-kernel, lftan, linux-arch, Russell King

On Wednesday, October 14, 2015 at 05:01:45 PM, Arnd Bergmann wrote:
> On Saturday 19 September 2015 06:42:21 Marek Vasut wrote:
> > This change is similar to e001bbae7147b111fe1aa42beaf835635f3c016e
> > ARM: cmpxchg: avoid warnings from macro-ized cmpxchg() implementations
> > 
> > A recent change in kernel/acct.c added a new warning for many
> > configurations using generic __xchg() implementation:
> > 
> > In file included from ./arch/nios2/include/asm/cmpxchg.h:12:0,
> > 
> >                  from include/asm-generic/atomic.h:18,
> >                  from arch/nios2/include/generated/asm/atomic.h:1,
> >                  from include/linux/atomic.h:4,
> >                  from include/linux/spinlock.h:406,
> >                  from include/linux/mmzone.h:7,
> >                  from include/linux/gfp.h:5,
> >                  from include/linux/mm.h:9,
> > 
> >                  from kernel/acct.c:46:
> > kernel/acct.c: In function 'acct_pin_kill':
> > include/asm-generic/cmpxchg.h:94:3: warning: value computed is not used
> > [-Wunused-value]
> > 
> >   ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned
> >   long)(o),\
> >   
> >    ^
> > 
> > include/asm-generic/cmpxchg.h:102:28: note: in expansion of macro
> > 'cmpxchg_local'
> > 
> >  #define cmpxchg(ptr, o, n) cmpxchg_local((ptr), (o), (n))
> >  
> >                             ^
> > 
> > kernel/acct.c:177:2: note: in expansion of macro 'cmpxchg'
> > 
> >   cmpxchg(&acct->ns->bacct, pin, NULL);
> >   ^
> > 
> > The code is in fact correct, it's just a cmpxchg() call that
> > intentionally ignores the result, and no other code does that.  The
> > warning does not show up on x86 because of the way that its cmpxchg()
> > macro is written. This changes the asm-ggeneric implementation to use
> > a similar construct with a compound expression instead of a typecast,
> > which causes the compiler to not complain about an unused result.
> > 
> > Fix the other macros in this file in a similar way, and place them
> > just below their function implementations.
> > 
> > Signed-off-by: Marek Vasut <marex@denx.de>
> > Cc: Russell King <rmk+kernel@arm.linux.org.uk>
> 
> Applied to my asm-generic tree, thanks!

Thank you!

Now I really hope someone doesn't flame me to a crisp for breaking some odd
architecture ;-)

Best regards,
Marek Vasut

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-10-15 14:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-19  4:42 [PATCH] asm-generic: cmpxchg: avoid warnings from macro-ized cmpxchg() implementations Marek Vasut
2015-10-01 14:06 ` Ley Foon Tan
2015-10-14 15:01 ` Arnd Bergmann
2015-10-15 14:25   ` Marek Vasut

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).