PCI: Fix BUILD_BUG_ON usage for old gcc
PATCH 1/1 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 still enforce this sanity check and older compilers can still work.
---
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(-)
drivers/pci/probe.c +2 -1
@@ -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 ;
Signature · 1 line
2.47.1
Quoted 10 lines · Alex Williamson
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")Reported-by Oleg Nesterov <[email protected]>Suggested-by Oleg Nesterov <[email protected]>
^^^^^^^^^^^^
Well, thanks, but I didn't ;)
drivers/pci/probe.c static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom) · line 349
Quoted 7 lines
drivers/pci/probe.c +2
-1@@ -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 );
Thanks!
Quoted 7 lines · Oleg Nesterov
Quoted 5 lines · Alex Williamson
drivers/pci/probe.c +0
-0@@ -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;
Quoted 7 lines
drivers/pci/probe.c static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom) · line 349
Quoted 3 lines
drivers/pci/probe.c +2
-1-BUILD_BUG_ON (howmany >PCI_STD_NUM_BARS ); +BUILD_BUG_ON (__builtin_constant_p (howmany) && + howmany >PCI_STD_NUM_BARS );Thanks!
Tested-by Oleg Nesterov <[email protected]>
Just in case... I agree with David, statically_true() looks a bit better and
BUILD_BUG_ON(statically_true(howmany > PCI_STD_NUM_BARS));
also works for me, so if you decide to update this patch feel free to keep my Tested-by.
Oleg.
Mitchell Augustin
Tested-byOn Ubuntu's (modern) GCC 13.3.0-6ubuntu2~24.04, both proposed options also build as expected for me when howmany is set correctly, and fail as expected when I force howmany = 7.
Quoted 27 lines · Oleg Nesterov
Quoted 7 lines · Oleg Nesterov
Quoted 5 lines · Alex Williamson
drivers/pci/probe.c +0
-0@@ -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;Quoted 7 lines
drivers/pci/probe.c static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom) · line 349
Quoted 3 lines
drivers/pci/probe.c +2
-1-BUILD_BUG_ON (howmany >PCI_STD_NUM_BARS ); +BUILD_BUG_ON (__builtin_constant_p (howmany) && + howmany >PCI_STD_NUM_BARS );Thanks!
Tested-by Oleg Nesterov <[email protected]>Just in case... I agree with David,
statically_true()looks a bit better andBUILD_BUG_ON(statically_true(howmany > PCI_STD_NUM_BARS));also works for me, so if you decide to update this patch feel free to keep my Tested-by.
Oleg.
Signature · 2 lines
Mitchell Augustin Software Engineer - Ubuntu Partner Engineering