diff options
-rw-r--r-- | drivers/input/input.c | 63 |
1 files changed, 36 insertions, 27 deletions
diff --git a/drivers/input/input.c b/drivers/input/input.c index c8ae2bb054e0..bdd2a7fc268d 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c | |||
@@ -536,7 +536,7 @@ static struct attribute *input_dev_attrs[] = { | |||
536 | NULL | 536 | NULL |
537 | }; | 537 | }; |
538 | 538 | ||
539 | static struct attribute_group input_dev_group = { | 539 | static struct attribute_group input_dev_attr_group = { |
540 | .attrs = input_dev_attrs, | 540 | .attrs = input_dev_attrs, |
541 | }; | 541 | }; |
542 | 542 | ||
@@ -717,35 +717,14 @@ struct input_dev *input_allocate_device(void) | |||
717 | return dev; | 717 | return dev; |
718 | } | 718 | } |
719 | 719 | ||
720 | static void input_register_classdevice(struct input_dev *dev) | ||
721 | { | ||
722 | static atomic_t input_no = ATOMIC_INIT(0); | ||
723 | const char *path; | ||
724 | |||
725 | __module_get(THIS_MODULE); | ||
726 | |||
727 | dev->dev = dev->cdev.dev; | ||
728 | |||
729 | snprintf(dev->cdev.class_id, sizeof(dev->cdev.class_id), | ||
730 | "input%ld", (unsigned long) atomic_inc_return(&input_no) - 1); | ||
731 | |||
732 | path = kobject_get_path(&dev->cdev.class->subsys.kset.kobj, GFP_KERNEL); | ||
733 | printk(KERN_INFO "input: %s as %s/%s\n", | ||
734 | dev->name ? dev->name : "Unspecified device", | ||
735 | path ? path : "", dev->cdev.class_id); | ||
736 | kfree(path); | ||
737 | |||
738 | class_device_add(&dev->cdev); | ||
739 | sysfs_create_group(&dev->cdev.kobj, &input_dev_group); | ||
740 | sysfs_create_group(&dev->cdev.kobj, &input_dev_id_attr_group); | ||
741 | sysfs_create_group(&dev->cdev.kobj, &input_dev_caps_attr_group); | ||
742 | } | ||
743 | |||
744 | int input_register_device(struct input_dev *dev) | 720 | int input_register_device(struct input_dev *dev) |
745 | { | 721 | { |
722 | static atomic_t input_no = ATOMIC_INIT(0); | ||
746 | struct input_handle *handle; | 723 | struct input_handle *handle; |
747 | struct input_handler *handler; | 724 | struct input_handler *handler; |
748 | struct input_device_id *id; | 725 | struct input_device_id *id; |
726 | const char *path; | ||
727 | int error; | ||
749 | 728 | ||
750 | if (!dev->dynalloc) { | 729 | if (!dev->dynalloc) { |
751 | printk(KERN_WARNING "input: device %s is statically allocated, will not register\n" | 730 | printk(KERN_WARNING "input: device %s is statically allocated, will not register\n" |
@@ -773,7 +752,32 @@ int input_register_device(struct input_dev *dev) | |||
773 | INIT_LIST_HEAD(&dev->h_list); | 752 | INIT_LIST_HEAD(&dev->h_list); |
774 | list_add_tail(&dev->node, &input_dev_list); | 753 | list_add_tail(&dev->node, &input_dev_list); |
775 | 754 | ||
776 | input_register_classdevice(dev); | 755 | dev->cdev.class = &input_class; |
756 | snprintf(dev->cdev.class_id, sizeof(dev->cdev.class_id), | ||
757 | "input%ld", (unsigned long) atomic_inc_return(&input_no) - 1); | ||
758 | |||
759 | error = class_device_add(&dev->cdev); | ||
760 | if (error) | ||
761 | return error; | ||
762 | |||
763 | error = sysfs_create_group(&dev->cdev.kobj, &input_dev_attr_group); | ||
764 | if (error) | ||
765 | goto fail1; | ||
766 | |||
767 | error = sysfs_create_group(&dev->cdev.kobj, &input_dev_id_attr_group); | ||
768 | if (error) | ||
769 | goto fail2; | ||
770 | |||
771 | error = sysfs_create_group(&dev->cdev.kobj, &input_dev_caps_attr_group); | ||
772 | if (error) | ||
773 | goto fail3; | ||
774 | |||
775 | __module_get(THIS_MODULE); | ||
776 | |||
777 | path = kobject_get_path(&dev->cdev.kobj, GFP_KERNEL); | ||
778 | printk(KERN_INFO "input: %s as %s\n", | ||
779 | dev->name ? dev->name : "Unspecified device", path ? path : "N/A"); | ||
780 | kfree(path); | ||
777 | 781 | ||
778 | list_for_each_entry(handler, &input_handler_list, node) | 782 | list_for_each_entry(handler, &input_handler_list, node) |
779 | if (!handler->blacklist || !input_match_device(handler->blacklist, dev)) | 783 | if (!handler->blacklist || !input_match_device(handler->blacklist, dev)) |
@@ -784,6 +788,11 @@ int input_register_device(struct input_dev *dev) | |||
784 | input_wakeup_procfs_readers(); | 788 | input_wakeup_procfs_readers(); |
785 | 789 | ||
786 | return 0; | 790 | return 0; |
791 | |||
792 | fail3: sysfs_remove_group(&dev->cdev.kobj, &input_dev_id_attr_group); | ||
793 | fail2: sysfs_remove_group(&dev->cdev.kobj, &input_dev_attr_group); | ||
794 | fail1: class_device_del(&dev->cdev); | ||
795 | return error; | ||
787 | } | 796 | } |
788 | 797 | ||
789 | void input_unregister_device(struct input_dev *dev) | 798 | void input_unregister_device(struct input_dev *dev) |
@@ -805,7 +814,7 @@ void input_unregister_device(struct input_dev *dev) | |||
805 | 814 | ||
806 | sysfs_remove_group(&dev->cdev.kobj, &input_dev_caps_attr_group); | 815 | sysfs_remove_group(&dev->cdev.kobj, &input_dev_caps_attr_group); |
807 | sysfs_remove_group(&dev->cdev.kobj, &input_dev_id_attr_group); | 816 | sysfs_remove_group(&dev->cdev.kobj, &input_dev_id_attr_group); |
808 | sysfs_remove_group(&dev->cdev.kobj, &input_dev_group); | 817 | sysfs_remove_group(&dev->cdev.kobj, &input_dev_attr_group); |
809 | class_device_unregister(&dev->cdev); | 818 | class_device_unregister(&dev->cdev); |
810 | 819 | ||
811 | input_wakeup_procfs_readers(); | 820 | input_wakeup_procfs_readers(); |