linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/1] x86/percpu: Cast -1 to argument type when comparing in percpu_add_op()
@ 2024-09-05 17:03 Andy Shevchenko
  2024-10-16 13:37 ` Andy Shevchenko
  2024-10-16 15:44 ` Dave Hansen
  0 siblings, 2 replies; 16+ messages in thread
From: Andy Shevchenko @ 2024-09-05 17:03 UTC (permalink / raw)
  To: Ingo Molnar, Uros Bizjak, linux-mm, linux-kernel, llvm
  Cc: Dennis Zhou, Tejun Heo, Christoph Lameter, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Andy Shevchenko

When percpu_add_op() is used with unsigned argument, it prevents kernel builds
with clang, `make W=1` and CONFIG_WERROR=y:

net/ipv4/tcp_output.c:187:3: error: result of comparison of constant -1 with expression of type 'u8' (aka 'unsigned char') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
  187 |                 NET_ADD_STATS(sock_net(sk), LINUX_MIB_TCPACKCOMPRESSED,
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  188 |                               tp->compressed_ack);
      |                               ~~~~~~~~~~~~~~~~~~~
...
arch/x86/include/asm/percpu.h:238:31: note: expanded from macro 'percpu_add_op'
  238 |                               ((val) == 1 || (val) == -1)) ?            \
      |                                              ~~~~~ ^  ~~

Fix this by casting -1 to the type of the parameter and then compare.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 arch/x86/include/asm/percpu.h | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index c55a79d5feae..e525cd85f999 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -234,9 +234,10 @@ do {									\
  */
 #define percpu_add_op(size, qual, var, val)				\
 do {									\
-	const int pao_ID__ = (__builtin_constant_p(val) &&		\
-			      ((val) == 1 || (val) == -1)) ?		\
-				(int)(val) : 0;				\
+	const int pao_ID__ =						\
+		(__builtin_constant_p(val) &&				\
+			((val) == 1 ||					\
+			 (val) == (typeof(val))-1)) ? (int)(val) : 0;	\
 									\
 	if (0) {							\
 		typeof(var) pao_tmp__;					\
-- 
2.43.0.rc1.1336.g36b5255a03ac



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

end of thread, other threads:[~2024-10-23 21:41 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-05 17:03 [PATCH v1 1/1] x86/percpu: Cast -1 to argument type when comparing in percpu_add_op() Andy Shevchenko
2024-10-16 13:37 ` Andy Shevchenko
2024-10-16 15:44 ` Dave Hansen
2024-10-16 17:03   ` Nick Desaulniers
2024-10-16 18:06   ` Andy Shevchenko
2024-10-16 18:20     ` Andy Shevchenko
2024-10-16 19:43       ` Dave Hansen
2024-10-16 19:20   ` Peter Zijlstra
2024-10-16 19:44     ` Dave Hansen
2024-10-17 18:18       ` Peter Zijlstra
2024-10-18 12:21         ` Andy Shevchenko
2024-10-22 19:53         ` Dave Hansen
2024-10-22 23:24           ` Christoph Lameter (Ampere)
2024-10-23 17:15             ` Dave Hansen
2024-10-23 21:40               ` H. Peter Anvin
2024-10-23 14:24           ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox