Re: [PATCH 27/62] pci: Fix locking in pci_do_resource_release_and_resize() error paths
From: Ilpo Järvinen
Date: Tue Feb 24 2026 - 03:26:45 EST
On Mon, 23 Feb 2026, Bart Van Assche wrote:
> From: Bart Van Assche <bvanassche@xxxxxxx>
>
> Make sure that down(&pci_bus_sem) has been called before
> up(&pci_bus_sem) is called.
Before explaining the solution, it would be useful to mention how this
problem can manifest itself (taking one of the early gotos).
> This has been detected by the Clang
> thread-safety analyzer. Compile-tested only.
>
> Cc: Bjorn Helgaas <bhelgaas@xxxxxxxxxx>
> Cc: Ilpo Järvinen <ilpo.jarvinen@xxxxxxxxxxxxxxx>
> Cc: linux-pci@xxxxxxxxxxxxxxx
These (obvious) Ccs are not needed in the commit message, if your workflow
requires having them, please place them below the --- line so that the
maintainer's tools remove them while applying the patch.
> Fixes: 337b1b566db0 ("PCI: Fix restoring BARs on BAR resize rollback path")
> Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx>
> ---
> drivers/pci/setup-bus.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
> index 61f769aaa2f6..3bb8cd9a581e 100644
> --- a/drivers/pci/setup-bus.c
> +++ b/drivers/pci/setup-bus.c
> @@ -2346,6 +2346,7 @@ int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size
> if (ret)
> return ret;
>
> + down_read(&pci_bus_sem);
> pci_dev_for_each_resource(pdev, r, i) {
> if (i >= PCI_BRIDGE_RESOURCES)
> break;
> @@ -2367,7 +2368,6 @@ int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size
> if (!bus->self)
> goto out;
>
> - down_read(&pci_bus_sem);
> ret = pbus_reassign_bridge_resources(bus, res, &saved);
> if (ret)
> goto restore;
--
i.