Skip to content

Commit

Permalink
kobject: check for duplicate names in kobject_rename
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Greg Kroah-Hartman committed Oct 31, 2007
1 parent fcd239d commit 34358c2
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/kobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,19 @@ int kobject_rename(struct kobject * kobj, const char *new_name)
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;
Expand Down

0 comments on commit 34358c2

Please sign in to comment.