From: Cornelia Huck <cornelia.huck@de.ibm.com>
To: Greg K-H <greg@kroah.com>
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Subject: [01/12] driver core fixes: make_class_name() retval check
Date: Wed, 13 Sep 2006 18:38:34 +0200 [thread overview]
Message-ID: <20060913183834.3a71bbbe@gondolin.boeblingen.de.ibm.com> (raw)
In-Reply-To: <20060913163007.21cf10a8@gondolin.boeblingen.de.ibm.com>
From: Cornelia Huck <cornelia.huck@de.ibm.com>
make_class_name() may return an error pointer. Audit the callers in the
driver core.
Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
class.c | 11 ++++++++++-
core.c | 31 +++++++++++++++++++++++--------
2 files changed, 33 insertions(+), 9 deletions(-)
diff -Naurp linux-2.6.18-rc6/drivers/base/class.c linux-2.6.18-rc6+CH/drivers/base/class.c
--- linux-2.6.18-rc6/drivers/base/class.c 2006-09-12 14:18:40.000000000 +0200
+++ linux-2.6.18-rc6+CH/drivers/base/class.c 2006-09-12 16:17:02.000000000 +0200
@@ -596,6 +596,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)
@@ -736,7 +741,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);
diff -Naurp linux-2.6.18-rc6/drivers/base/core.c linux-2.6.18-rc6+CH/drivers/base/core.c
--- linux-2.6.18-rc6/drivers/base/core.c 2006-09-12 14:18:57.000000000 +0200
+++ linux-2.6.18-rc6+CH/drivers/base/core.c 2006-09-12 16:17:02.000000000 +0200
@@ -437,7 +437,11 @@ int device_add(struct device *dev)
if ((parent) && (!device_is_virtual(dev))) {
sysfs_create_link(&dev->kobj, &dev->parent->kobj, "device");
class_name = make_class_name(dev->class->name, &dev->kobj);
- sysfs_create_link(&dev->parent->kobj, &dev->kobj, class_name);
+ if (!IS_ERR(class_name))
+ sysfs_create_link(&dev->parent->kobj,
+ &dev->kobj, class_name);
+ else
+ class_name = NULL;
}
}
@@ -557,12 +561,16 @@ void device_del(struct device * dev)
if (dev->class) {
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) && (!device_is_virtual(dev))) {
+ class_name = make_class_name(dev->class->name,
+ &dev->kobj);
sysfs_remove_link(&dev->kobj, "device");
- sysfs_remove_link(&dev->parent->kobj, class_name);
+ if (!IS_ERR(class_name)) {
+ 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);
@@ -763,9 +771,14 @@ int device_rename(struct device *dev, ch
pr_debug("DEVICE: renaming '%s' to '%s'\n", dev->bus_id, new_name);
- if ((dev->class) && (dev->parent))
+ if ((dev->class) && (dev->parent)) {
old_class_name = make_class_name(dev->class->name, &dev->kobj);
-
+ if (IS_ERR(old_class_name)) {
+ error = PTR_ERR(old_class_name);
+ old_class_name = NULL;
+ goto out;
+ }
+ }
if (dev->class) {
old_symlink_name = kmalloc(BUS_ID_SIZE, GFP_KERNEL);
if (!old_symlink_name)
@@ -779,11 +792,12 @@ int device_rename(struct device *dev, ch
if (old_class_name) {
new_class_name = make_class_name(dev->class->name, &dev->kobj);
- if (new_class_name) {
+ if (!IS_ERR(new_class_name)) {
sysfs_create_link(&dev->parent->kobj, &dev->kobj,
new_class_name);
sysfs_remove_link(&dev->parent->kobj, old_class_name);
- }
+ } else
+ new_class_name = NULL;
}
if (dev->class) {
sysfs_remove_link(&dev->class->subsys.kset.kobj,
@@ -791,6 +805,7 @@ int device_rename(struct device *dev, ch
sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj,
dev->bus_id);
}
+out:
put_device(dev);
kfree(old_class_name);
next parent reply other threads:[~2006-09-13 16:38 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20060913163007.21cf10a8@gondolin.boeblingen.de.ibm.com>
2006-09-13 16:38 ` Cornelia Huck [this message]
2006-09-14 12:01 ` Martin Waitz
2006-09-15 11:20 ` Cornelia Huck
2006-09-13 16:38 ` [02/12] driver core fixes: device_register() retval check in platform.c Cornelia Huck
2006-09-13 16:38 ` [03/12] driver core fixes: fixup platform_device_register_simple() Cornelia Huck
2006-09-14 2:31 ` Dmitry Torokhov
2006-09-14 7:06 ` Cornelia Huck
2006-09-13 16:38 ` [04/12] driver core fixes: retval check in class_register() Cornelia Huck
2006-09-13 16:38 ` [05/12] driver core fixes: sysfs_create_link() retval check in class.c Cornelia Huck
2006-09-13 16:38 ` [06/12] driver core fixes: bus_add_attrs() retval check Cornelia Huck
2006-09-13 16:38 ` [07/12] driver core fixes: bus_add_device() cleanup on error Cornelia Huck
[not found] ` <1158168423.14312.16.camel@localhost>
2006-09-14 7:40 ` Cornelia Huck
2006-09-13 16:38 ` [08/12] driver core fixes: device_add() " Cornelia Huck
2006-09-13 16:38 ` [09/12] driver core fixes: bus_attach_device() retval check Cornelia Huck
2006-09-13 16:39 ` [10/12] driver core fixes: sysfs_create_link() retval check in core.c Cornelia Huck
[not found] ` <1158168842.14312.18.camel@localhost>
2006-09-14 7:43 ` Cornelia Huck
2006-09-13 16:39 ` [11/12] driver core fixes: device_create_file() retval check in dmapool.c Cornelia Huck
2006-09-13 16:39 ` [12/12] driver core fixes: sysfs_create_group() retval in topology.c Cornelia Huck
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=20060913183834.3a71bbbe@gondolin.boeblingen.de.ibm.com \
--to=cornelia.huck@de.ibm.com \
--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®