Driver Core: do not oops when driver_unregister() is called for unregistered drivers
authorKay Sievers <kay.sievers@vrfy.org>
Thu, 28 May 2009 21:24:07 +0000 (14:24 -0700)
committerGreg Kroah-Hartman <gregkh@suse.de>
Thu, 28 May 2009 21:24:07 +0000 (14:24 -0700)
We also fix a problem with cleaning up properly when initializing
drivers and devices, so checks like this will work successfully.

Portions of the patch by Linus and Greg and Ingo.

Reported-by: Ozan Çağlayan <ozan@pardus.org.tr>
Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/base/bus.c
drivers/base/core.c
drivers/base/driver.c

index dc030f1f00f19706a4c5e5d0a077a085b0885187..c6599618523e7fc265daf265880c9c1e7c0fe056 100644 (file)
@@ -700,8 +700,10 @@ int bus_add_driver(struct device_driver *drv)
        }
 
        kobject_uevent(&priv->kobj, KOBJ_ADD);
-       return error;
+       return 0;
 out_unregister:
+       kfree(drv->p);
+       drv->p = NULL;
        kobject_put(&priv->kobj);
 out_put_bus:
        bus_put(bus);
index 4aa527b8a91381289eb175b33f46e3e418d10374..1977d4beb89e0012290a567c850f6a59dd3da1b0 100644 (file)
@@ -879,7 +879,7 @@ int device_add(struct device *dev)
        }
 
        if (!dev_name(dev))
-               goto done;
+               goto name_error;
 
        pr_debug("device: '%s': %s\n", dev_name(dev), __func__);
 
@@ -978,6 +978,9 @@ done:
        cleanup_device_parent(dev);
        if (parent)
                put_device(parent);
+name_error:
+       kfree(dev->p);
+       dev->p = NULL;
        goto done;
 }
 
index c51f11bb29ae2bdd0a13077147e6db357da8be27..8ae0f63602e0730a71647cb571cbf933d76ceec8 100644 (file)
@@ -257,6 +257,10 @@ EXPORT_SYMBOL_GPL(driver_register);
  */
 void driver_unregister(struct device_driver *drv)
 {
+       if (!drv || !drv->p) {
+               WARN(1, "Unexpected driver unregister!\n");
+               return;
+       }
        driver_remove_groups(drv, drv->groups);
        bus_remove_driver(drv);
 }