linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Rikard Falkeborn <rikard.falkeborn@gmail.com>,
	Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
	Arnd Bergmann <arnd@arndb.de>,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	Ard Biesheuvel <ardb@kernel.org>,
	Yury Norov <yury.norov@gmail.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH AUTOSEL 5.10 62/62] linux/bits.h: fix compilation error with GENMASK
Date: Mon, 24 May 2021 10:47:43 -0400	[thread overview]
Message-ID: <20210524144744.2497894-62-sashal@kernel.org> (raw)
In-Reply-To: <20210524144744.2497894-1-sashal@kernel.org>

From: Rikard Falkeborn <rikard.falkeborn@gmail.com>

[ Upstream commit f747e6667ebb2ffb8133486c9cd19800d72b0d98 ]

GENMASK() has an input check which uses __builtin_choose_expr() to
enable a compile time sanity check of its inputs if they are known at
compile time.

However, it turns out that __builtin_constant_p() does not always return
a compile time constant [0].  It was thought this problem was fixed with
gcc 4.9 [1], but apparently this is not the case [2].

Switch to use __is_constexpr() instead which always returns a compile time
constant, regardless of its inputs.

Link: https://lore.kernel.org/lkml/42b4342b-aefc-a16a-0d43-9f9c0d63ba7a@rasmusvillemoes.dk [0]
Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=19449 [1]
Link: https://lore.kernel.org/lkml/1ac7bbc2-45d9-26ed-0b33-bf382b8d858b@I-love.SAKURA.ne.jp [2]
Link: https://lkml.kernel.org/r/20210511203716.117010-1-rikard.falkeborn@gmail.com
Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
Reported-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Yury Norov <yury.norov@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 include/linux/bits.h        |  2 +-
 include/linux/const.h       |  8 ++++++++
 include/linux/minmax.h      | 10 ++--------
 tools/include/linux/bits.h  |  2 +-
 tools/include/linux/const.h |  8 ++++++++
 5 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/include/linux/bits.h b/include/linux/bits.h
index 7f475d59a097..87d112650dfb 100644
--- a/include/linux/bits.h
+++ b/include/linux/bits.h
@@ -22,7 +22,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)))
+		__is_constexpr((l) > (h)), (l) > (h), 0)))
 #else
 /*
  * BUILD_BUG_ON_ZERO is not available in h files included from asm files,
diff --git a/include/linux/const.h b/include/linux/const.h
index 81b8aae5a855..435ddd72d2c4 100644
--- a/include/linux/const.h
+++ b/include/linux/const.h
@@ -3,4 +3,12 @@
 
 #include <vdso/const.h>
 
+/*
+ * This returns a constant expression while determining if an argument is
+ * a constant expression, most importantly without evaluating the argument.
+ * Glory to Martin Uecker <Martin.Uecker@med.uni-goettingen.de>
+ */
+#define __is_constexpr(x) \
+	(sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
+
 #endif /* _LINUX_CONST_H */
diff --git a/include/linux/minmax.h b/include/linux/minmax.h
index c0f57b0c64d9..5433c08fcc68 100644
--- a/include/linux/minmax.h
+++ b/include/linux/minmax.h
@@ -2,6 +2,8 @@
 #ifndef _LINUX_MINMAX_H
 #define _LINUX_MINMAX_H
 
+#include <linux/const.h>
+
 /*
  * min()/max()/clamp() macros must accomplish three things:
  *
@@ -17,14 +19,6 @@
 #define __typecheck(x, y) \
 	(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
 
-/*
- * This returns a constant expression while determining if an argument is
- * a constant expression, most importantly without evaluating the argument.
- * Glory to Martin Uecker <Martin.Uecker@med.uni-goettingen.de>
- */
-#define __is_constexpr(x) \
-	(sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
-
 #define __no_side_effects(x, y) \
 		(__is_constexpr(x) && __is_constexpr(y))
 
diff --git a/tools/include/linux/bits.h b/tools/include/linux/bits.h
index 7f475d59a097..87d112650dfb 100644
--- a/tools/include/linux/bits.h
+++ b/tools/include/linux/bits.h
@@ -22,7 +22,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)))
+		__is_constexpr((l) > (h)), (l) > (h), 0)))
 #else
 /*
  * BUILD_BUG_ON_ZERO is not available in h files included from asm files,
diff --git a/tools/include/linux/const.h b/tools/include/linux/const.h
index 81b8aae5a855..435ddd72d2c4 100644
--- a/tools/include/linux/const.h
+++ b/tools/include/linux/const.h
@@ -3,4 +3,12 @@
 
 #include <vdso/const.h>
 
+/*
+ * This returns a constant expression while determining if an argument is
+ * a constant expression, most importantly without evaluating the argument.
+ * Glory to Martin Uecker <Martin.Uecker@med.uni-goettingen.de>
+ */
+#define __is_constexpr(x) \
+	(sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
+
 #endif /* _LINUX_CONST_H */
-- 
2.30.2


      parent reply	other threads:[~2021-05-24 15:01 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-24 14:46 [PATCH AUTOSEL 5.10 01/62] platform/x86: hp_accel: Avoid invoking _INI to speed up resume Sasha Levin
2021-05-24 14:46 ` [PATCH AUTOSEL 5.10 02/62] gpio: cadence: Add missing MODULE_DEVICE_TABLE Sasha Levin
2021-05-24 14:46 ` [PATCH AUTOSEL 5.10 03/62] Revert "crypto: cavium/nitrox - add an error message to explain the failure of pci_request_mem_regions" Sasha Levin
2021-05-24 14:46 ` [PATCH AUTOSEL 5.10 04/62] Revert "media: usb: gspca: add a missed check for goto_low_power" Sasha Levin
2021-05-24 14:46 ` [PATCH AUTOSEL 5.10 05/62] Revert "ALSA: sb: fix a missing check of snd_ctl_add" Sasha Levin
2021-05-24 14:46 ` [PATCH AUTOSEL 5.10 06/62] Revert "serial: max310x: pass return value of spi_register_driver" Sasha Levin
2021-05-24 14:46 ` [PATCH AUTOSEL 5.10 07/62] serial: max310x: unregister uart driver in case of failure and abort Sasha Levin
2021-05-24 14:46 ` [PATCH AUTOSEL 5.10 08/62] Revert "net: fujitsu: fix a potential NULL pointer dereference" Sasha Levin
2021-05-24 14:46 ` [PATCH AUTOSEL 5.10 09/62] net: fujitsu: fix potential null-ptr-deref Sasha Levin
2021-05-24 14:46 ` [PATCH AUTOSEL 5.10 10/62] Revert "net/smc: fix a NULL pointer dereference" Sasha Levin
2021-05-24 14:46 ` [PATCH AUTOSEL 5.10 11/62] net/smc: properly handle workqueue allocation failure Sasha Levin
2021-05-24 14:46 ` [PATCH AUTOSEL 5.10 12/62] Revert "net: caif: replace BUG_ON with recovery code" Sasha Levin
2021-05-24 14:46 ` [PATCH AUTOSEL 5.10 13/62] net: caif: remove BUG_ON(dev == NULL) in caif_xmit Sasha Levin
2021-05-24 14:46 ` [PATCH AUTOSEL 5.10 14/62] Revert "char: hpet: fix a missing check of ioremap" Sasha Levin
2021-05-24 14:46 ` [PATCH AUTOSEL 5.10 15/62] char: hpet: add checks after calling ioremap Sasha Levin
2021-05-24 14:46 ` [PATCH AUTOSEL 5.10 16/62] Revert "ALSA: gus: add a check of the status of snd_ctl_add" Sasha Levin
2021-05-24 14:46 ` [PATCH AUTOSEL 5.10 17/62] ALSA: sb8: Add a comment note regarding an unused pointer Sasha Levin
2021-05-24 14:46 ` [PATCH AUTOSEL 5.10 18/62] Revert "ALSA: usx2y: Fix potential NULL pointer dereference" Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 19/62] Revert "isdn: mISDNinfineon: fix " Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 20/62] isdn: mISDNinfineon: check/cleanup ioremap failure correctly in setup_io Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 21/62] Revert "ath6kl: return error code in ath6kl_wmi_set_roam_lrssi_cmd()" Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 22/62] ath6kl: return error code in ath6kl_wmi_set_roam_lrssi_cmd() Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 23/62] Revert "isdn: mISDN: Fix potential NULL pointer dereference of kzalloc" Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 24/62] isdn: mISDN: correctly handle ph_info allocation failure in hfcsusb_ph_info Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 25/62] Revert "dmaengine: qcom_hidma: Check for driver register failure" Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 26/62] dmaengine: qcom_hidma: comment platform_driver_register call Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 27/62] Revert "libertas: add checks for the return value of sysfs_create_group" Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 28/62] libertas: register sysfs groups properly Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 29/62] Revert "ASoC: rt5645: fix a NULL pointer dereference" Sasha Levin
2021-05-25 22:00   ` Mark Brown
2021-05-26  0:58     ` Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 30/62] ASoC: rt5645: add error checking to rt5645_probe function Sasha Levin
2021-05-25 21:49   ` Mark Brown
2021-05-25 22:15     ` Phillip Potter
2021-05-26 10:28       ` Mark Brown
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 31/62] Revert "ASoC: cs43130: fix a NULL pointer dereference" Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 32/62] ASoC: cs43130: handle errors in cs43130_probe() properly Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 33/62] Revert "media: dvb: Add check on sp8870_readreg" Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 34/62] media: dvb: Add check on sp8870_readreg return Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 35/62] Revert "media: gspca: mt9m111: Check write_bridge for timeout" Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 36/62] media: gspca: mt9m111: Check write_bridge for timeout Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 37/62] Revert "media: gspca: Check the return value of write_bridge for timeout" Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 38/62] media: gspca: properly check for errors in po1030_probe() Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 39/62] Revert "net: liquidio: fix a NULL pointer dereference" Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 40/62] net: liquidio: Add missing null pointer checks Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 41/62] Revert "brcmfmac: add a check for the status of usb_register" Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 42/62] brcmfmac: properly check for bus register errors Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 43/62] cdrom: gdrom: initialize global variable at init time Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 44/62] btrfs: return whole extents in fiemap Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 45/62] scsi: ufs: ufs-mediatek: Fix power down spec violation Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 46/62] scsi: BusLogic: Fix 64-bit system enumeration error for Buslogic Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 47/62] openrisc: Define memory barrier mb Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 48/62] scsi: pm80xx: Fix drives missing during rmmod/insmod loop Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 49/62] btrfs: release path before starting transaction when cloning inline extent Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 50/62] btrfs: do not BUG_ON in link_to_fixup_dir Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 51/62] platform/x86: hp-wireless: add AMD's hardware id to the supported list Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 52/62] platform/x86: intel_punit_ipc: Append MODULE_DEVICE_TABLE for ACPI Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 53/62] platform/x86: touchscreen_dmi: Add info for the Mediacom Winpad 7.0 W700 tablet Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 54/62] SMB3: incorrect file id in requests compounded with open Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 55/62] drm/amd/display: Disconnect non-DP with no EDID Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 56/62] drm/amd/amdgpu: fix refcount leak Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 57/62] drm/amdgpu: Fix a use-after-free Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 58/62] drm/amd/amdgpu: fix a potential deadlock in gpu reset Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 59/62] drm/amdgpu: stop touching sched.ready in the backend Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 60/62] platform/x86: touchscreen_dmi: Add info for the Chuwi Hi10 Pro (CWI529) tablet Sasha Levin
2021-05-24 14:47 ` [PATCH AUTOSEL 5.10 61/62] block: fix a race between del_gendisk and BLKRRPART Sasha Levin
2021-05-24 14:47 ` Sasha Levin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210524144744.2497894-62-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=andy.shevchenko@gmail.com \
    --cc=ardb@kernel.org \
    --cc=arnd@arndb.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=peterz@infradead.org \
    --cc=rikard.falkeborn@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=yury.norov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).