aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/class.c21
-rw-r--r--drivers/base/core.c17
2 files changed, 25 insertions, 13 deletions
diff --git a/drivers/base/class.c b/drivers/base/class.c
index 8bf2ca2e56b5..96def1ddba19 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -364,7 +364,7 @@ char *make_class_name(const char *name, struct kobject *kobj)
364 364
365 class_name = kmalloc(size, GFP_KERNEL); 365 class_name = kmalloc(size, GFP_KERNEL);
366 if (!class_name) 366 if (!class_name)
367 return ERR_PTR(-ENOMEM); 367 return NULL;
368 368
369 strcpy(class_name, name); 369 strcpy(class_name, name);
370 strcat(class_name, ":"); 370 strcat(class_name, ":");
@@ -411,8 +411,11 @@ static int make_deprecated_class_device_links(struct class_device *class_dev)
411 return 0; 411 return 0;
412 412
413 class_name = make_class_name(class_dev->class->name, &class_dev->kobj); 413 class_name = make_class_name(class_dev->class->name, &class_dev->kobj);
414 error = sysfs_create_link(&class_dev->dev->kobj, &class_dev->kobj, 414 if (class_name)
415 class_name); 415 error = sysfs_create_link(&class_dev->dev->kobj,
416 &class_dev->kobj, class_name);
417 else
418 error = -ENOMEM;
416 kfree(class_name); 419 kfree(class_name);
417 return error; 420 return error;
418} 421}
@@ -425,7 +428,8 @@ static void remove_deprecated_class_device_links(struct class_device *class_dev)
425 return; 428 return;
426 429
427 class_name = make_class_name(class_dev->class->name, &class_dev->kobj); 430 class_name = make_class_name(class_dev->class->name, &class_dev->kobj);
428 sysfs_remove_link(&class_dev->dev->kobj, class_name); 431 if (class_name)
432 sysfs_remove_link(&class_dev->dev->kobj, class_name);
429 kfree(class_name); 433 kfree(class_name);
430} 434}
431#else 435#else
@@ -863,9 +867,12 @@ int class_device_rename(struct class_device *class_dev, char *new_name)
863 if (class_dev->dev) { 867 if (class_dev->dev) {
864 new_class_name = make_class_name(class_dev->class->name, 868 new_class_name = make_class_name(class_dev->class->name,
865 &class_dev->kobj); 869 &class_dev->kobj);
866 sysfs_create_link(&class_dev->dev->kobj, &class_dev->kobj, 870 if (new_class_name)
867 new_class_name); 871 sysfs_create_link(&class_dev->dev->kobj,
868 sysfs_remove_link(&class_dev->dev->kobj, old_class_name); 872 &class_dev->kobj, new_class_name);
873 if (old_class_name)
874 sysfs_remove_link(&class_dev->dev->kobj,
875 old_class_name);
869 } 876 }
870#endif 877#endif
871 class_device_put(class_dev); 878 class_device_put(class_dev);
diff --git a/drivers/base/core.c b/drivers/base/core.c
index c60114dbe5f5..6fee3e6b1ac2 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -527,9 +527,13 @@ int device_add(struct device *dev)
527 &dev->kobj, dev->bus_id); 527 &dev->kobj, dev->bus_id);
528#ifdef CONFIG_SYSFS_DEPRECATED 528#ifdef CONFIG_SYSFS_DEPRECATED
529 if (parent) { 529 if (parent) {
530 sysfs_create_link(&dev->kobj, &dev->parent->kobj, "device"); 530 sysfs_create_link(&dev->kobj, &dev->parent->kobj,
531 class_name = make_class_name(dev->class->name, &dev->kobj); 531 "device");
532 sysfs_create_link(&dev->parent->kobj, &dev->kobj, class_name); 532 class_name = make_class_name(dev->class->name,
533 &dev->kobj);
534 if (class_name)
535 sysfs_create_link(&dev->parent->kobj,
536 &dev->kobj, class_name);
533 } 537 }
534#endif 538#endif
535 } 539 }
@@ -672,7 +676,9 @@ void device_del(struct device * dev)
672 if (parent) { 676 if (parent) {
673 char *class_name = make_class_name(dev->class->name, 677 char *class_name = make_class_name(dev->class->name,
674 &dev->kobj); 678 &dev->kobj);
675 sysfs_remove_link(&dev->parent->kobj, class_name); 679 if (class_name)
680 sysfs_remove_link(&dev->parent->kobj,
681 class_name);
676 kfree(class_name); 682 kfree(class_name);
677 sysfs_remove_link(&dev->kobj, "device"); 683 sysfs_remove_link(&dev->kobj, "device");
678 } 684 }
@@ -975,8 +981,7 @@ static int device_move_class_links(struct device *dev,
975 981
976 class_name = make_class_name(dev->class->name, &dev->kobj); 982 class_name = make_class_name(dev->class->name, &dev->kobj);
977 if (!class_name) { 983 if (!class_name) {
978 error = PTR_ERR(class_name); 984 error = -ENOMEM;
979 class_name = NULL;
980 goto out; 985 goto out;
981 } 986 }
982 if (old_parent) { 987 if (old_parent) {