Skip to contentSkip to conversation

driver core: handle sysfs_op failure while device_add

PATCH New Dmitriy Monakhov 1 participant 1 message Mar 11, 2007 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 driver core: handle sysfs_op failure while device_add

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.

---
 drivers/base/core.c |   47 +++++++++++++++++++++++++++++++----------------
 1 files changed, 31 insertions(+), 16 deletions(-)
drivers/base/core.c +31 -16
index 245d703..bcfcfad 100644
@@ -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);
Signature · 1 line
1.5.0.1