]> git.karo-electronics.de Git - linux-beck.git/commitdiff
gpio: sysfs: reduce gpiochip-export locking scope
authorJohan Hovold <johan@kernel.org>
Mon, 4 May 2015 15:10:30 +0000 (17:10 +0200)
committerLinus Walleij <linus.walleij@linaro.org>
Tue, 12 May 2015 08:46:40 +0000 (10:46 +0200)
Reduce scope of sysfs_lock protection during chip export and unexport,
which is only needed to prevent gpiod (re-)exports during chip removal.

Signed-off-by: Johan Hovold <johan@kernel.org>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/gpio/gpiolib-sysfs.c

index 658ed28e6d7d9fe7bc345fcb76ab9c1d13b6f2bb..d19bf234e8783fe732540caa9f746c22180e9c50 100644 (file)
@@ -779,7 +779,6 @@ int gpiochip_export(struct gpio_chip *chip)
                return 0;
 
        /* use chip->base for the ID; it's already known to be unique */
-       mutex_lock(&sysfs_lock);
        dev = device_create_with_groups(&gpio_class, chip->dev, MKDEV(0, 0),
                                        chip, gpiochip_groups,
                                        "gpiochip%d", chip->base);
@@ -787,6 +786,8 @@ int gpiochip_export(struct gpio_chip *chip)
                status = PTR_ERR(dev);
        else
                status = 0;
+
+       mutex_lock(&sysfs_lock);
        chip->exported = (status == 0);
        mutex_unlock(&sysfs_lock);
 
@@ -803,17 +804,17 @@ void gpiochip_unexport(struct gpio_chip *chip)
        struct gpio_desc *desc;
        unsigned int i;
 
-       mutex_lock(&sysfs_lock);
        dev = class_find_device(&gpio_class, NULL, chip, match_export);
        if (dev) {
                put_device(dev);
                device_unregister(dev);
                /* prevent further gpiod exports */
+               mutex_lock(&sysfs_lock);
                chip->exported = false;
+               mutex_unlock(&sysfs_lock);
                status = 0;
        } else
                status = -ENODEV;
-       mutex_unlock(&sysfs_lock);
 
        if (status)
                chip_dbg(chip, "%s: status %d\n", __func__, status);