forked from luck/tmp_suning_uos_patched
[PATCH] fix class symlinks in sysfs
The class symlinks in sysfs don't properly handle changing device names. To demonstrate, rename your network device from eth0 to eth1. Your pci (or usb, or whatever) device will still have a 'net:eth0' link, except now it points to /sys/class/net/eth1. The attached patch makes sure the class symlink name changes when the class device name changes. It isn't 100% correct, it should be using sysfs_rename_link. Unfortunately, sysfs_rename_link doesn't exist. Signed-off-by: Bill Nottingham <notting@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
parent
d305ef5d2a
commit
3e51377dc4
@ -669,6 +669,7 @@ void class_device_destroy(struct class *cls, dev_t devt)
|
|||||||
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;
|
int error = 0;
|
||||||
|
char *old_class_name = NULL, *new_class_name = NULL;
|
||||||
|
|
||||||
class_dev = class_device_get(class_dev);
|
class_dev = class_device_get(class_dev);
|
||||||
if (!class_dev)
|
if (!class_dev)
|
||||||
@ -677,12 +678,24 @@ int class_device_rename(struct class_device *class_dev, char *new_name)
|
|||||||
pr_debug("CLASS: renaming '%s' to '%s'\n", class_dev->class_id,
|
pr_debug("CLASS: renaming '%s' to '%s'\n", class_dev->class_id,
|
||||||
new_name);
|
new_name);
|
||||||
|
|
||||||
|
if (class_dev->dev)
|
||||||
|
old_class_name = make_class_name(class_dev);
|
||||||
|
|
||||||
strlcpy(class_dev->class_id, new_name, KOBJ_NAME_LEN);
|
strlcpy(class_dev->class_id, new_name, KOBJ_NAME_LEN);
|
||||||
|
|
||||||
error = kobject_rename(&class_dev->kobj, new_name);
|
error = kobject_rename(&class_dev->kobj, new_name);
|
||||||
|
|
||||||
|
if (class_dev->dev) {
|
||||||
|
new_class_name = make_class_name(class_dev);
|
||||||
|
sysfs_create_link(&class_dev->dev->kobj, &class_dev->kobj,
|
||||||
|
new_class_name);
|
||||||
|
sysfs_remove_link(&class_dev->dev->kobj, old_class_name);
|
||||||
|
}
|
||||||
class_device_put(class_dev);
|
class_device_put(class_dev);
|
||||||
|
|
||||||
|
kfree(old_class_name);
|
||||||
|
kfree(new_class_name);
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user