提交 34358c26 编写于 作者: G Greg Kroah-Hartman

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: NGreg Kroah-Hartman <gregkh@suse.de>
上级 fcd239d3
...@@ -308,6 +308,19 @@ int kobject_rename(struct kobject * kobj, const char *new_name) ...@@ -308,6 +308,19 @@ int kobject_rename(struct kobject * kobj, const char *new_name)
if (!kobj->parent) if (!kobj->parent)
return -EINVAL; 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); devpath = kobject_get_path(kobj, GFP_KERNEL);
if (!devpath) { if (!devpath) {
error = -ENOMEM; error = -ENOMEM;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册