diff options
author | Greg Kroah-Hartman <gregkh@suse.de> | 2006-07-03 17:31:12 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-09-26 00:08:38 -0400 |
commit | a2de48cace5d0993da6cfa28b276ae724dc3569b (patch) | |
tree | e4b1107ec3167c8d0064fe756bde6e0d53cf8c93 /drivers | |
parent | 2620efef7029bb040430f50f0fc148f2d5e002ad (diff) |
Driver core: add device_rename function
The network layer needs this to convert to using struct device instead
of a struct class_device.
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/base/core.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c index f1228f25efe0..0db47561331e 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
@@ -736,3 +736,58 @@ void device_destroy(struct class *class, dev_t devt) | |||
736 | device_unregister(dev); | 736 | device_unregister(dev); |
737 | } | 737 | } |
738 | EXPORT_SYMBOL_GPL(device_destroy); | 738 | EXPORT_SYMBOL_GPL(device_destroy); |
739 | |||
740 | /** | ||
741 | * device_rename - renames a device | ||
742 | * @dev: the pointer to the struct device to be renamed | ||
743 | * @new_name: the new name of the device | ||
744 | */ | ||
745 | int device_rename(struct device *dev, char *new_name) | ||
746 | { | ||
747 | char *old_class_name = NULL; | ||
748 | char *new_class_name = NULL; | ||
749 | char *old_symlink_name = NULL; | ||
750 | int error; | ||
751 | |||
752 | dev = get_device(dev); | ||
753 | if (!dev) | ||
754 | return -EINVAL; | ||
755 | |||
756 | pr_debug("DEVICE: renaming '%s' to '%s'\n", dev->bus_id, new_name); | ||
757 | |||
758 | if ((dev->class) && (dev->parent)) | ||
759 | old_class_name = make_class_name(dev->class->name, &dev->kobj); | ||
760 | |||
761 | if (dev->class) { | ||
762 | old_symlink_name = kmalloc(BUS_ID_SIZE, GFP_KERNEL); | ||
763 | if (!old_symlink_name) | ||
764 | return -ENOMEM; | ||
765 | strlcpy(old_symlink_name, dev->bus_id, BUS_ID_SIZE); | ||
766 | } | ||
767 | |||
768 | strlcpy(dev->bus_id, new_name, BUS_ID_SIZE); | ||
769 | |||
770 | error = kobject_rename(&dev->kobj, new_name); | ||
771 | |||
772 | if (old_class_name) { | ||
773 | new_class_name = make_class_name(dev->class->name, &dev->kobj); | ||
774 | if (new_class_name) { | ||
775 | sysfs_create_link(&dev->parent->kobj, &dev->kobj, | ||
776 | new_class_name); | ||
777 | sysfs_remove_link(&dev->parent->kobj, old_class_name); | ||
778 | } | ||
779 | } | ||
780 | if (dev->class) { | ||
781 | sysfs_remove_link(&dev->class->subsys.kset.kobj, | ||
782 | old_symlink_name); | ||
783 | sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj, | ||
784 | dev->bus_id); | ||
785 | } | ||
786 | put_device(dev); | ||
787 | |||
788 | kfree(old_class_name); | ||
789 | kfree(new_class_name); | ||
790 | kfree(old_symlink_name); | ||
791 | |||
792 | return error; | ||
793 | } | ||