Skip to content

Commit 472ff48

Browse files
awilliambjorn-helgaas
authored andcommitted
PCI: Fix BUILD_BUG_ON usage for old gcc
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 enforce this sanity check and older compilers can still work. Add __always_inline attribute to give the compiler an even better chance to know the inputs. Link: https://lore.kernel.org/r/20250212185337.293023-1-alex.williamson@redhat.com Fixes: 4453f36 ("PCI: Batch BAR sizing operations") Reported-by: Oleg Nesterov <oleg@redhat.com> Link: https://lore.kernel.org/all/20250209154512.GA18688@redhat.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Tested-by: Oleg Nesterov <oleg@redhat.com> Tested-by: Mitchell Augustin <mitchell.augustin@canonical.com>
1 parent 2014c95 commit 472ff48

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/pci/probe.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,14 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
339339
return (res->flags & IORESOURCE_MEM_64) ? 1 : 0;
340340
}
341341

342-
static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom)
342+
static __always_inline void pci_read_bases(struct pci_dev *dev,
343+
unsigned int howmany, int rom)
343344
{
344345
u32 rombar, stdbars[PCI_STD_NUM_BARS];
345346
unsigned int pos, reg;
346347
u16 orig_cmd;
347348

348-
BUILD_BUG_ON(howmany > PCI_STD_NUM_BARS);
349+
BUILD_BUG_ON(statically_true(howmany > PCI_STD_NUM_BARS));
349350

350351
if (dev->non_compliant_bars)
351352
return;

0 commit comments

Comments
 (0)