Skip to content

Commit

Permalink
kobject: Cleanup kobject_rename and !CONFIG_SYSFS
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Tejun Heo <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
ebiederm authored and gregkh committed Oct 16, 2008
1 parent 030c1d2 commit 0b4a4fe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
6 changes: 1 addition & 5 deletions fs/sysfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -829,16 +829,12 @@ int sysfs_rename_dir(struct kobject * kobj, const char *new_name)
if (!new_dentry)
goto out_unlock;

/* rename kobject and sysfs_dirent */
/* rename sysfs_dirent */
error = -ENOMEM;
new_name = dup_name = kstrdup(new_name, GFP_KERNEL);
if (!new_name)
goto out_unlock;

error = kobject_set_name(kobj, "%s", new_name);
if (error)
goto out_unlock;

dup_name = sd->s_name;
sd->s_name = new_name;

Expand Down
4 changes: 1 addition & 3 deletions include/linux/sysfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
struct kobject;
struct module;

extern int kobject_set_name(struct kobject *kobj, const char *name, ...)
__attribute__((format(printf, 2, 3)));
/* FIXME
* The *owner field is no longer used, but leave around
* until the tree gets cleaned up fully.
Expand Down Expand Up @@ -149,7 +147,7 @@ static inline void sysfs_remove_dir(struct kobject *kobj)

static inline int sysfs_rename_dir(struct kobject *kobj, const char *new_name)
{
return kobject_set_name(kobj, "%s", new_name);
return 0;
}

static inline int sysfs_move_dir(struct kobject *kobj,
Expand Down
17 changes: 15 additions & 2 deletions lib/kobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -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);
Expand Down

0 comments on commit 0b4a4fe

Please sign in to comment.