]> err.no Git - linux-2.6/commitdiff
driver core fixes: device_add() cleanup on error
authorCornelia Huck <cornelia.huck@de.ibm.com>
Fri, 22 Sep 2006 09:37:13 +0000 (11:37 +0200)
committerGreg Kroah-Hartman <gregkh@suse.de>
Wed, 18 Oct 2006 19:49:55 +0000 (12:49 -0700)
Check for return code of device_create_file() and correct cleanup in
the error case in device_add().

Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/base/core.c

index aee3743bd4a3db1f99d81ddf463ee9ec3cc0315d..365f709715efa7c8e2a80b6c736b092cc68673ae 100644 (file)
@@ -433,14 +433,16 @@ int device_add(struct device *dev)
        if (dev->driver)
                dev->uevent_attr.attr.owner = dev->driver->owner;
        dev->uevent_attr.store = store_uevent;
-       device_create_file(dev, &dev->uevent_attr);
+       error = device_create_file(dev, &dev->uevent_attr);
+       if (error)
+               goto attrError;
 
        if (MAJOR(dev->devt)) {
                struct device_attribute *attr;
                attr = kzalloc(sizeof(*attr), GFP_KERNEL);
                if (!attr) {
                        error = -ENOMEM;
-                       goto PMError;
+                       goto ueventattrError;
                }
                attr->attr.name = "dev";
                attr->attr.mode = S_IRUGO;
@@ -450,7 +452,7 @@ int device_add(struct device *dev)
                error = device_create_file(dev, attr);
                if (error) {
                        kfree(attr);
-                       goto attrError;
+                       goto ueventattrError;
                }
 
                dev->devt_attr = attr;
@@ -507,6 +509,8 @@ int device_add(struct device *dev)
                device_remove_file(dev, dev->devt_attr);
                kfree(dev->devt_attr);
        }
+ ueventattrError:
+       device_remove_file(dev, &dev->uevent_attr);
  attrError:
        kobject_uevent(&dev->kobj, KOBJ_REMOVE);
        kobject_del(&dev->kobj);