[PATCH] PCI: Fix BUILD_BUG_ON usage for old gcc

From: Alex Williamson
Date: Mon Feb 10 2025 - 16:03:54 EST


As reported in the below link, it seems older versions of gcc cannot
determine that the howmany variable is known for all callers. Include
a test so that newer compilers can still enforce this sanity check and
older compilers can still work.

Fixes: 4453f360862e ("PCI: Batch BAR sizing operations")
Link: https://lore.kernel.org/all/20250209154512.GA18688@xxxxxxxxxx
Reported-by: Oleg Nesterov <oleg@xxxxxxxxxx>
Suggested-by: Oleg Nesterov <oleg@xxxxxxxxxx>
Signed-off-by: Alex Williamson <alex.williamson@xxxxxxxxxx>
---

Verified against gcc 14.2.1 to still trigger a build error if called
with a constant value greater than 6, Oleg to confirm build issue is
resolved for gcc 5.3.1.

drivers/pci/probe.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index b6536ed599c3..1bde89d0dc0d 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -345,7 +345,8 @@ static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom)
unsigned int pos, reg;
u16 orig_cmd;

- BUILD_BUG_ON(howmany > PCI_STD_NUM_BARS);
+ BUILD_BUG_ON(__builtin_constant_p(howmany) &&
+ howmany > PCI_STD_NUM_BARS);

if (dev->non_compliant_bars)
return;
--
2.47.1