summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2008-07-03 18:05:28 -0700
committerGreg Kroah-Hartman <gregkh@suse.de>2008-10-16 09:24:52 -0700
commit0b4a4fea253e1296222603ccc55430ed7cd9413a (patch)
tree5ce1810393a0f3a48ac208e0dbf994b63a481f18 /lib
parent030c1d2bfcc2187650fb975456ca0b61a5bb77f4 (diff)
kobject: Cleanup kobject_rename and !CONFIG_SYSFS
It finally dawned on me what the clean fix to sysfs_rename_dir calling kobject_set_name is. Move the work into kobject_rename where it belongs. The callers serialize us anyway so this is safe. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/kobject.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/kobject.c b/lib/kobject.c
index ae6bb900bfb..0487d1f6480 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -397,6 +397,7 @@ int kobject_rename(struct kobject *kobj, const char *new_name)
{
int error = 0;
const char *devpath = NULL;
+ const char *dup_name = NULL, *name;
char *devpath_string = NULL;
char *envp[2];
@@ -420,15 +421,27 @@ int kobject_rename(struct kobject *kobj, const char *new_name)
envp[0] = devpath_string;
envp[1] = NULL;
+ name = dup_name = kstrdup(new_name, GFP_KERNEL);
+ if (!name) {
+ error = -ENOMEM;
+ goto out;
+ }
+
error = sysfs_rename_dir(kobj, new_name);
+ if (error)
+ goto out;
+
+ /* Install the new kobject name */
+ dup_name = kobj->name;
+ kobj->name = name;
/* This function is mostly/only used for network interface.
* Some hotplug package track interfaces by their name and
* therefore want to know when the name is changed by the user. */
- if (!error)
- kobject_uevent_env(kobj, KOBJ_MOVE, envp);
+ kobject_uevent_env(kobj, KOBJ_MOVE, envp);
out:
+ kfree(dup_name);
kfree(devpath_string);
kfree(devpath);
kobject_put(kobj);