aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpiolib-sysfs.c
diff options
context:
space:
mode:
authorJohan Hovold <johan@kernel.org>2015-05-04 11:10:31 -0400
committerLinus Walleij <linus.walleij@linaro.org>2015-05-12 04:46:44 -0400
commit6a4b6b0a3b55f23f4cc9ad85a1539c581bcb0874 (patch)
tree2c4e625f5c707fdea60096b8aa64c991f19b217a /drivers/gpio/gpiolib-sysfs.c
parent3ff74be5c1a72df6d304dcb453f68e3c3bea3bdd (diff)
gpio: sysfs: clean up chip class-device handling
Clean gpio-chip class device registration and deregistration. The class device is registered when a gpio-chip is added (or from gpiolib_sysfs_init post-core init call), and deregistered when the chip is removed. Store the class device in struct gpio_chip directly rather than do a class-device lookup on deregistration. This also removes the need for the exported flag. Signed-off-by: Johan Hovold <johan@kernel.org> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio/gpiolib-sysfs.c')
-rw-r--r--drivers/gpio/gpiolib-sysfs.c39
1 files changed, 13 insertions, 26 deletions
diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index d19bf234e878..767b79adb9a4 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -582,7 +582,7 @@ int gpiod_export(struct gpio_desc *desc, bool direction_may_change)
582 mutex_lock(&sysfs_lock); 582 mutex_lock(&sysfs_lock);
583 583
584 /* check if chip is being removed */ 584 /* check if chip is being removed */
585 if (!chip || !chip->exported) { 585 if (!chip || !chip->cdev) {
586 status = -ENODEV; 586 status = -ENODEV;
587 goto fail_unlock; 587 goto fail_unlock;
588 } 588 }
@@ -767,7 +767,6 @@ EXPORT_SYMBOL_GPL(gpiod_unexport);
767 767
768int gpiochip_export(struct gpio_chip *chip) 768int gpiochip_export(struct gpio_chip *chip)
769{ 769{
770 int status;
771 struct device *dev; 770 struct device *dev;
772 771
773 /* Many systems register gpio chips for SOC support very early, 772 /* Many systems register gpio chips for SOC support very early,
@@ -783,41 +782,29 @@ int gpiochip_export(struct gpio_chip *chip)
783 chip, gpiochip_groups, 782 chip, gpiochip_groups,
784 "gpiochip%d", chip->base); 783 "gpiochip%d", chip->base);
785 if (IS_ERR(dev)) 784 if (IS_ERR(dev))
786 status = PTR_ERR(dev); 785 return PTR_ERR(dev);
787 else
788 status = 0;
789 786
790 mutex_lock(&sysfs_lock); 787 mutex_lock(&sysfs_lock);
791 chip->exported = (status == 0); 788 chip->cdev = dev;
792 mutex_unlock(&sysfs_lock); 789 mutex_unlock(&sysfs_lock);
793 790
794 if (status) 791 return 0;
795 chip_dbg(chip, "%s: status %d\n", __func__, status);
796
797 return status;
798} 792}
799 793
800void gpiochip_unexport(struct gpio_chip *chip) 794void gpiochip_unexport(struct gpio_chip *chip)
801{ 795{
802 int status;
803 struct device *dev;
804 struct gpio_desc *desc; 796 struct gpio_desc *desc;
805 unsigned int i; 797 unsigned int i;
806 798
807 dev = class_find_device(&gpio_class, NULL, chip, match_export); 799 if (!chip->cdev)
808 if (dev) { 800 return;
809 put_device(dev);
810 device_unregister(dev);
811 /* prevent further gpiod exports */
812 mutex_lock(&sysfs_lock);
813 chip->exported = false;
814 mutex_unlock(&sysfs_lock);
815 status = 0;
816 } else
817 status = -ENODEV;
818 801
819 if (status) 802 device_unregister(chip->cdev);
820 chip_dbg(chip, "%s: status %d\n", __func__, status); 803
804 /* prevent further gpiod exports */
805 mutex_lock(&sysfs_lock);
806 chip->cdev = NULL;
807 mutex_unlock(&sysfs_lock);
821 808
822 /* unregister gpiod class devices owned by sysfs */ 809 /* unregister gpiod class devices owned by sysfs */
823 for (i = 0; i < chip->ngpio; i++) { 810 for (i = 0; i < chip->ngpio; i++) {
@@ -845,7 +832,7 @@ static int __init gpiolib_sysfs_init(void)
845 */ 832 */
846 spin_lock_irqsave(&gpio_lock, flags); 833 spin_lock_irqsave(&gpio_lock, flags);
847 list_for_each_entry(chip, &gpio_chips, list) { 834 list_for_each_entry(chip, &gpio_chips, list) {
848 if (chip->exported) 835 if (chip->cdev)
849 continue; 836 continue;
850 837
851 /* 838 /*