Commit 51c0c34c authored by Maneesh Soni's avatar Maneesh Soni Committed by Greg Kroah-Hartman

[PATCH] sysfs_rename_dir-cleanup

o The following patch cleans up sysfs_rename_dir(). It now checks the
  return code of kobject_set_name() and propagates the error code to its
  callers. Because of this there are changes in the following two APIs. Both
  return int instead of void.

int sysfs_rename_dir(struct kobject * kobj, const char *new_name)
int kobject_rename(struct kobject * kobj, char *new_name)
parent f00beb55
...@@ -361,6 +361,8 @@ void class_device_unregister(struct class_device *class_dev) ...@@ -361,6 +361,8 @@ void class_device_unregister(struct class_device *class_dev)
int class_device_rename(struct class_device *class_dev, char *new_name) int class_device_rename(struct class_device *class_dev, char *new_name)
{ {
int error = 0;
class_dev = class_device_get(class_dev); class_dev = class_device_get(class_dev);
if (!class_dev) if (!class_dev)
return -EINVAL; return -EINVAL;
...@@ -370,11 +372,11 @@ int class_device_rename(struct class_device *class_dev, char *new_name) ...@@ -370,11 +372,11 @@ int class_device_rename(struct class_device *class_dev, char *new_name)
strlcpy(class_dev->class_id, new_name, KOBJ_NAME_LEN); strlcpy(class_dev->class_id, new_name, KOBJ_NAME_LEN);
kobject_rename(&class_dev->kobj, new_name); error = kobject_rename(&class_dev->kobj, new_name);
class_device_put(class_dev); class_device_put(class_dev);
return 0; return error;
} }
struct class_device * class_device_get(struct class_device *class_dev) struct class_device * class_device_get(struct class_device *class_dev)
......
...@@ -154,24 +154,33 @@ void sysfs_remove_dir(struct kobject * kobj) ...@@ -154,24 +154,33 @@ void sysfs_remove_dir(struct kobject * kobj)
dput(dentry); dput(dentry);
} }
void sysfs_rename_dir(struct kobject * kobj, const char *new_name) int sysfs_rename_dir(struct kobject * kobj, const char *new_name)
{ {
int error = 0;
struct dentry * new_dentry, * parent; struct dentry * new_dentry, * parent;
if (!strcmp(kobject_name(kobj), new_name)) if (!strcmp(kobject_name(kobj), new_name))
return; return -EINVAL;
if (!kobj->parent) if (!kobj->parent)
return; return -EINVAL;
parent = kobj->parent->dentry; parent = kobj->parent->dentry;
down(&parent->d_inode->i_sem); down(&parent->d_inode->i_sem);
new_dentry = sysfs_get_dentry(parent, new_name); new_dentry = sysfs_get_dentry(parent, new_name);
d_move(kobj->dentry, new_dentry); if (!IS_ERR(new_dentry)) {
kobject_set_name(kobj,new_name); if (!new_dentry->d_inode) {
error = kobject_set_name(kobj,new_name);
if (!error)
d_move(kobj->dentry, new_dentry);
}
dput(new_dentry);
}
up(&parent->d_inode->i_sem); up(&parent->d_inode->i_sem);
return error;
} }
EXPORT_SYMBOL(sysfs_create_dir); EXPORT_SYMBOL(sysfs_create_dir);
......
...@@ -48,7 +48,7 @@ extern void kobject_cleanup(struct kobject *); ...@@ -48,7 +48,7 @@ extern void kobject_cleanup(struct kobject *);
extern int kobject_add(struct kobject *); extern int kobject_add(struct kobject *);
extern void kobject_del(struct kobject *); extern void kobject_del(struct kobject *);
extern void kobject_rename(struct kobject *, char *new_name); extern int kobject_rename(struct kobject *, char *new_name);
extern int kobject_register(struct kobject *); extern int kobject_register(struct kobject *);
extern void kobject_unregister(struct kobject *); extern void kobject_unregister(struct kobject *);
......
...@@ -44,7 +44,7 @@ sysfs_create_dir(struct kobject *); ...@@ -44,7 +44,7 @@ sysfs_create_dir(struct kobject *);
extern void extern void
sysfs_remove_dir(struct kobject *); sysfs_remove_dir(struct kobject *);
extern void extern int
sysfs_rename_dir(struct kobject *, const char *new_name); sysfs_rename_dir(struct kobject *, const char *new_name);
extern int extern int
......
...@@ -385,13 +385,17 @@ EXPORT_SYMBOL(kobject_set_name); ...@@ -385,13 +385,17 @@ EXPORT_SYMBOL(kobject_set_name);
* @new_name: object's new name * @new_name: object's new name
*/ */
void kobject_rename(struct kobject * kobj, char *new_name) int kobject_rename(struct kobject * kobj, char *new_name)
{ {
int error = 0;
kobj = kobject_get(kobj); kobj = kobject_get(kobj);
if (!kobj) if (!kobj)
return; return -EINVAL;
sysfs_rename_dir(kobj, new_name); error = sysfs_rename_dir(kobj, new_name);
kobject_put(kobj); kobject_put(kobj);
return error;
} }
/** /**
......
...@@ -792,6 +792,8 @@ int dev_alloc_name(struct net_device *dev, const char *name) ...@@ -792,6 +792,8 @@ int dev_alloc_name(struct net_device *dev, const char *name)
*/ */
int dev_change_name(struct net_device *dev, char *newname) int dev_change_name(struct net_device *dev, char *newname)
{ {
int err = 0;
ASSERT_RTNL(); ASSERT_RTNL();
if (dev->flags & IFF_UP) if (dev->flags & IFF_UP)
...@@ -801,7 +803,7 @@ int dev_change_name(struct net_device *dev, char *newname) ...@@ -801,7 +803,7 @@ int dev_change_name(struct net_device *dev, char *newname)
return -EINVAL; return -EINVAL;
if (strchr(newname, '%')) { if (strchr(newname, '%')) {
int err = dev_alloc_name(dev, newname); err = dev_alloc_name(dev, newname);
if (err < 0) if (err < 0)
return err; return err;
strcpy(newname, dev->name); strcpy(newname, dev->name);
...@@ -811,12 +813,14 @@ int dev_change_name(struct net_device *dev, char *newname) ...@@ -811,12 +813,14 @@ int dev_change_name(struct net_device *dev, char *newname)
else else
strlcpy(dev->name, newname, IFNAMSIZ); strlcpy(dev->name, newname, IFNAMSIZ);
hlist_del(&dev->name_hlist); err = class_device_rename(&dev->class_dev, dev->name);
hlist_add_head(&dev->name_hlist, dev_name_hash(dev->name)); if (!err) {
hlist_del(&dev->name_hlist);
hlist_add_head(&dev->name_hlist, dev_name_hash(dev->name));
notifier_call_chain(&netdev_chain, NETDEV_CHANGENAME, dev);
}
class_device_rename(&dev->class_dev, dev->name); return err;
notifier_call_chain(&netdev_chain, NETDEV_CHANGENAME, dev);
return 0;
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment