[Patch] [2.6.18-rc2-mm1] Return code checking for make_class_name()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Cornelia Huck <[email protected]>

make_class_name() may return an error pointer. Make sure that all
callers in the driver core check for it.

CC: Greg K-H <[email protected]>
Signed-off-by: Cornelia Huck <[email protected]>

 class.c |   25 ++++++++++++++++++++++---
 core.c  |   11 +++++++----
 2 files changed, 29 insertions(+), 7 deletions(-)

diff -Naurp linux-2.6.18-rc2-mm1/drivers/base/class.c linux-2.6.18-rc2-mm1+CH/drivers/base/class.c
--- linux-2.6.18-rc2-mm1/drivers/base/class.c	2006-07-27 16:43:25.000000000 +0200
+++ linux-2.6.18-rc2-mm1+CH/drivers/base/class.c	2006-07-27 16:39:14.000000000 +0200
@@ -602,6 +602,11 @@ int class_device_add(struct class_device
 	if (class_dev->dev) {
 		class_name = make_class_name(class_dev->class->name,
 					     &class_dev->kobj);
+		if (IS_ERR(class_name)) {
+			error = PTR_ERR(class_name);
+			class_name = NULL;
+			goto out6;
+		}
 		error = sysfs_create_link(&class_dev->kobj,
 					  &class_dev->dev->kobj, "device");
 		if (error)
@@ -741,7 +746,11 @@ void class_device_del(struct class_devic
 		class_name = make_class_name(class_dev->class->name,
 					     &class_dev->kobj);
 		sysfs_remove_link(&class_dev->kobj, "device");
-		sysfs_remove_link(&class_dev->dev->kobj, class_name);
+		if (!IS_ERR(class_name))
+			sysfs_remove_link(&class_dev->dev->kobj, class_name);
+		else
+			/* Hmm, don't know what else to do */
+			class_name = NULL;
 	}
 	sysfs_remove_link(&class_dev->kobj, "subsystem");
 	class_device_remove_file(class_dev, &class_dev->uevent_attr);
@@ -804,10 +813,15 @@ int class_device_rename(struct class_dev
 	pr_debug("CLASS: renaming '%s' to '%s'\n", class_dev->class_id,
 		 new_name);
 
-	if (class_dev->dev)
+	if (class_dev->dev) {
 		old_class_name = make_class_name(class_dev->class->name,
 						 &class_dev->kobj);
-
+		if (IS_ERR(old_class_name)) {
+			error = PTR_ERR(old_class_name);
+			old_class_name = NULL;
+			goto out;
+		}
+	}
 	strlcpy(class_dev->class_id, new_name, KOBJ_NAME_LEN);
 
 	error = kobject_rename(&class_dev->kobj, new_name);
@@ -815,6 +829,11 @@ int class_device_rename(struct class_dev
 	if (class_dev->dev) {
 		new_class_name = make_class_name(class_dev->class->name,
 						 &class_dev->kobj);
+		if (IS_ERR(new_class_name)) {
+			error = PTR_ERR(new_class_name);
+			new_class_name = NULL;
+			goto out;
+		}
 		error = sysfs_create_link(&class_dev->dev->kobj,
 					  &class_dev->kobj, new_class_name);
 		if (error)
diff -Naurp linux-2.6.18-rc2-mm1/drivers/base/core.c linux-2.6.18-rc2-mm1+CH/drivers/base/core.c
--- linux-2.6.18-rc2-mm1/drivers/base/core.c	2006-07-27 16:43:25.000000000 +0200
+++ linux-2.6.18-rc2-mm1+CH/drivers/base/core.c	2006-07-27 16:41:03.000000000 +0200
@@ -608,11 +608,14 @@ void device_del(struct device * dev)
 		sysfs_remove_link(&dev->kobj, "subsystem");
 		sysfs_remove_link(&dev->class->subsys.kset.kobj, dev->bus_id);
 		class_name = make_class_name(dev->class->name, &dev->kobj);
-		if (parent) {
-			sysfs_remove_link(&dev->kobj, "device");
-			sysfs_remove_link(&dev->parent->kobj, class_name);
+		if (!IS_ERR(class_name)) {
+			if (parent) {
+				sysfs_remove_link(&dev->kobj, "device");
+				sysfs_remove_link(&dev->parent->kobj,
+						  class_name);
+			}
+			kfree(class_name);
 		}
-		kfree(class_name);
 		down(&dev->class->sem);
 		list_del_init(&dev->node);
 		up(&dev->class->sem);
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux