Skip to content

Commit

Permalink
PCI: Fix refcount issue in pci_create_root_bus() error recovery path
Browse files Browse the repository at this point in the history
After calling device_register(&bridge->dev), the bridge is reference-
counted, and it is illegal to call kfree() on it except in the release
function.

[bhelgaas: changelog, use put_device() after device_register() failure]
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: stable@vger.kernel.org
  • Loading branch information
Jiang Liu authored and Bjorn Helgaas committed Jun 7, 2013
1 parent a649dbf commit 343df77
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions drivers/pci/probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1711,12 +1711,16 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
bridge->dev.release = pci_release_bus_bridge_dev;
dev_set_name(&bridge->dev, "pci%04x:%02x", pci_domain_nr(b), bus);
error = pcibios_root_bridge_prepare(bridge);
if (error)
goto bridge_dev_reg_err;
if (error) {
kfree(bridge);
goto err_out;
}

error = device_register(&bridge->dev);
if (error)
goto bridge_dev_reg_err;
if (error) {
put_device(&bridge->dev);
goto err_out;
}
b->bridge = get_device(&bridge->dev);
device_enable_async_suspend(b->bridge);
pci_set_bus_of_node(b);
Expand Down Expand Up @@ -1772,8 +1776,6 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
class_dev_reg_err:
put_device(&bridge->dev);
device_unregister(&bridge->dev);
bridge_dev_reg_err:
kfree(bridge);
err_out:
kfree(b);
return NULL;
Expand Down

0 comments on commit 343df77

Please sign in to comment.