* [PATCH v2] PCI: Fix BUILD_BUG_ON usage for old gcc
@ 2025-02-12 18:53 Alex Williamson
2025-02-12 22:18 ` Bjorn Helgaas
0 siblings, 1 reply; 2+ messages in thread
From: Alex Williamson @ 2025-02-12 18:53 UTC (permalink / raw)
To: bhelgaas
Cc: Alex Williamson, linux-pci, linux-kernel, mitchell.augustin,
ilpo.jarvinen, david.laight.linux, Oleg Nesterov
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.
Fixes: 4453f360862e ("PCI: Batch BAR sizing operations")
Link: https://lore.kernel.org/all/20250209154512.GA18688@redhat.com
Reported-by: Oleg Nesterov <oleg@redhat.com>
Tested-by: Oleg Nesterov <oleg@redhat.com>
Tested-by: Mitchell Augustin <mitchell.augustin@canonical.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
v2:
- Switch to statically_true (David Laight)
- Add __always_inline (David Laight)
- Included Tested-by reports
drivers/pci/probe.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index b6536ed599c3..246744d8d268 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -339,13 +339,14 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
return (res->flags & IORESOURCE_MEM_64) ? 1 : 0;
}
-static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom)
+static __always_inline void pci_read_bases(struct pci_dev *dev,
+ unsigned int howmany, int rom)
{
u32 rombar, stdbars[PCI_STD_NUM_BARS];
unsigned int pos, reg;
u16 orig_cmd;
- BUILD_BUG_ON(howmany > PCI_STD_NUM_BARS);
+ BUILD_BUG_ON(statically_true(howmany > PCI_STD_NUM_BARS));
if (dev->non_compliant_bars)
return;
--
2.48.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v2] PCI: Fix BUILD_BUG_ON usage for old gcc
2025-02-12 18:53 [PATCH v2] PCI: Fix BUILD_BUG_ON usage for old gcc Alex Williamson
@ 2025-02-12 22:18 ` Bjorn Helgaas
0 siblings, 0 replies; 2+ messages in thread
From: Bjorn Helgaas @ 2025-02-12 22:18 UTC (permalink / raw)
To: Alex Williamson
Cc: bhelgaas, linux-pci, linux-kernel, mitchell.augustin,
ilpo.jarvinen, david.laight.linux, Oleg Nesterov
On Wed, Feb 12, 2025 at 11:53:32AM -0700, Alex Williamson wrote:
> 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.
>
> Fixes: 4453f360862e ("PCI: Batch BAR sizing operations")
> Link: https://lore.kernel.org/all/20250209154512.GA18688@redhat.com
> Reported-by: Oleg Nesterov <oleg@redhat.com>
> Tested-by: Oleg Nesterov <oleg@redhat.com>
> Tested-by: Mitchell Augustin <mitchell.augustin@canonical.com>
> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Applied to pci/for-linus for v6.14 since this fixes a build issue we
added in v6.14-rc1, thanks, Alex.
> ---
>
> v2:
> - Switch to statically_true (David Laight)
> - Add __always_inline (David Laight)
> - Included Tested-by reports
>
> drivers/pci/probe.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index b6536ed599c3..246744d8d268 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -339,13 +339,14 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
> return (res->flags & IORESOURCE_MEM_64) ? 1 : 0;
> }
>
> -static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom)
> +static __always_inline void pci_read_bases(struct pci_dev *dev,
> + unsigned int howmany, int rom)
> {
> u32 rombar, stdbars[PCI_STD_NUM_BARS];
> unsigned int pos, reg;
> u16 orig_cmd;
>
> - BUILD_BUG_ON(howmany > PCI_STD_NUM_BARS);
> + BUILD_BUG_ON(statically_true(howmany > PCI_STD_NUM_BARS));
>
> if (dev->non_compliant_bars)
> return;
> --
> 2.48.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-02-12 22:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-12 18:53 [PATCH v2] PCI: Fix BUILD_BUG_ON usage for old gcc Alex Williamson
2025-02-12 22:18 ` Bjorn Helgaas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox