diff options
author | Glenn Elliott <gelliott@cs.unc.edu> | 2012-03-04 19:47:13 -0500 |
---|---|---|
committer | Glenn Elliott <gelliott@cs.unc.edu> | 2012-03-04 19:47:13 -0500 |
commit | c71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch) | |
tree | ecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /drivers/base/core.c | |
parent | ea53c912f8a86a8567697115b6a0d8152beee5c8 (diff) | |
parent | 6a00f206debf8a5c8899055726ad127dbeeed098 (diff) |
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts:
litmus/sched_cedf.c
Diffstat (limited to 'drivers/base/core.c')
-rw-r--r-- | drivers/base/core.c | 310 |
1 files changed, 124 insertions, 186 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c index d1b2c9adc271..bc8729d603a7 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
@@ -26,6 +26,19 @@ | |||
26 | #include "base.h" | 26 | #include "base.h" |
27 | #include "power/power.h" | 27 | #include "power/power.h" |
28 | 28 | ||
29 | #ifdef CONFIG_SYSFS_DEPRECATED | ||
30 | #ifdef CONFIG_SYSFS_DEPRECATED_V2 | ||
31 | long sysfs_deprecated = 1; | ||
32 | #else | ||
33 | long sysfs_deprecated = 0; | ||
34 | #endif | ||
35 | static __init int sysfs_deprecated_setup(char *arg) | ||
36 | { | ||
37 | return strict_strtol(arg, 10, &sysfs_deprecated); | ||
38 | } | ||
39 | early_param("sysfs.deprecated", sysfs_deprecated_setup); | ||
40 | #endif | ||
41 | |||
29 | int (*platform_notify)(struct device *dev) = NULL; | 42 | int (*platform_notify)(struct device *dev) = NULL; |
30 | int (*platform_notify_remove)(struct device *dev) = NULL; | 43 | int (*platform_notify_remove)(struct device *dev) = NULL; |
31 | static struct kobject *dev_kobj; | 44 | static struct kobject *dev_kobj; |
@@ -203,37 +216,6 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, | |||
203 | if (dev->driver) | 216 | if (dev->driver) |
204 | add_uevent_var(env, "DRIVER=%s", dev->driver->name); | 217 | add_uevent_var(env, "DRIVER=%s", dev->driver->name); |
205 | 218 | ||
206 | #ifdef CONFIG_SYSFS_DEPRECATED | ||
207 | if (dev->class) { | ||
208 | struct device *parent = dev->parent; | ||
209 | |||
210 | /* find first bus device in parent chain */ | ||
211 | while (parent && !parent->bus) | ||
212 | parent = parent->parent; | ||
213 | if (parent && parent->bus) { | ||
214 | const char *path; | ||
215 | |||
216 | path = kobject_get_path(&parent->kobj, GFP_KERNEL); | ||
217 | if (path) { | ||
218 | add_uevent_var(env, "PHYSDEVPATH=%s", path); | ||
219 | kfree(path); | ||
220 | } | ||
221 | |||
222 | add_uevent_var(env, "PHYSDEVBUS=%s", parent->bus->name); | ||
223 | |||
224 | if (parent->driver) | ||
225 | add_uevent_var(env, "PHYSDEVDRIVER=%s", | ||
226 | parent->driver->name); | ||
227 | } | ||
228 | } else if (dev->bus) { | ||
229 | add_uevent_var(env, "PHYSDEVBUS=%s", dev->bus->name); | ||
230 | |||
231 | if (dev->driver) | ||
232 | add_uevent_var(env, "PHYSDEVDRIVER=%s", | ||
233 | dev->driver->name); | ||
234 | } | ||
235 | #endif | ||
236 | |||
237 | /* have the bus specific function add its stuff */ | 219 | /* have the bus specific function add its stuff */ |
238 | if (dev->bus && dev->bus->uevent) { | 220 | if (dev->bus && dev->bus->uevent) { |
239 | retval = dev->bus->uevent(dev, env); | 221 | retval = dev->bus->uevent(dev, env); |
@@ -251,7 +233,7 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, | |||
251 | __func__, retval); | 233 | __func__, retval); |
252 | } | 234 | } |
253 | 235 | ||
254 | /* have the device type specific fuction add its stuff */ | 236 | /* have the device type specific function add its stuff */ |
255 | if (dev->type && dev->type->uevent) { | 237 | if (dev->type && dev->type->uevent) { |
256 | retval = dev->type->uevent(dev, env); | 238 | retval = dev->type->uevent(dev, env); |
257 | if (retval) | 239 | if (retval) |
@@ -356,6 +338,35 @@ static void device_remove_attributes(struct device *dev, | |||
356 | device_remove_file(dev, &attrs[i]); | 338 | device_remove_file(dev, &attrs[i]); |
357 | } | 339 | } |
358 | 340 | ||
341 | static int device_add_bin_attributes(struct device *dev, | ||
342 | struct bin_attribute *attrs) | ||
343 | { | ||
344 | int error = 0; | ||
345 | int i; | ||
346 | |||
347 | if (attrs) { | ||
348 | for (i = 0; attr_name(attrs[i]); i++) { | ||
349 | error = device_create_bin_file(dev, &attrs[i]); | ||
350 | if (error) | ||
351 | break; | ||
352 | } | ||
353 | if (error) | ||
354 | while (--i >= 0) | ||
355 | device_remove_bin_file(dev, &attrs[i]); | ||
356 | } | ||
357 | return error; | ||
358 | } | ||
359 | |||
360 | static void device_remove_bin_attributes(struct device *dev, | ||
361 | struct bin_attribute *attrs) | ||
362 | { | ||
363 | int i; | ||
364 | |||
365 | if (attrs) | ||
366 | for (i = 0; attr_name(attrs[i]); i++) | ||
367 | device_remove_bin_file(dev, &attrs[i]); | ||
368 | } | ||
369 | |||
359 | static int device_add_groups(struct device *dev, | 370 | static int device_add_groups(struct device *dev, |
360 | const struct attribute_group **groups) | 371 | const struct attribute_group **groups) |
361 | { | 372 | { |
@@ -389,19 +400,22 @@ static void device_remove_groups(struct device *dev, | |||
389 | static int device_add_attrs(struct device *dev) | 400 | static int device_add_attrs(struct device *dev) |
390 | { | 401 | { |
391 | struct class *class = dev->class; | 402 | struct class *class = dev->class; |
392 | struct device_type *type = dev->type; | 403 | const struct device_type *type = dev->type; |
393 | int error; | 404 | int error; |
394 | 405 | ||
395 | if (class) { | 406 | if (class) { |
396 | error = device_add_attributes(dev, class->dev_attrs); | 407 | error = device_add_attributes(dev, class->dev_attrs); |
397 | if (error) | 408 | if (error) |
398 | return error; | 409 | return error; |
410 | error = device_add_bin_attributes(dev, class->dev_bin_attrs); | ||
411 | if (error) | ||
412 | goto err_remove_class_attrs; | ||
399 | } | 413 | } |
400 | 414 | ||
401 | if (type) { | 415 | if (type) { |
402 | error = device_add_groups(dev, type->groups); | 416 | error = device_add_groups(dev, type->groups); |
403 | if (error) | 417 | if (error) |
404 | goto err_remove_class_attrs; | 418 | goto err_remove_class_bin_attrs; |
405 | } | 419 | } |
406 | 420 | ||
407 | error = device_add_groups(dev, dev->groups); | 421 | error = device_add_groups(dev, dev->groups); |
@@ -413,6 +427,9 @@ static int device_add_attrs(struct device *dev) | |||
413 | err_remove_type_groups: | 427 | err_remove_type_groups: |
414 | if (type) | 428 | if (type) |
415 | device_remove_groups(dev, type->groups); | 429 | device_remove_groups(dev, type->groups); |
430 | err_remove_class_bin_attrs: | ||
431 | if (class) | ||
432 | device_remove_bin_attributes(dev, class->dev_bin_attrs); | ||
416 | err_remove_class_attrs: | 433 | err_remove_class_attrs: |
417 | if (class) | 434 | if (class) |
418 | device_remove_attributes(dev, class->dev_attrs); | 435 | device_remove_attributes(dev, class->dev_attrs); |
@@ -423,15 +440,17 @@ static int device_add_attrs(struct device *dev) | |||
423 | static void device_remove_attrs(struct device *dev) | 440 | static void device_remove_attrs(struct device *dev) |
424 | { | 441 | { |
425 | struct class *class = dev->class; | 442 | struct class *class = dev->class; |
426 | struct device_type *type = dev->type; | 443 | const struct device_type *type = dev->type; |
427 | 444 | ||
428 | device_remove_groups(dev, dev->groups); | 445 | device_remove_groups(dev, dev->groups); |
429 | 446 | ||
430 | if (type) | 447 | if (type) |
431 | device_remove_groups(dev, type->groups); | 448 | device_remove_groups(dev, type->groups); |
432 | 449 | ||
433 | if (class) | 450 | if (class) { |
434 | device_remove_attributes(dev, class->dev_attrs); | 451 | device_remove_attributes(dev, class->dev_attrs); |
452 | device_remove_bin_attributes(dev, class->dev_bin_attrs); | ||
453 | } | ||
435 | } | 454 | } |
436 | 455 | ||
437 | 456 | ||
@@ -578,24 +597,6 @@ void device_initialize(struct device *dev) | |||
578 | set_dev_node(dev, -1); | 597 | set_dev_node(dev, -1); |
579 | } | 598 | } |
580 | 599 | ||
581 | #ifdef CONFIG_SYSFS_DEPRECATED | ||
582 | static struct kobject *get_device_parent(struct device *dev, | ||
583 | struct device *parent) | ||
584 | { | ||
585 | /* class devices without a parent live in /sys/class/<classname>/ */ | ||
586 | if (dev->class && (!parent || parent->class != dev->class)) | ||
587 | return &dev->class->p->class_subsys.kobj; | ||
588 | /* all other devices keep their parent */ | ||
589 | else if (parent) | ||
590 | return &parent->kobj; | ||
591 | |||
592 | return NULL; | ||
593 | } | ||
594 | |||
595 | static inline void cleanup_device_parent(struct device *dev) {} | ||
596 | static inline void cleanup_glue_dir(struct device *dev, | ||
597 | struct kobject *glue_dir) {} | ||
598 | #else | ||
599 | static struct kobject *virtual_device_parent(struct device *dev) | 600 | static struct kobject *virtual_device_parent(struct device *dev) |
600 | { | 601 | { |
601 | static struct kobject *virtual_dir = NULL; | 602 | static struct kobject *virtual_dir = NULL; |
@@ -646,7 +647,7 @@ class_dir_create_and_add(struct class *class, struct kobject *parent_kobj) | |||
646 | dir->class = class; | 647 | dir->class = class; |
647 | kobject_init(&dir->kobj, &class_dir_ktype); | 648 | kobject_init(&dir->kobj, &class_dir_ktype); |
648 | 649 | ||
649 | dir->kobj.kset = &class->p->class_dirs; | 650 | dir->kobj.kset = &class->p->glue_dirs; |
650 | 651 | ||
651 | retval = kobject_add(&dir->kobj, parent_kobj, "%s", class->name); | 652 | retval = kobject_add(&dir->kobj, parent_kobj, "%s", class->name); |
652 | if (retval < 0) { | 653 | if (retval < 0) { |
@@ -666,6 +667,15 @@ static struct kobject *get_device_parent(struct device *dev, | |||
666 | struct kobject *parent_kobj; | 667 | struct kobject *parent_kobj; |
667 | struct kobject *k; | 668 | struct kobject *k; |
668 | 669 | ||
670 | #ifdef CONFIG_BLOCK | ||
671 | /* block disks show up in /sys/block */ | ||
672 | if (sysfs_deprecated && dev->class == &block_class) { | ||
673 | if (parent && parent->class == &block_class) | ||
674 | return &parent->kobj; | ||
675 | return &block_class.p->subsys.kobj; | ||
676 | } | ||
677 | #endif | ||
678 | |||
669 | /* | 679 | /* |
670 | * If we have no parent, we live in "virtual". | 680 | * If we have no parent, we live in "virtual". |
671 | * Class-devices with a non class-device as parent, live | 681 | * Class-devices with a non class-device as parent, live |
@@ -681,13 +691,13 @@ static struct kobject *get_device_parent(struct device *dev, | |||
681 | mutex_lock(&gdp_mutex); | 691 | mutex_lock(&gdp_mutex); |
682 | 692 | ||
683 | /* find our class-directory at the parent and reference it */ | 693 | /* find our class-directory at the parent and reference it */ |
684 | spin_lock(&dev->class->p->class_dirs.list_lock); | 694 | spin_lock(&dev->class->p->glue_dirs.list_lock); |
685 | list_for_each_entry(k, &dev->class->p->class_dirs.list, entry) | 695 | list_for_each_entry(k, &dev->class->p->glue_dirs.list, entry) |
686 | if (k->parent == parent_kobj) { | 696 | if (k->parent == parent_kobj) { |
687 | kobj = kobject_get(k); | 697 | kobj = kobject_get(k); |
688 | break; | 698 | break; |
689 | } | 699 | } |
690 | spin_unlock(&dev->class->p->class_dirs.list_lock); | 700 | spin_unlock(&dev->class->p->glue_dirs.list_lock); |
691 | if (kobj) { | 701 | if (kobj) { |
692 | mutex_unlock(&gdp_mutex); | 702 | mutex_unlock(&gdp_mutex); |
693 | return kobj; | 703 | return kobj; |
@@ -709,7 +719,7 @@ static void cleanup_glue_dir(struct device *dev, struct kobject *glue_dir) | |||
709 | { | 719 | { |
710 | /* see if we live in a "glue" directory */ | 720 | /* see if we live in a "glue" directory */ |
711 | if (!glue_dir || !dev->class || | 721 | if (!glue_dir || !dev->class || |
712 | glue_dir->kset != &dev->class->p->class_dirs) | 722 | glue_dir->kset != &dev->class->p->glue_dirs) |
713 | return; | 723 | return; |
714 | 724 | ||
715 | kobject_put(glue_dir); | 725 | kobject_put(glue_dir); |
@@ -719,7 +729,6 @@ static void cleanup_device_parent(struct device *dev) | |||
719 | { | 729 | { |
720 | cleanup_glue_dir(dev, dev->kobj.parent); | 730 | cleanup_glue_dir(dev, dev->kobj.parent); |
721 | } | 731 | } |
722 | #endif | ||
723 | 732 | ||
724 | static void setup_parent(struct device *dev, struct device *parent) | 733 | static void setup_parent(struct device *dev, struct device *parent) |
725 | { | 734 | { |
@@ -737,75 +746,34 @@ static int device_add_class_symlinks(struct device *dev) | |||
737 | return 0; | 746 | return 0; |
738 | 747 | ||
739 | error = sysfs_create_link(&dev->kobj, | 748 | error = sysfs_create_link(&dev->kobj, |
740 | &dev->class->p->class_subsys.kobj, | 749 | &dev->class->p->subsys.kobj, |
741 | "subsystem"); | 750 | "subsystem"); |
742 | if (error) | 751 | if (error) |
743 | goto out; | 752 | goto out; |
744 | 753 | ||
745 | #ifdef CONFIG_SYSFS_DEPRECATED | ||
746 | /* stacked class devices need a symlink in the class directory */ | ||
747 | if (dev->kobj.parent != &dev->class->p->class_subsys.kobj && | ||
748 | device_is_not_partition(dev)) { | ||
749 | error = sysfs_create_link(&dev->class->p->class_subsys.kobj, | ||
750 | &dev->kobj, dev_name(dev)); | ||
751 | if (error) | ||
752 | goto out_subsys; | ||
753 | } | ||
754 | |||
755 | if (dev->parent && device_is_not_partition(dev)) { | 754 | if (dev->parent && device_is_not_partition(dev)) { |
756 | struct device *parent = dev->parent; | 755 | error = sysfs_create_link(&dev->kobj, &dev->parent->kobj, |
757 | char *class_name; | ||
758 | |||
759 | /* | ||
760 | * stacked class devices have the 'device' link | ||
761 | * pointing to the bus device instead of the parent | ||
762 | */ | ||
763 | while (parent->class && !parent->bus && parent->parent) | ||
764 | parent = parent->parent; | ||
765 | |||
766 | error = sysfs_create_link(&dev->kobj, | ||
767 | &parent->kobj, | ||
768 | "device"); | 756 | "device"); |
769 | if (error) | 757 | if (error) |
770 | goto out_busid; | 758 | goto out_subsys; |
771 | |||
772 | class_name = make_class_name(dev->class->name, | ||
773 | &dev->kobj); | ||
774 | if (class_name) | ||
775 | error = sysfs_create_link(&dev->parent->kobj, | ||
776 | &dev->kobj, class_name); | ||
777 | kfree(class_name); | ||
778 | if (error) | ||
779 | goto out_device; | ||
780 | } | 759 | } |
781 | return 0; | ||
782 | 760 | ||
783 | out_device: | 761 | #ifdef CONFIG_BLOCK |
784 | if (dev->parent && device_is_not_partition(dev)) | 762 | /* /sys/block has directories and does not need symlinks */ |
785 | sysfs_remove_link(&dev->kobj, "device"); | 763 | if (sysfs_deprecated && dev->class == &block_class) |
786 | out_busid: | 764 | return 0; |
787 | if (dev->kobj.parent != &dev->class->p->class_subsys.kobj && | 765 | #endif |
788 | device_is_not_partition(dev)) | 766 | |
789 | sysfs_delete_link(&dev->class->p->class_subsys.kobj, &dev->kobj, | ||
790 | dev_name(dev)); | ||
791 | #else | ||
792 | /* link in the class directory pointing to the device */ | 767 | /* link in the class directory pointing to the device */ |
793 | error = sysfs_create_link(&dev->class->p->class_subsys.kobj, | 768 | error = sysfs_create_link(&dev->class->p->subsys.kobj, |
794 | &dev->kobj, dev_name(dev)); | 769 | &dev->kobj, dev_name(dev)); |
795 | if (error) | 770 | if (error) |
796 | goto out_subsys; | 771 | goto out_device; |
797 | 772 | ||
798 | if (dev->parent && device_is_not_partition(dev)) { | ||
799 | error = sysfs_create_link(&dev->kobj, &dev->parent->kobj, | ||
800 | "device"); | ||
801 | if (error) | ||
802 | goto out_busid; | ||
803 | } | ||
804 | return 0; | 773 | return 0; |
805 | 774 | ||
806 | out_busid: | 775 | out_device: |
807 | sysfs_delete_link(&dev->class->p->class_subsys.kobj, &dev->kobj, dev_name(dev)); | 776 | sysfs_remove_link(&dev->kobj, "device"); |
808 | #endif | ||
809 | 777 | ||
810 | out_subsys: | 778 | out_subsys: |
811 | sysfs_remove_link(&dev->kobj, "subsystem"); | 779 | sysfs_remove_link(&dev->kobj, "subsystem"); |
@@ -818,30 +786,14 @@ static void device_remove_class_symlinks(struct device *dev) | |||
818 | if (!dev->class) | 786 | if (!dev->class) |
819 | return; | 787 | return; |
820 | 788 | ||
821 | #ifdef CONFIG_SYSFS_DEPRECATED | ||
822 | if (dev->parent && device_is_not_partition(dev)) { | ||
823 | char *class_name; | ||
824 | |||
825 | class_name = make_class_name(dev->class->name, &dev->kobj); | ||
826 | if (class_name) { | ||
827 | sysfs_remove_link(&dev->parent->kobj, class_name); | ||
828 | kfree(class_name); | ||
829 | } | ||
830 | sysfs_remove_link(&dev->kobj, "device"); | ||
831 | } | ||
832 | |||
833 | if (dev->kobj.parent != &dev->class->p->class_subsys.kobj && | ||
834 | device_is_not_partition(dev)) | ||
835 | sysfs_delete_link(&dev->class->p->class_subsys.kobj, &dev->kobj, | ||
836 | dev_name(dev)); | ||
837 | #else | ||
838 | if (dev->parent && device_is_not_partition(dev)) | 789 | if (dev->parent && device_is_not_partition(dev)) |
839 | sysfs_remove_link(&dev->kobj, "device"); | 790 | sysfs_remove_link(&dev->kobj, "device"); |
840 | |||
841 | sysfs_delete_link(&dev->class->p->class_subsys.kobj, &dev->kobj, dev_name(dev)); | ||
842 | #endif | ||
843 | |||
844 | sysfs_remove_link(&dev->kobj, "subsystem"); | 791 | sysfs_remove_link(&dev->kobj, "subsystem"); |
792 | #ifdef CONFIG_BLOCK | ||
793 | if (sysfs_deprecated && dev->class == &block_class) | ||
794 | return; | ||
795 | #endif | ||
796 | sysfs_delete_link(&dev->class->p->subsys.kobj, &dev->kobj, dev_name(dev)); | ||
845 | } | 797 | } |
846 | 798 | ||
847 | /** | 799 | /** |
@@ -1032,7 +984,7 @@ int device_add(struct device *dev) | |||
1032 | mutex_lock(&dev->class->p->class_mutex); | 984 | mutex_lock(&dev->class->p->class_mutex); |
1033 | /* tie the class to the device */ | 985 | /* tie the class to the device */ |
1034 | klist_add_tail(&dev->knode_class, | 986 | klist_add_tail(&dev->knode_class, |
1035 | &dev->class->p->class_devices); | 987 | &dev->class->p->klist_devices); |
1036 | 988 | ||
1037 | /* notify any interfaces that the device is here */ | 989 | /* notify any interfaces that the device is here */ |
1038 | list_for_each_entry(class_intf, | 990 | list_for_each_entry(class_intf, |
@@ -1362,13 +1314,15 @@ EXPORT_SYMBOL_GPL(put_device); | |||
1362 | EXPORT_SYMBOL_GPL(device_create_file); | 1314 | EXPORT_SYMBOL_GPL(device_create_file); |
1363 | EXPORT_SYMBOL_GPL(device_remove_file); | 1315 | EXPORT_SYMBOL_GPL(device_remove_file); |
1364 | 1316 | ||
1365 | struct root_device | 1317 | struct root_device { |
1366 | { | ||
1367 | struct device dev; | 1318 | struct device dev; |
1368 | struct module *owner; | 1319 | struct module *owner; |
1369 | }; | 1320 | }; |
1370 | 1321 | ||
1371 | #define to_root_device(dev) container_of(dev, struct root_device, dev) | 1322 | inline struct root_device *to_root_device(struct device *d) |
1323 | { | ||
1324 | return container_of(d, struct root_device, dev); | ||
1325 | } | ||
1372 | 1326 | ||
1373 | static void root_device_release(struct device *dev) | 1327 | static void root_device_release(struct device *dev) |
1374 | { | 1328 | { |
@@ -1598,6 +1552,35 @@ EXPORT_SYMBOL_GPL(device_destroy); | |||
1598 | * exclusion between two different calls of device_rename | 1552 | * exclusion between two different calls of device_rename |
1599 | * on the same device to ensure that new_name is valid and | 1553 | * on the same device to ensure that new_name is valid and |
1600 | * won't conflict with other devices. | 1554 | * won't conflict with other devices. |
1555 | * | ||
1556 | * Note: Don't call this function. Currently, the networking layer calls this | ||
1557 | * function, but that will change. The following text from Kay Sievers offers | ||
1558 | * some insight: | ||
1559 | * | ||
1560 | * Renaming devices is racy at many levels, symlinks and other stuff are not | ||
1561 | * replaced atomically, and you get a "move" uevent, but it's not easy to | ||
1562 | * connect the event to the old and new device. Device nodes are not renamed at | ||
1563 | * all, there isn't even support for that in the kernel now. | ||
1564 | * | ||
1565 | * In the meantime, during renaming, your target name might be taken by another | ||
1566 | * driver, creating conflicts. Or the old name is taken directly after you | ||
1567 | * renamed it -- then you get events for the same DEVPATH, before you even see | ||
1568 | * the "move" event. It's just a mess, and nothing new should ever rely on | ||
1569 | * kernel device renaming. Besides that, it's not even implemented now for | ||
1570 | * other things than (driver-core wise very simple) network devices. | ||
1571 | * | ||
1572 | * We are currently about to change network renaming in udev to completely | ||
1573 | * disallow renaming of devices in the same namespace as the kernel uses, | ||
1574 | * because we can't solve the problems properly, that arise with swapping names | ||
1575 | * of multiple interfaces without races. Means, renaming of eth[0-9]* will only | ||
1576 | * be allowed to some other name than eth[0-9]*, for the aforementioned | ||
1577 | * reasons. | ||
1578 | * | ||
1579 | * Make up a "real" name in the driver before you register anything, or add | ||
1580 | * some other attributes for userspace to find the device, or use udev to add | ||
1581 | * symlinks -- but never rename kernel devices later, it's a complete mess. We | ||
1582 | * don't even want to get into that and try to implement the missing pieces in | ||
1583 | * the core. We really have other pieces to fix in the driver core mess. :) | ||
1601 | */ | 1584 | */ |
1602 | int device_rename(struct device *dev, const char *new_name) | 1585 | int device_rename(struct device *dev, const char *new_name) |
1603 | { | 1586 | { |
@@ -1613,41 +1596,23 @@ int device_rename(struct device *dev, const char *new_name) | |||
1613 | pr_debug("device: '%s': %s: renaming to '%s'\n", dev_name(dev), | 1596 | pr_debug("device: '%s': %s: renaming to '%s'\n", dev_name(dev), |
1614 | __func__, new_name); | 1597 | __func__, new_name); |
1615 | 1598 | ||
1616 | #ifdef CONFIG_SYSFS_DEPRECATED | ||
1617 | if ((dev->class) && (dev->parent)) | ||
1618 | old_class_name = make_class_name(dev->class->name, &dev->kobj); | ||
1619 | #endif | ||
1620 | |||
1621 | old_device_name = kstrdup(dev_name(dev), GFP_KERNEL); | 1599 | old_device_name = kstrdup(dev_name(dev), GFP_KERNEL); |
1622 | if (!old_device_name) { | 1600 | if (!old_device_name) { |
1623 | error = -ENOMEM; | 1601 | error = -ENOMEM; |
1624 | goto out; | 1602 | goto out; |
1625 | } | 1603 | } |
1626 | 1604 | ||
1627 | #ifndef CONFIG_SYSFS_DEPRECATED | ||
1628 | if (dev->class) { | 1605 | if (dev->class) { |
1629 | error = sysfs_rename_link(&dev->class->p->class_subsys.kobj, | 1606 | error = sysfs_rename_link(&dev->class->p->subsys.kobj, |
1630 | &dev->kobj, old_device_name, new_name); | 1607 | &dev->kobj, old_device_name, new_name); |
1631 | if (error) | 1608 | if (error) |
1632 | goto out; | 1609 | goto out; |
1633 | } | 1610 | } |
1634 | #endif | 1611 | |
1635 | error = kobject_rename(&dev->kobj, new_name); | 1612 | error = kobject_rename(&dev->kobj, new_name); |
1636 | if (error) | 1613 | if (error) |
1637 | goto out; | 1614 | goto out; |
1638 | 1615 | ||
1639 | #ifdef CONFIG_SYSFS_DEPRECATED | ||
1640 | if (old_class_name) { | ||
1641 | new_class_name = make_class_name(dev->class->name, &dev->kobj); | ||
1642 | if (new_class_name) { | ||
1643 | error = sysfs_rename_link(&dev->parent->kobj, | ||
1644 | &dev->kobj, | ||
1645 | old_class_name, | ||
1646 | new_class_name); | ||
1647 | } | ||
1648 | } | ||
1649 | #endif | ||
1650 | |||
1651 | out: | 1616 | out: |
1652 | put_device(dev); | 1617 | put_device(dev); |
1653 | 1618 | ||
@@ -1664,40 +1629,13 @@ static int device_move_class_links(struct device *dev, | |||
1664 | struct device *new_parent) | 1629 | struct device *new_parent) |
1665 | { | 1630 | { |
1666 | int error = 0; | 1631 | int error = 0; |
1667 | #ifdef CONFIG_SYSFS_DEPRECATED | ||
1668 | char *class_name; | ||
1669 | 1632 | ||
1670 | class_name = make_class_name(dev->class->name, &dev->kobj); | ||
1671 | if (!class_name) { | ||
1672 | error = -ENOMEM; | ||
1673 | goto out; | ||
1674 | } | ||
1675 | if (old_parent) { | ||
1676 | sysfs_remove_link(&dev->kobj, "device"); | ||
1677 | sysfs_remove_link(&old_parent->kobj, class_name); | ||
1678 | } | ||
1679 | if (new_parent) { | ||
1680 | error = sysfs_create_link(&dev->kobj, &new_parent->kobj, | ||
1681 | "device"); | ||
1682 | if (error) | ||
1683 | goto out; | ||
1684 | error = sysfs_create_link(&new_parent->kobj, &dev->kobj, | ||
1685 | class_name); | ||
1686 | if (error) | ||
1687 | sysfs_remove_link(&dev->kobj, "device"); | ||
1688 | } else | ||
1689 | error = 0; | ||
1690 | out: | ||
1691 | kfree(class_name); | ||
1692 | return error; | ||
1693 | #else | ||
1694 | if (old_parent) | 1633 | if (old_parent) |
1695 | sysfs_remove_link(&dev->kobj, "device"); | 1634 | sysfs_remove_link(&dev->kobj, "device"); |
1696 | if (new_parent) | 1635 | if (new_parent) |
1697 | error = sysfs_create_link(&dev->kobj, &new_parent->kobj, | 1636 | error = sysfs_create_link(&dev->kobj, &new_parent->kobj, |
1698 | "device"); | 1637 | "device"); |
1699 | return error; | 1638 | return error; |
1700 | #endif | ||
1701 | } | 1639 | } |
1702 | 1640 | ||
1703 | /** | 1641 | /** |