提交 a306eea4 编写于 作者: C Cornelia Huck 提交者: Greg Kroah-Hartman

driver core fixes: device_add() cleanup on error

Check for return code of device_create_file() and correct cleanup in
the error case in device_add().
Signed-off-by: NCornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 513e7337
...@@ -433,14 +433,16 @@ int device_add(struct device *dev) ...@@ -433,14 +433,16 @@ int device_add(struct device *dev)
if (dev->driver) if (dev->driver)
dev->uevent_attr.attr.owner = dev->driver->owner; dev->uevent_attr.attr.owner = dev->driver->owner;
dev->uevent_attr.store = store_uevent; 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)) { if (MAJOR(dev->devt)) {
struct device_attribute *attr; struct device_attribute *attr;
attr = kzalloc(sizeof(*attr), GFP_KERNEL); attr = kzalloc(sizeof(*attr), GFP_KERNEL);
if (!attr) { if (!attr) {
error = -ENOMEM; error = -ENOMEM;
goto PMError; goto ueventattrError;
} }
attr->attr.name = "dev"; attr->attr.name = "dev";
attr->attr.mode = S_IRUGO; attr->attr.mode = S_IRUGO;
...@@ -450,7 +452,7 @@ int device_add(struct device *dev) ...@@ -450,7 +452,7 @@ int device_add(struct device *dev)
error = device_create_file(dev, attr); error = device_create_file(dev, attr);
if (error) { if (error) {
kfree(attr); kfree(attr);
goto attrError; goto ueventattrError;
} }
dev->devt_attr = attr; dev->devt_attr = attr;
...@@ -507,6 +509,8 @@ int device_add(struct device *dev) ...@@ -507,6 +509,8 @@ int device_add(struct device *dev)
device_remove_file(dev, dev->devt_attr); device_remove_file(dev, dev->devt_attr);
kfree(dev->devt_attr); kfree(dev->devt_attr);
} }
ueventattrError:
device_remove_file(dev, &dev->uevent_attr);
attrError: attrError:
kobject_uevent(&dev->kobj, KOBJ_REMOVE); kobject_uevent(&dev->kobj, KOBJ_REMOVE);
kobject_del(&dev->kobj); kobject_del(&dev->kobj);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册