public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] linux/bits.h: Squash unsigned comparison warning for GENMASK
@ 2025-02-04 17:13 Yazen Ghannam
  2025-02-04 21:26 ` Yury Norov
  0 siblings, 1 reply; 7+ messages in thread
From: Yazen Ghannam @ 2025-02-04 17:13 UTC (permalink / raw)
  To: Yury Norov, Rasmus Villemoes; +Cc: linux-kernel, Yazen Ghannam

Cast inputs to 'long' to avoid the following 'type-limits' warning:
  warning: comparison of unsigned expression in ‘< 0’ is always false

The 'long' type can hold +/- 2G which far exceeds valid inputs for the
GENMASK helpers (current max use is 128 bits).

Idea is similar to implementation in __is_nonneg().

Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com>
---
Note to maintainers:
I found some previous discussions on this topic in the mailing list
archives. The upstream code has changed a bit since then, and this
proposed solution seems fairly simple when based on the latest code.

I figured I'd look at something outside my normal focus areas. I
apologize for the noise if this solution is too naive or incomplete.

Thanks!
---
 include/linux/bits.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/bits.h b/include/linux/bits.h
index 61a75d3f294b..318346f2a5a6 100644
--- a/include/linux/bits.h
+++ b/include/linux/bits.h
@@ -21,7 +21,7 @@
 #if !defined(__ASSEMBLY__)
 #include <linux/build_bug.h>
 #include <linux/compiler.h>
-#define GENMASK_INPUT_CHECK(h, l) BUILD_BUG_ON_ZERO(const_true((l) > (h)))
+#define GENMASK_INPUT_CHECK(h, l) BUILD_BUG_ON_ZERO(const_true((long)(l) > (long)(h)))
 #else
 /*
  * BUILD_BUG_ON_ZERO is not available in h files included from asm files,

---
base-commit: 0de63bb7d91975e73338300a57c54b93d3cc151c
change-id: 20250204-fix-genmask-warn-489a6480779f


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

end of thread, other threads:[~2025-02-11 15:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-04 17:13 [PATCH] linux/bits.h: Squash unsigned comparison warning for GENMASK Yazen Ghannam
2025-02-04 21:26 ` Yury Norov
2025-02-05 17:06   ` Yazen Ghannam
2025-02-05 20:59     ` Yury Norov
2025-02-06  2:02       ` Yazen Ghannam
2025-02-06 17:53         ` Yury Norov
2025-02-11 15:53           ` Vincent Mailhol

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