From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Morton Subject: [patch 10/32] linux/bits.h: fix unsigned less than zero warnings Date: Thu, 25 Jun 2020 20:29:46 -0700 Message-ID: <20200626032946._LJ_E6G66%akpm@linux-foundation.org> References: <20200625202807.b630829d6fa55388148bee7d@linux-foundation.org> Reply-To: linux-kernel@vger.kernel.org Return-path: Received: from mail.kernel.org ([198.145.29.99]:48134 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728333AbgFZD3r (ORCPT ); Thu, 25 Jun 2020 23:29:47 -0400 In-Reply-To: <20200625202807.b630829d6fa55388148bee7d@linux-foundation.org> Sender: mm-commits-owner@vger.kernel.org List-Id: mm-commits@vger.kernel.org To: akpm@linux-foundation.org, andy.shevchenko@gmail.com, arnd@arndb.de, emil.l.velikov@gmail.com, geert@linux-m68k.org, keescook@chromium.org, linus.walleij@linaro.org, lkp@intel.com, mm-commits@vger.kernel.org, rikard.falkeborn@gmail.com, syednwaris@gmail.com, torvalds@linux-foundation.org, vilhelm.gray@gmail.com, yamada.masahiro@socionext.com From: Rikard Falkeborn Subject: linux/bits.h: fix unsigned less than zero warnings When calling the GENMASK and GENMASK_ULL macros with zero lower bit and an unsigned unknown high bit, some gcc versions warn due to the comparisons of the high and low bit in GENMASK_INPUT_CHECK. To silence the warnings, only perform the check if both inputs are known. This does not trigger any warnings, from the Wtype-limits help: Warn if a comparison is always true or always false due to the limited range of the data type, but do not warn for constant expressions. As an example of the warning, kindly reported by the kbuild test robot: from drivers/mfd/atmel-smc.c:11: drivers/mfd/atmel-smc.c: In function 'atmel_smc_cs_encode_ncycles': include/linux/bits.h:26:28: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits] 26 | __builtin_constant_p((l) > (h)), (l) > (h), 0))) | ^ include/linux/build_bug.h:16:62: note: in definition of macro 'BUILD_BUG_ON_ZERO' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); }))) | ^ include/linux/bits.h:39:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l)) | ^~~~~~~~~~~~~~~~~~~ >> drivers/mfd/atmel-smc.c:49:25: note: in expansion of macro 'GENMASK' 49 | unsigned int lsbmask = GENMASK(msbpos - 1, 0); | ^~~~~~~ Link: http://lkml.kernel.org/r/20200621054210.14804-1-rikard.falkeborn@gmail.com Link: http://lkml.kernel.org/r/20200608221823.35799-1-rikard.falkeborn@gmail.com Fixes: 295bcca84916 ("linux/bits.h: add compile time sanity check of GENMASK inputs") Signed-off-by: Rikard Falkeborn Reported-by: kbuild test robot Reported-by: Emil Velikov Reported-by: Syed Nayyar Waris Reviewed-by: Andy Shevchenko Reviewed-by: Emil Velikov Cc: Arnd Bergmann Cc: Geert Uytterhoeven Cc: Kees Cook Cc: Linus Walleij Cc: William Breathitt Gray Cc: Masahiro Yamada Signed-off-by: Andrew Morton --- include/linux/bits.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/include/linux/bits.h~linux-bitsh-fix-unsigned-less-than-zero-warnings +++ a/include/linux/bits.h @@ -23,7 +23,8 @@ #include #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) && __builtin_constant_p(h), \ + (l) > (h), 0))) #else /* * BUILD_BUG_ON_ZERO is not available in h files included from asm files, _