Commit 65a1fb23 authored by Jiang Liu's avatar Jiang Liu Committed by Greg Kroah-Hartman

PCI: Fix refcount issue in pci_create_root_bus() error recovery path

commit 343df771 upstream.

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: default avatarJiang Liu <jiang.liu@huawei.com>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent c723caee
...@@ -1703,12 +1703,16 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus, ...@@ -1703,12 +1703,16 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
bridge->dev.release = pci_release_bus_bridge_dev; bridge->dev.release = pci_release_bus_bridge_dev;
dev_set_name(&bridge->dev, "pci%04x:%02x", pci_domain_nr(b), bus); dev_set_name(&bridge->dev, "pci%04x:%02x", pci_domain_nr(b), bus);
error = pcibios_root_bridge_prepare(bridge); error = pcibios_root_bridge_prepare(bridge);
if (error) if (error) {
goto bridge_dev_reg_err; kfree(bridge);
goto err_out;
}
error = device_register(&bridge->dev); error = device_register(&bridge->dev);
if (error) if (error) {
goto bridge_dev_reg_err; put_device(&bridge->dev);
goto err_out;
}
b->bridge = get_device(&bridge->dev); b->bridge = get_device(&bridge->dev);
device_enable_async_suspend(b->bridge); device_enable_async_suspend(b->bridge);
pci_set_bus_of_node(b); pci_set_bus_of_node(b);
...@@ -1764,8 +1768,6 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus, ...@@ -1764,8 +1768,6 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
class_dev_reg_err: class_dev_reg_err:
put_device(&bridge->dev); put_device(&bridge->dev);
device_unregister(&bridge->dev); device_unregister(&bridge->dev);
bridge_dev_reg_err:
kfree(bridge);
err_out: err_out:
kfree(b); kfree(b);
return NULL; return NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment