gpio: sysfs: clean up gpiod_export_link locking
authorJohan Hovold <johan@kernel.org>
Mon, 4 May 2015 15:10:43 +0000 (17:10 +0200)
committerLinus Walleij <linus.walleij@linaro.org>
Tue, 12 May 2015 08:47:35 +0000 (10:47 +0200)
Drop unnecessary locking from gpiod_export_link. If the class device has
not already been unregistered, class_find_device returns the ref-counted
class device so there's no need for locking.

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 1161a46618dd3d4958cd22422747218652923e92..682e4d34999c4e5f349322f5b237c328e5233080 100644 (file)
@@ -631,34 +631,22 @@ static int match_export(struct device *dev, const void *desc)
 int gpiod_export_link(struct device *dev, const char *name,
                      struct gpio_desc *desc)
 {
-       int                     status = -EINVAL;
+       struct device *cdev;
+       int ret;
 
        if (!desc) {
                pr_warn("%s: invalid GPIO\n", __func__);
                return -EINVAL;
        }
 
-       mutex_lock(&sysfs_lock);
-
-       if (test_bit(FLAG_EXPORT, &desc->flags)) {
-               struct device *tdev;
-
-               tdev = class_find_device(&gpio_class, NULL, desc, match_export);
-               if (tdev != NULL) {
-                       status = sysfs_create_link(&dev->kobj, &tdev->kobj,
-                                               name);
-                       put_device(tdev);
-               } else {
-                       status = -ENODEV;
-               }
-       }
-
-       mutex_unlock(&sysfs_lock);
+       cdev = class_find_device(&gpio_class, NULL, desc, match_export);
+       if (!cdev)
+               return -ENODEV;
 
-       if (status)
-               gpiod_dbg(desc, "%s: status %d\n", __func__, status);
+       ret = sysfs_create_link(&dev->kobj, &cdev->kobj, name);
+       put_device(cdev);
 
-       return status;
+       return ret;
 }
 EXPORT_SYMBOL_GPL(gpiod_export_link);