[PATCH v2] linux/bits.h: adjust GENMASK_INPUT_CHECK() check

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Recently the GENMASK_INPUT_CHECK() was added, aiming to catch cases
where there GENMASK arguments are flipped.

Although it seems to be triggering -Wtype-limits in the following cases:

   unsigned foo = (10 + x);
   unsigned bar = GENMASK(foo, 0);

   const unsigned foo = (10 + x);
   unsigned bar = GENMASK(foo, 0);

Here are the warnings, from my GCC 9.2 box.

warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
   __builtin_constant_p((l) > (h)), (l) > (h), 0)))
                            ^
warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
   __builtin_constant_p((l) > (h)), (l) > (h), 0)))
                                        ^

This results in people disabling the warning all together or promoting
foo to signed. Either of which being a sub par option IMHO.

Add a trivial "+ 1" to each h and l in the constant expression.

v2: drop accidental !

Fixes: 295bcca84916 ("linux/bits.h: add compile time sanity check of
GENMASK inputs")
Cc: Rikard Falkeborn <rikard.falkeborn@xxxxxxxxx>
Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Cc: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx>
Cc: dri-devel@xxxxxxxxxxxxxxxxxxxxx
Signed-off-by: Emil Velikov <emil.l.velikov@xxxxxxxxx>
Reported-by: kbuild test robot <lkp@xxxxxxxxx>
Reported-by: kbuild test robot <lkp@xxxxxxxxx>
---
 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 4671fbf28842..02a42866d198 100644
--- a/include/linux/bits.h
+++ b/include/linux/bits.h
@@ -23,7 +23,7 @@
 #include <linux/build_bug.h>
 #define GENMASK_INPUT_CHECK(h, l) \
 	(BUILD_BUG_ON_ZERO(__builtin_choose_expr( \
-		__builtin_constant_p((l) > (h)), (l) > (h), 0)))
+		__builtin_constant_p((l + 1) > (h + 1)), (l + 1) > (h + 1), 0)))
 #else
 /*
  * BUILD_BUG_ON_ZERO is not available in h files included from asm files,
-- 
2.25.1

_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel



[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux