mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Cornelia Huck <cornelia.huck@de.ibm.com>
To: Andrew Morton <akpm@osdl.org>
Cc: Greg K-H <greg@kroah.com>, linux-kernel@vger.kernel.org
Subject: [Patch] [2.6.18-rc2-mm1] Return code checking for make_class_name()
Date: Thu, 27 Jul 2006 17:17:11 +0200	[thread overview]
Message-ID: <20060727171711.6fe210aa@gondolin.boeblingen.de.ibm.com> (raw)

From: Cornelia Huck <cornelia.huck@de.ibm.com>

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

CC: Greg K-H <greg@kroah.com>
Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>

 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);

                 reply	other threads:[~2006-07-27 15:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060727171711.6fe210aa@gondolin.boeblingen.de.ibm.com \
    --to=cornelia.huck@de.ibm.com \
    --cc=akpm@osdl.org \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®