Skip to contentSkip to conversation

PCI: host-common: Fix driver remove NULL bridge->bus dereference

PATCH In review Rob Herring 4 participants 4 messages Jul 9, 2020 – Jul 10, 2020

Subsystems (3)
lore
Share & tools
lore

Rob Herring

author reviewer
#0 lore raw

PATCH 1/1 PCI: host-common: Fix driver remove NULL bridge->bus dereference

Commit 2d716c37b5ce ("PCI: host-common: Use struct pci_host_bridge.windows list directly") moved platform_set_drvdata() before pci_host_probe() which results in the bridge->bus pointer being NULL. Let's change the drvdata to the bridge struct instead to fix this.

Fixes 2d716c37b5ce ("PCI: host-common: Use struct pci_host_bridge.windows list directly")
Cc Will Deacon <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 drivers/pci/controller/pci-host-common.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/pci/controller/pci-host-common.c +4 -4
index f8f71d99e427..b76e55f495e4 100644
@@ -83,7 +83,7 @@ int pci_host_common_probe(struct platform_device *pdev)
 	bridge->map_irq = of_irq_parse_and_map_pci;
 	bridge->swizzle_irq = pci_common_swizzle;
 
-	platform_set_drvdata(pdev, bridge->bus);
+	platform_set_drvdata(pdev, bridge);
 
 	return pci_host_probe(bridge);
 }
@@ -91,11 +91,11 @@ EXPORT_SYMBOL_GPL(pci_host_common_probe);
 
 int pci_host_common_remove(struct platform_device *pdev)
 {
-	struct pci_bus *bus = platform_get_drvdata(pdev);
+	struct pci_host_bridge *bridge = platform_get_drvdata(pdev);
 
 	pci_lock_rescan_remove();
-	pci_stop_root_bus(bus);
-	pci_remove_root_bus(bus);
+	pci_stop_root_bus(bridge->bus);
+	pci_remove_root_bus(bridge->bus);
 	pci_unlock_rescan_remove();
 
 	return 0;
Signature · 1 line
2.25.1
Tested-by on v1 1/1
#1 lore raw
Quoted 6 lines · Rob Herring

Commit 2d716c37b5ce ("PCI: host-common: Use struct pci_host_bridge.windows list directly") moved platform_set_drvdata() before pci_host_probe() which results in the bridge->bus pointer being NULL. Let's change the drvdata to the bridge struct instead to fix this.

Quoted 6 lines
Fixes 2d716c37b5ce ("PCI: host-common: Use struct pci_host_bridge.windows list directly")
Cc Will Deacon <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>

Thank you for the quick fix.

Cheers,
Anders

Quoted 35 lines
---
 drivers/pci/controller/pci-host-common.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/pci/controller/pci-host-common.c +4 -5
index f8f71d99e427..b76e55f495e4 100644
@@ -83,7 +83,7 @@ int pci_host_common_probe(struct platform_device *pdev)
        bridge->map_irq = of_irq_parse_and_map_pci;
        bridge->swizzle_irq = pci_common_swizzle;
 
-       platform_set_drvdata(pdev, bridge->bus);
+       platform_set_drvdata(pdev, bridge);
 
        return pci_host_probe(bridge);
 }
@@ -91,11 +91,11 @@ EXPORT_SYMBOL_GPL(pci_host_common_probe);
 
 int pci_host_common_remove(struct platform_device *pdev)
 {
-       struct pci_bus *bus = platform_get_drvdata(pdev);
+       struct pci_host_bridge *bridge = platform_get_drvdata(pdev);
 
        pci_lock_rescan_remove();
-       pci_stop_root_bus(bus);
-       pci_remove_root_bus(bus);
+       pci_stop_root_bus(bridge->bus);
+       pci_remove_root_bus(bridge->bus);
        pci_unlock_rescan_remove();
 
        return 0;
--

2.25.1

#2 lore raw
In reply to Rob Herring
Quoted 6 lines · Rob Herring

Commit 2d716c37b5ce ("PCI: host-common: Use struct pci_host_bridge.windows list directly") moved platform_set_drvdata() before pci_host_probe() which results in the bridge->bus pointer being NULL. Let's change the drvdata to the bridge struct instead to fix this.

Fixes 2d716c37b5ce ("PCI: host-common: Use struct pci_host_bridge.windows list directly")

This commit is in -next, but not Linus's tree. Hopefully Lorenzo can just squash this fix into it.

#3 lore raw
Quoted 10 lines · Bjorn Helgaas
Quoted 6 lines · Rob Herring

Commit 2d716c37b5ce ("PCI: host-common: Use struct pci_host_bridge.windows list directly") moved platform_set_drvdata() before pci_host_probe() which results in the bridge->bus pointer being NULL. Let's change the drvdata to the bridge struct instead to fix this.

Fixes 2d716c37b5ce ("PCI: host-common: Use struct pci_host_bridge.windows list directly")

This commit is in -next, but not Linus's tree. Hopefully Lorenzo can just squash this fix into it.

Done, updated my pci/misc branch accordingly.

Lorenzo