public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] drivers/base/core: improve device_add() error handling, fix bugs
@ 2007-07-18  5:53 Jeff Garzik
  2007-07-18  5:55 ` [PATCH 2/3] drivers/video/aty/radeon_base: fix radeonfb_pci_register() err handling Jeff Garzik
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Jeff Garzik @ 2007-07-18  5:53 UTC (permalink / raw)
  To: LKML; +Cc: Greg KH, Andrew Morton


The following change was checked into 'warnings' branch of
git://git.kernel.org/pub/scm/linux/kernel/git/jgarzik/misc-2.6.git

commit 5330916f5a11d8b7def46a6b3e14a831684032f5
Author: Jeff Garzik <jeff@garzik.org>
Date:   Wed Jul 18 01:41:29 2007 -0400

    drivers/base/core: improve device_add() error handling, fix bugs
    
    * silence several warnings by handling sysfs_create_link() failure
    
    * re-order some operations in error handling, to precisely reverse
      the order of operations, i.e. unwind properly.
    
    Signed-off-by: Jeff Garzik <jeff@garzik.org>

 drivers/base/core.c |   46 ++++++++++++++++++++++++++++++----------------
 1 file changed, 30 insertions(+), 16 deletions(-)

5330916f5a11d8b7def46a6b3e14a831684032f5
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 0455aa7..f26c005 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -698,16 +698,26 @@ int device_add(struct device *dev)
 	}
 
 	if (dev->class) {
-		sysfs_create_link(&dev->kobj, &dev->class->subsys.kobj,
-				  "subsystem");
+		error = sysfs_create_link(&dev->kobj, &dev->class->subsys.kobj,
+					  "subsystem");
+		if (error)
+			goto ClassSubsysError;
+
 		/* 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.kobj)
-			sysfs_create_link(&dev->class->subsys.kobj,
-					  &dev->kobj, dev->bus_id);
+		if (dev->kobj.parent != &dev->class->subsys.kobj) {
+			error = sysfs_create_link(&dev->class->subsys.kobj,
+						  &dev->kobj, dev->bus_id);
+			if (error)
+				goto ClassDevLinkError;
+		}
+
 		if (parent) {
-			sysfs_create_link(&dev->kobj, &dev->parent->kobj,
-							"device");
+			error = sysfs_create_link(&dev->kobj,&dev->parent->kobj,
+						  "device");
+			if (error)
+				goto ParentDevLinkError;
+
 #ifdef CONFIG_SYSFS_DEPRECATED
 			class_name = make_class_name(dev->class->name,
 							&dev->kobj);
@@ -755,16 +765,7 @@ int device_add(struct device *dev)
 					     BUS_NOTIFY_DEL_DEVICE, dev);
 	device_remove_attrs(dev);
  AttrsError:
-	if (MAJOR(dev->devt))
-		device_remove_file(dev, &devt_attr);
-
 	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.kobj)
-			sysfs_remove_link(&dev->class->subsys.kobj,
-					  dev->bus_id);
 		if (parent) {
 #ifdef CONFIG_SYSFS_DEPRECATED
 			char *class_name = make_class_name(dev->class->name,
@@ -776,7 +777,20 @@ int device_add(struct device *dev)
 #endif
 			sysfs_remove_link(&dev->kobj, "device");
 		}
+
+ ParentDevLinkError:
+		/* If this is not a "fake" compatible device, remove the
+		 * symlink from the class to the device. */
+		if (dev->kobj.parent != &dev->class->subsys.kobj)
+			sysfs_remove_link(&dev->class->subsys.kobj,
+					  dev->bus_id);
+
+ ClassDevLinkError:
+		sysfs_remove_link(&dev->kobj, "subsystem");
 	}
+ ClassSubsysError:
+	if (MAJOR(dev->devt))
+		device_remove_file(dev, &devt_attr);
  ueventattrError:
 	device_remove_file(dev, &uevent_attr);
  attrError:

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-07-18  9:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-18  5:53 [PATCH 1/3] drivers/base/core: improve device_add() error handling, fix bugs Jeff Garzik
2007-07-18  5:55 ` [PATCH 2/3] drivers/video/aty/radeon_base: fix radeonfb_pci_register() err handling Jeff Garzik
2007-07-18  5:56 ` [PATCH 3/3] x86-64: make flush_tlb_kernel_range() a static inline function Jeff Garzik
2007-07-18  8:15 ` [PATCH 1/3] drivers/base/core: improve device_add() error handling, fix bugs Cornelia Huck
2007-07-18  8:16   ` Jeff Garzik
2007-07-18  8:36     ` Greg KH
2007-07-18  8:57       ` Cornelia Huck
2007-07-18  9:00         ` Jeff Garzik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox