[PATCH] driver core: handle sysfs_op failure while device_add

From: Dmitriy Monakhov
Date: Sun Mar 11 2007 - 15:11:58 EST


depends on: "[PATCH] driver core: fix device_add error path"

- rearrange error path sequence, in order to make it more correct.
In fact if initial sequance was doA(); doB(); doC();
we should undo it with folowing sequance undoC(); undoB(); undoA();
- handle sysfs_ops failure

This patch kills "ignoring return value of 'sysfs_create_link'"
warning message.

Signed-off-by: Monakhov Dmitriy <dmonakhov@xxxxxxxxxx>
---
drivers/base/core.c | 47 +++++++++++++++++++++++++++++++----------------
1 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 245d703..bcfcfad 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -602,22 +602,34 @@ int device_add(struct device *dev)
}

if (dev->class) {
- sysfs_create_link(&dev->kobj, &dev->class->subsys.kset.kobj,
- "subsystem");
+ error = sysfs_create_link(&dev->kobj,
+ &dev->class->subsys.kset.kobj, "subsystem");
+ if (error)
+ goto ueventattrError;
/* If this is not a "fake" compatible device, then create the
* symlink from the class to the device. */
- if (dev->kobj.parent != &dev->class->subsys.kset.kobj)
- sysfs_create_link(&dev->class->subsys.kset.kobj,
- &dev->kobj, dev->bus_id);
+ if (dev->kobj.parent != &dev->class->subsys.kset.kobj) {
+ error = sysfs_create_link(
+ &dev->class->subsys.kset.kobj,
+ &dev->kobj, dev->bus_id);
+ if (error)
+ goto busLinkErr;
+ }
if (parent) {
- sysfs_create_link(&dev->kobj, &dev->parent->kobj,
- "device");
+ error = sysfs_create_link(&dev->kobj,
+ &dev->parent->kobj, "device");
+ if (error)
+ goto deviceLinkErr;
#ifdef CONFIG_SYSFS_DEPRECATED
class_name = make_class_name(dev->class->name,
&dev->kobj);
- if (class_name)
- sysfs_create_link(&dev->parent->kobj,
- &dev->kobj, class_name);
+ if (class_name) {
+ error = sysfs_create_link(
+ &dev->parent->kobj,
+ &dev->kobj, class_name);
+ if (error)
+ goto classLinkErr;
+ }
#endif
}
}
@@ -673,12 +685,6 @@ int device_add(struct device *dev)
}

if (dev->class) {
- sysfs_remove_link(&dev->kobj, "subsystem");
- /* If this is not a "fake" compatible device, remove the
- * symlink from the class to the device. */
- if (dev->kobj.parent != &dev->class->subsys.kset.kobj)
- sysfs_remove_link(&dev->class->subsys.kset.kobj,
- dev->bus_id);
if (parent) {
#ifdef CONFIG_SYSFS_DEPRECATED
char *class_name = make_class_name(dev->class->name,
@@ -688,8 +694,17 @@ int device_add(struct device *dev)
class_name);
kfree(class_name);
#endif
+classLinkErr:
sysfs_remove_link(&dev->kobj, "device");
}
+deviceLinkErr:
+ /* If this is not a "fake" compatible device, remove the
+ * symlink from the class to the device. */
+ if (dev->kobj.parent != &dev->class->subsys.kset.kobj)
+ sysfs_remove_link(&dev->class->subsys.kset.kobj,
+ dev->bus_id);
+busLinkErr:
+ sysfs_remove_link(&dev->kobj, "subsystem");
}
ueventattrError:
device_remove_file(dev, &dev->uevent_attr);
--
1.5.0.1

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/