aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio
diff options
context:
space:
mode:
authorAlexandre Courbot <acourbot@nvidia.com>2014-07-22 03:17:40 -0400
committerLinus Walleij <linus.walleij@linaro.org>2014-07-23 11:37:51 -0400
commit14141a9352d007434ff61df1e16a2bcaf3119307 (patch)
treef54c02c3344952004a08f1ea3f1913467c5fa357 /drivers/gpio
parentf63ad7ed71e525b74fe486d25cdc788d6531f4a9 (diff)
gpio: simplify gpiochip_export()
For some reason gpiochip_export() would invalidate all the descriptors of a chip if exporting it to sysfs failed. This does not appear as necessary. Remove that part of the code. While we are at it, add a note about the non-safety of temporarily releasing a spinlock in the middle of the loop that protects its iterator, and explain why this is done. Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/gpiolib-sysfs.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index 3516502059f2..f150aa288fa1 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -760,18 +760,8 @@ int gpiochip_export(struct gpio_chip *chip)
760 chip->exported = (status == 0); 760 chip->exported = (status == 0);
761 mutex_unlock(&sysfs_lock); 761 mutex_unlock(&sysfs_lock);
762 762
763 if (status) { 763 if (status)
764 unsigned long flags;
765 unsigned gpio;
766
767 spin_lock_irqsave(&gpio_lock, flags);
768 gpio = 0;
769 while (gpio < chip->ngpio)
770 chip->desc[gpio++].chip = NULL;
771 spin_unlock_irqrestore(&gpio_lock, flags);
772
773 chip_dbg(chip, "%s: status %d\n", __func__, status); 764 chip_dbg(chip, "%s: status %d\n", __func__, status);
774 }
775 765
776 return status; 766 return status;
777} 767}
@@ -817,6 +807,14 @@ static int __init gpiolib_sysfs_init(void)
817 if (!chip || chip->exported) 807 if (!chip || chip->exported)
818 continue; 808 continue;
819 809
810 /*
811 * TODO we yield gpio_lock here because gpiochip_export()
812 * acquires a mutex. This is unsafe and needs to be fixed.
813 *
814 * Also it would be nice to use gpiochip_find() here so we
815 * can keep gpio_chips local to gpiolib.c, but the yield of
816 * gpio_lock prevents us from doing this.
817 */
820 spin_unlock_irqrestore(&gpio_lock, flags); 818 spin_unlock_irqrestore(&gpio_lock, flags);
821 status = gpiochip_export(chip); 819 status = gpiochip_export(chip);
822 spin_lock_irqsave(&gpio_lock, flags); 820 spin_lock_irqsave(&gpio_lock, flags);