From nobody Tue Jun 23 08:14:35 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5957EC433EF for ; Tue, 8 Mar 2022 14:12:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347322AbiCHONm (ORCPT ); Tue, 8 Mar 2022 09:13:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346716AbiCHONg (ORCPT ); Tue, 8 Mar 2022 09:13:36 -0500 Received: from smtp.smtpout.orange.fr (smtp04.smtpout.orange.fr [80.12.242.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2558A140FA for ; Tue, 8 Mar 2022 06:12:37 -0800 (PST) Received: from localhost.localdomain ([106.133.35.112]) by smtp.orange.fr with ESMTPA id RaZInDouy9VRxRaZcnRk3S; Tue, 08 Mar 2022 15:12:35 +0100 X-ME-Helo: localhost.localdomain X-ME-Auth: MDU0YmViZGZmMDIzYiBlMiM2NTczNTRjNWZkZTMwOGRiOGQ4ODf3NWI1ZTMyMzdiODlhOQ== X-ME-Date: Tue, 08 Mar 2022 15:12:35 +0100 X-ME-IP: 106.133.35.112 From: Vincent Mailhol To: Rikard Falkeborn , Andrew Morton , Linux Kernel Mailing List Cc: Arnd Bergmann , Andy Shevchenko , Kees Cook , Alexander Lobakin , Herbert Xu , Emil Velikov , Geert Uytterhoeven , Linus Walleij , linux-arch , kernel test robot , Syed Nayyar Waris , William Breathitt Gray , Masahiro Yamada , Linus Torvalds , Vincent Mailhol Subject: [PATCH v2] linux/bits.h: GENMASK_INPUT_CHECK: reduce W=2 noise by 31% treewide Date: Tue, 8 Mar 2022 23:12:01 +0900 Message-Id: <20220308141201.2343757-1-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220304124416.1181029-1-mailhol.vincent@wanadoo.fr> References: <20220304124416.1181029-1-mailhol.vincent@wanadoo.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch silences a -Wtypes-limits warning in GENMASK_INPUT_CHECK() which is accountable for 31% of all warnings when compiling with W=3D2. Indeed, GENMASK_INPUT_CHECK() will generate some warnings at W=3D2 level if invoked with an unsigned integer and zero. For example, this: | #include | unsigned int foo(unsigned int bar) | { return GENMASK(bar, 0); } would yield 30 lines of warning. Extract: | In file included from ./include/linux/bits.h:22, | from ./foo.c:1: | foo.c: In function 'foo': | ./include/linux/bits.h:25:36: warning: comparison of unsigned expression = in '< 0' is always false [-Wtype-limits] | 25 | __is_constexpr((l) > (h)), (l) > (h), 0))) | | ^ This pattern is harmless (false positive) and for that reason, -Wtypes-limits was moved to W=3D2. c.f. [1]. However because it occurs in header files (example: find_first_bit() from linux/find.h [2]), GENMASK_INPUT_CHECK() is accountable for roughly 31% (164714/532484) of all W=3D2 warnings for an allyesconfig. This is an issue because that noise makes it harder to triage and find relevant W=3D2 warnings. Reference (using gcc 11.2, linux v5.17-rc6 on x86_64): | $ make allyesconfig | $ sed -i '/CONFIG_WERROR/d' .config | $ make W=3D2 -j8 2> kernel_w2.log > /dev/null | $ grep "\./include/linux/bits\.h:.*: warning" kernel_w2\.log | wc -l | 164714 | $ grep ": warning: " kernel_w2.log | wc -l | 532484 In this patch, we silence this warning by: * replacing the comparison > by and logical and && in the first argument of __builtin_choose_expr(). * casting the high bit of the mask to a signed integer in the second argument of __builtin_choose_expr(). [1] https://lore.kernel.org/lkml/20200708190756.16810-1-rikard.falkeborn@gm= ail.com/ [2] https://elixir.bootlin.com/linux/v5.17-rc6/source/include/linux/find.h#= L119 Link: https://lore.kernel.org/lkml/cover.1590017578.git.syednwaris@gmail.co= m/ Link: https://lore.kernel.org/lkml/20220304124416.1181029-1-mailhol.vincent= @wanadoo.fr/ Fixes: 295bcca84916 ("linux/bits.h: add compile time sanity check of GENMAS= K inputs") Signed-off-by: Vincent Mailhol --- * Changelog * v1 -> v2: * Rewrote the commit message to make it less verbose * Add in CC all people from: https://lore.kernel.org/lkml/cover.1590017578.git.syednwaris@gmail.com/ --- 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 87d112650dfb..542e9a8985b1 100644 --- a/include/linux/bits.h +++ b/include/linux/bits.h @@ -22,7 +22,7 @@ #include #define GENMASK_INPUT_CHECK(h, l) \ (BUILD_BUG_ON_ZERO(__builtin_choose_expr( \ - __is_constexpr((l) > (h)), (l) > (h), 0))) + __is_constexpr((h)) && __is_constexpr((l)), (l) > (int)(h), 0))) #else /* * BUILD_BUG_ON_ZERO is not available in h files included from asm files, --=20 2.34.1