Re: sysfs: WARNING: at fs/sysfs/dir.c:424 sysfs_add_one()

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Greg KH
Date: Friday, October 26, 2007 - 8:50 am

On Fri, Oct 26, 2007 at 12:44:38PM +0530, Amit Shah wrote:

I sent out the patch below for comments, yet no one did :(

Can you try it out and let me know if it works for you or not?

thanks,

greg k-h

------------
From: Greg Kroah-Hartman <gregkh@suse.de>
Subject: kobject: check for duplicate names in kobject_rename

This should catch any duplicate names before we try to tell sysfs to
rename the object.  This happens a lot with older versions of udev and
the network rename scripts.

Cc: David Miller <davem@davemloft.net>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <htejun@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 lib/kobject.c |   13 +++++++++++++
 1 file changed, 13 insertions(+)

--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -308,6 +308,19 @@ int kobject_rename(struct kobject * kobj
 	if (!kobj->parent)
 		return -EINVAL;
 
+	/* see if this name is already in use */
+	if (kobj->kset) {
+		struct kobject *temp_kobj;
+		temp_kobj = kset_find_obj(kobj->kset, new_name);
+		if (temp_kobj) {
+			printk(KERN_WARNING "kobject '%s' can not be renamed "
+			       "to '%s' as '%s' is already in existance.\n",
+			       kobject_name(kobj), new_name, new_name);
+			kobject_put(temp_kobj);
+			return -EINVAL;
+		}
+	}
+
 	devpath = kobject_get_path(kobj, GFP_KERNEL);
 	if (!devpath) {
 		error = -ENOMEM;
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: sysfs: WARNING: at fs/sysfs/dir.c:424 sysfs_add_one() ..., Kamalesh Babulal, (Fri Oct 26, 2:17 am)
Re: sysfs: WARNING: at fs/sysfs/dir.c:424 sysfs_add_one(), Greg KH, (Fri Oct 26, 8:50 am)
Re: [alsa-devel] sysfs: WARNING: at fs/sysfs/dir.c:424 sys ..., Kamalesh Babulal, (Fri Oct 26, 10:15 am)
Re: [alsa-devel] sysfs: WARNING: at fs/sysfs/dir.c:424 sys ..., Kamalesh Babulal, (Fri Oct 26, 10:17 am)