[PATCH 05/11] Driver core: Fix error handling in bus_add_driver().

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <linux-kernel@...>
Cc: Cornelia Huck <cornelia.huck@...>, Greg Kroah-Hartman <gregkh@...>
Date: Thursday, February 21, 2008 - 7:48 pm

From: Cornelia Huck <cornelia.huck@de.ibm.com>

- If the allocation of ->priv fails, the reference on the bus
  must be dropped.
- If adding the kobject fails, kobject_put must be called to
  clean things up.

Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/base/bus.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 055989e..2d207ad 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -658,9 +658,10 @@ int bus_add_driver(struct device_driver *drv)
 	pr_debug("bus: '%s': add driver %s\n", bus->name, drv->name);
 
 	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
-	if (!priv)
-		return -ENOMEM;
-
+	if (!priv) {
+		error = -ENOMEM;
+		goto out_put_bus;
+	}
 	klist_init(&priv->klist_devices, NULL, NULL);
 	priv->driver = drv;
 	drv->p = priv;
@@ -668,7 +669,7 @@ int bus_add_driver(struct device_driver *drv)
 	error = kobject_init_and_add(&priv->kobj, &driver_ktype, NULL,
 				     "%s", drv->name);
 	if (error)
-		goto out_put_bus;
+		goto out_unregister;
 
 	if (drv->bus->p->drivers_autoprobe) {
 		error = driver_attach(drv);
-- 
1.5.4

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 11/11] modules: do not try to add sysfs attributes if..., Greg Kroah-Hartman, (Thu Feb 21, 7:48 pm)
[PATCH 10/11] POWERPC: fix typo in pseries/power.c, Greg Kroah-Hartman, (Thu Feb 21, 7:48 pm)
[PATCH 09/11] PM: Remove unbalanced mutex_unlock() from dpm_..., Greg Kroah-Hartman, (Thu Feb 21, 7:48 pm)
[PATCH 08/11] UIO: fix Greg's stupid changes, Greg Kroah-Hartman, (Thu Feb 21, 7:48 pm)
[PATCH 07/11] stable_kernel_rules: fix must already be in ma..., Greg Kroah-Hartman, (Thu Feb 21, 7:48 pm)
[PATCH 06/11] ide: mark "ide=reverse" option as obsolete, Greg Kroah-Hartman, (Thu Feb 21, 7:48 pm)
[PATCH 05/11] Driver core: Fix error handling in bus_add_dri..., Greg Kroah-Hartman, (Thu Feb 21, 7:48 pm)
[PATCH 04/11] driver-core: fix kernel-doc function parameters, Greg Kroah-Hartman, (Thu Feb 21, 7:48 pm)
[PATCH 03/11] cpufreq: fix kobject reference count handling, Greg Kroah-Hartman, (Thu Feb 21, 7:47 pm)
[PATCH 02/11] slabinfo: fall back from /sys/kernel/slab to /..., Greg Kroah-Hartman, (Thu Feb 21, 7:47 pm)
[PATCH 01/11] Fix broken utf-8 encodings in ja_JP translatio..., Greg Kroah-Hartman, (Thu Feb 21, 7:47 pm)