Skip to contentSkip to conversation

mca: fix device_register() error handling

PATCH Applied Vasiliy Kulikov 2 participants 2 messages Sep 19, 2010 Kernel janitors

lore
Share & tools
lore
#0 lore raw

PATCH 3/14 mca: fix device_register() error handling

If device_register() fails then call put_device(). See comment to device_register.

---
I cannot compile this driver, so it is not tested at all.

 drivers/mca/mca-bus.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
drivers/mca/mca-bus.c +4 -1
index ada5ebb..7162f08 100644
@@ -116,8 +116,10 @@ int __init mca_register_device(int bus, struct mca_device *mca_dev)
 	mca_dev->dev.coherent_dma_mask = mca_dev->dma_mask;
 
 	rc = device_register(&mca_dev->dev);
-	if (rc)
+	if (rc) {
+		put_device(&mca_dev->dev);
 		goto err_out;
+	}
 
 	rc = device_create_file(&mca_dev->dev, &dev_attr_id);
 	if (rc) goto err_out_devreg;
@@ -154,6 +156,7 @@ struct mca_bus * __devinit mca_attach_bus(int bus)
 	dev_set_name(&mca_bus->dev, "mca%d", bus);
 	sprintf(mca_bus->name,"Host %s MCA Bridge", bus ? "Secondary" : "Primary");
 	if (device_register(&mca_bus->dev)) {
+		put_device(&mca_bus->dev);
 		kfree(mca_bus);
 		return NULL;
 	}
Signature · 1 line
1.7.0.4
#1 lore raw
Quoted 27 lines · Vasiliy Kulikov

If device_register() fails then call put_device(). See comment to device_register.

---
I cannot compile this driver, so it is not tested at all.

 drivers/mca/mca-bus.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
drivers/mca/mca-bus.c +3 -1
index ada5ebb..7162f08 100644
@@ -116,8 +116,10 @@ int __init mca_register_device(int bus, struct mca_device *mca_dev)
 	mca_dev->dev.coherent_dma_mask = mca_dev->dma_mask;
 
 	rc = device_register(&mca_dev->dev);
-	if (rc)
+	if (rc) {
+		put_device(&mca_dev->dev);
 		goto err_out;
+	}
 
 	rc = device_create_file(&mca_dev->dev, &dev_attr_id);
 	if (rc) goto err_out_devreg;

drivers/mca/mca-bus.c struct mca_bus * __devinit mca_attach_bus(int bus) · line 162

Quoted 7 lines
drivers/mca/mca-bus.c +1 -0
@@ -154,6 +156,7 @@ struct mca_bus * __devinit mca_attach_bus(int bus)
 	dev_set_name(&mca_bus->dev, "mca%d", bus);
 	sprintf(mca_bus->name,"Host %s MCA Bridge", bus ? "Secondary" : "Primary");
 	if (device_register(&mca_bus->dev)) {
+		put_device(&mca_bus->dev);
 		kfree(mca_bus);
 		return NULL;
 	}

just a minor: dev_set_name() is not check here. (But is in other places).

re,
wh