2014-06-09 21:06:54

by Andreas Noever

[permalink] [raw]
Subject: [PATCH] PCI: Prevent NULL dereference during pciehp probe

pciehp assumes that dev->subordinate exists. But we do not assign a bus
if we run out of bus numbers during enumeration. This leads to a NULL
dereference in init_slot (and other places).

Change pciehp_probe to return -ENODEV when no subordinate bus is
present.

Signed-off-by: Andreas Noever <[email protected]>
---
drivers/pci/hotplug/pciehp_core.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
index 0e0a2ff..e5abcaf 100644
--- a/drivers/pci/hotplug/pciehp_core.c
+++ b/drivers/pci/hotplug/pciehp_core.c
@@ -255,6 +255,13 @@ static int pciehp_probe(struct pcie_device *dev)
else if (pciehp_acpi_slot_detection_check(dev->port))
goto err_out_none;

+ if (!dev->port->subordinate) {
+ /* Can happen if we run out of bus numbers during probe */
+ dev_err(&dev->device,
+ "Hotplug bridge without secondary bus, ignoring\n");
+ goto err_out_none;
+ }
+
ctrl = pcie_init(dev);
if (!ctrl) {
dev_err(&dev->device, "Controller initialization failed\n");
--
2.0.0