summaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpiolib-sysfs.c
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2016-02-09 07:21:06 -0500
committerLinus Walleij <linus.walleij@linaro.org>2016-02-11 12:16:54 -0500
commitafbc4f312b5e6e87fcd383eb6764e09f1324c78e (patch)
tree5428e0fe100c576dd158bba68df183010cee2009 /drivers/gpio/gpiolib-sysfs.c
parent9efd9e6956adf479eb85beb74bb975f702dc01a9 (diff)
gpio: move sysfs mock device to the gpio_device
Since gpio_device is the struct that survives if the backing gpio_chip is removed, move the sysfs mock device to this state container so it becomes part of the dangling state of the GPIO device on removal. Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio/gpiolib-sysfs.c')
-rw-r--r--drivers/gpio/gpiolib-sysfs.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index 28d3bf2328aa..94ba4bb8b4f8 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -572,7 +572,7 @@ int gpiod_export(struct gpio_desc *desc, bool direction_may_change)
572 mutex_lock(&sysfs_lock); 572 mutex_lock(&sysfs_lock);
573 573
574 /* check if chip is being removed */ 574 /* check if chip is being removed */
575 if (!chip || !chip->cdev) { 575 if (!chip || !gdev->mockdev) {
576 status = -ENODEV; 576 status = -ENODEV;
577 goto err_unlock; 577 goto err_unlock;
578 } 578 }
@@ -718,9 +718,10 @@ err_unlock:
718} 718}
719EXPORT_SYMBOL_GPL(gpiod_unexport); 719EXPORT_SYMBOL_GPL(gpiod_unexport);
720 720
721int gpiochip_sysfs_register(struct gpio_chip *chip) 721int gpiochip_sysfs_register(struct gpio_device *gdev)
722{ 722{
723 struct device *dev; 723 struct device *dev;
724 struct gpio_chip *chip = gdev->chip;
724 725
725 /* 726 /*
726 * Many systems add gpio chips for SOC support very early, 727 * Many systems add gpio chips for SOC support very early,
@@ -732,7 +733,7 @@ int gpiochip_sysfs_register(struct gpio_chip *chip)
732 return 0; 733 return 0;
733 734
734 /* use chip->base for the ID; it's already known to be unique */ 735 /* use chip->base for the ID; it's already known to be unique */
735 dev = device_create_with_groups(&gpio_class, chip->parent, 736 dev = device_create_with_groups(&gpio_class, &gdev->dev,
736 MKDEV(0, 0), 737 MKDEV(0, 0),
737 chip, gpiochip_groups, 738 chip, gpiochip_groups,
738 "gpiochip%d", chip->base); 739 "gpiochip%d", chip->base);
@@ -740,25 +741,26 @@ int gpiochip_sysfs_register(struct gpio_chip *chip)
740 return PTR_ERR(dev); 741 return PTR_ERR(dev);
741 742
742 mutex_lock(&sysfs_lock); 743 mutex_lock(&sysfs_lock);
743 chip->cdev = dev; 744 gdev->mockdev = dev;
744 mutex_unlock(&sysfs_lock); 745 mutex_unlock(&sysfs_lock);
745 746
746 return 0; 747 return 0;
747} 748}
748 749
749void gpiochip_sysfs_unregister(struct gpio_chip *chip) 750void gpiochip_sysfs_unregister(struct gpio_device *gdev)
750{ 751{
751 struct gpio_desc *desc; 752 struct gpio_desc *desc;
753 struct gpio_chip *chip = gdev->chip;
752 unsigned int i; 754 unsigned int i;
753 755
754 if (!chip->cdev) 756 if (!gdev->mockdev)
755 return; 757 return;
756 758
757 device_unregister(chip->cdev); 759 device_unregister(gdev->mockdev);
758 760
759 /* prevent further gpiod exports */ 761 /* prevent further gpiod exports */
760 mutex_lock(&sysfs_lock); 762 mutex_lock(&sysfs_lock);
761 chip->cdev = NULL; 763 gdev->mockdev = NULL;
762 mutex_unlock(&sysfs_lock); 764 mutex_unlock(&sysfs_lock);
763 765
764 /* unregister gpiod class devices owned by sysfs */ 766 /* unregister gpiod class devices owned by sysfs */
@@ -787,7 +789,7 @@ static int __init gpiolib_sysfs_init(void)
787 */ 789 */
788 spin_lock_irqsave(&gpio_lock, flags); 790 spin_lock_irqsave(&gpio_lock, flags);
789 list_for_each_entry(gdev, &gpio_devices, list) { 791 list_for_each_entry(gdev, &gpio_devices, list) {
790 if (gdev->chip->cdev) 792 if (gdev->mockdev)
791 continue; 793 continue;
792 794
793 /* 795 /*
@@ -800,12 +802,11 @@ static int __init gpiolib_sysfs_init(void)
800 * gpio_lock prevents us from doing this. 802 * gpio_lock prevents us from doing this.
801 */ 803 */
802 spin_unlock_irqrestore(&gpio_lock, flags); 804 spin_unlock_irqrestore(&gpio_lock, flags);
803 status = gpiochip_sysfs_register(gdev->chip); 805 status = gpiochip_sysfs_register(gdev);
804 spin_lock_irqsave(&gpio_lock, flags); 806 spin_lock_irqsave(&gpio_lock, flags);
805 } 807 }
806 spin_unlock_irqrestore(&gpio_lock, flags); 808 spin_unlock_irqrestore(&gpio_lock, flags);
807 809
808
809 return status; 810 return status;
810} 811}
811postcore_initcall(gpiolib_sysfs_init); 812postcore_initcall(gpiolib_sysfs_init);