Patchwork [67/98] PCI: Fix refcount issue in pci_create_root_bus() error recovery path

login
register
mail settings
Submitter Luis Henriques
Date July 11, 2013, 2:24 p.m.
Message ID <1373552708-15235-68-git-send-email-luis.henriques@canonical.com>
Download mbox | patch
Permalink /patch/258558/
State New
Headers show

Comments

Luis Henriques - July 11, 2013, 2:24 p.m.
3.5.7.17 -stable review patch.  If anyone has any objections, please let me know.

------------------

From: Jiang Liu <liuj97@gmail.com>

commit 343df771e671d821478dd3ef525a0610b808dbf8 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: Jiang Liu <jiang.liu@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
[ luis: backported to 3.5:
  - adjusted context
  - removed error handling for pcibios_root_bridge_prepare invocation ]
Signed-off-by: Luis Henriques <luis.henriques@canonical.com>
---
 drivers/pci/probe.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Patch

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 9319aa1..96273e3 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1625,8 +1625,10 @@  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 = 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);
@@ -1679,8 +1681,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;