aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/base.h1
-rw-r--r--drivers/base/class.c31
2 files changed, 18 insertions, 14 deletions
diff --git a/drivers/base/base.h b/drivers/base/base.h
index 79115eff6e94..c3b8dc98b8a7 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -42,4 +42,5 @@ struct class_device_attribute *to_class_dev_attr(struct attribute *_attr)
42 return container_of(_attr, struct class_device_attribute, attr); 42 return container_of(_attr, struct class_device_attribute, attr);
43} 43}
44 44
45extern char *make_class_name(const char *name, struct kobject *kobj);
45 46
diff --git a/drivers/base/class.c b/drivers/base/class.c
index 4b598be0e4b6..41a8e0934e3a 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -504,22 +504,21 @@ void class_device_initialize(struct class_device *class_dev)
504 INIT_LIST_HEAD(&class_dev->node); 504 INIT_LIST_HEAD(&class_dev->node);
505} 505}
506 506
507static char *make_class_name(struct class_device *class_dev) 507char *make_class_name(const char *name, struct kobject *kobj)
508{ 508{
509 char *name; 509 char *class_name;
510 int size; 510 int size;
511 511
512 size = strlen(class_dev->class->name) + 512 size = strlen(name) + strlen(kobject_name(kobj)) + 2;
513 strlen(kobject_name(&class_dev->kobj)) + 2;
514 513
515 name = kmalloc(size, GFP_KERNEL); 514 class_name = kmalloc(size, GFP_KERNEL);
516 if (!name) 515 if (!class_name)
517 return ERR_PTR(-ENOMEM); 516 return ERR_PTR(-ENOMEM);
518 517
519 strcpy(name, class_dev->class->name); 518 strcpy(class_name, name);
520 strcat(name, ":"); 519 strcat(class_name, ":");
521 strcat(name, kobject_name(&class_dev->kobj)); 520 strcat(class_name, kobject_name(kobj));
522 return name; 521 return class_name;
523} 522}
524 523
525int class_device_add(struct class_device *class_dev) 524int class_device_add(struct class_device *class_dev)
@@ -594,7 +593,8 @@ int class_device_add(struct class_device *class_dev)
594 goto out5; 593 goto out5;
595 594
596 if (class_dev->dev) { 595 if (class_dev->dev) {
597 class_name = make_class_name(class_dev); 596 class_name = make_class_name(class_dev->class->name,
597 &class_dev->kobj);
598 error = sysfs_create_link(&class_dev->kobj, 598 error = sysfs_create_link(&class_dev->kobj,
599 &class_dev->dev->kobj, "device"); 599 &class_dev->dev->kobj, "device");
600 if (error) 600 if (error)
@@ -731,7 +731,8 @@ void class_device_del(struct class_device *class_dev)
731 } 731 }
732 732
733 if (class_dev->dev) { 733 if (class_dev->dev) {
734 class_name = make_class_name(class_dev); 734 class_name = make_class_name(class_dev->class->name,
735 &class_dev->kobj);
735 sysfs_remove_link(&class_dev->kobj, "device"); 736 sysfs_remove_link(&class_dev->kobj, "device");
736 sysfs_remove_link(&class_dev->dev->kobj, class_name); 737 sysfs_remove_link(&class_dev->dev->kobj, class_name);
737 } 738 }
@@ -796,14 +797,16 @@ int class_device_rename(struct class_device *class_dev, char *new_name)
796 new_name); 797 new_name);
797 798
798 if (class_dev->dev) 799 if (class_dev->dev)
799 old_class_name = make_class_name(class_dev); 800 old_class_name = make_class_name(class_dev->class->name,
801 &class_dev->kobj);
800 802
801 strlcpy(class_dev->class_id, new_name, KOBJ_NAME_LEN); 803 strlcpy(class_dev->class_id, new_name, KOBJ_NAME_LEN);
802 804
803 error = kobject_rename(&class_dev->kobj, new_name); 805 error = kobject_rename(&class_dev->kobj, new_name);
804 806
805 if (class_dev->dev) { 807 if (class_dev->dev) {
806 new_class_name = make_class_name(class_dev); 808 new_class_name = make_class_name(class_dev->class->name,
809 &class_dev->kobj);
807 sysfs_create_link(&class_dev->dev->kobj, &class_dev->kobj, 810 sysfs_create_link(&class_dev->dev->kobj, &class_dev->kobj,
808 new_class_name); 811 new_class_name);
809 sysfs_remove_link(&class_dev->dev->kobj, old_class_name); 812 sysfs_remove_link(&class_dev->dev->kobj, old_class_name);