aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio
diff options
context:
space:
mode:
authorJohan Hovold <johan@kernel.org>2015-05-04 11:10:43 -0400
committerLinus Walleij <linus.walleij@linaro.org>2015-05-12 04:47:35 -0400
commit56d30ec14c13303eb9e7c34358ba6549fc7b0121 (patch)
tree1d39883f05c4a462e55a645c442db81241debb55 /drivers/gpio
parente4339ce32372e2f8c98222c0923b79476c29a309 (diff)
gpio: sysfs: clean up gpiod_export_link locking
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>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/gpiolib-sysfs.c28
1 files changed, 8 insertions, 20 deletions
diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index 1161a46618dd..682e4d34999c 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -631,34 +631,22 @@ static int match_export(struct device *dev, const void *desc)
631int gpiod_export_link(struct device *dev, const char *name, 631int gpiod_export_link(struct device *dev, const char *name,
632 struct gpio_desc *desc) 632 struct gpio_desc *desc)
633{ 633{
634 int status = -EINVAL; 634 struct device *cdev;
635 int ret;
635 636
636 if (!desc) { 637 if (!desc) {
637 pr_warn("%s: invalid GPIO\n", __func__); 638 pr_warn("%s: invalid GPIO\n", __func__);
638 return -EINVAL; 639 return -EINVAL;
639 } 640 }
640 641
641 mutex_lock(&sysfs_lock); 642 cdev = class_find_device(&gpio_class, NULL, desc, match_export);
642 643 if (!cdev)
643 if (test_bit(FLAG_EXPORT, &desc->flags)) { 644 return -ENODEV;
644 struct device *tdev;
645
646 tdev = class_find_device(&gpio_class, NULL, desc, match_export);
647 if (tdev != NULL) {
648 status = sysfs_create_link(&dev->kobj, &tdev->kobj,
649 name);
650 put_device(tdev);
651 } else {
652 status = -ENODEV;
653 }
654 }
655
656 mutex_unlock(&sysfs_lock);
657 645
658 if (status) 646 ret = sysfs_create_link(&dev->kobj, &cdev->kobj, name);
659 gpiod_dbg(desc, "%s: status %d\n", __func__, status); 647 put_device(cdev);
660 648
661 return status; 649 return ret;
662} 650}
663EXPORT_SYMBOL_GPL(gpiod_export_link); 651EXPORT_SYMBOL_GPL(gpiod_export_link);
664 652