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>
This commit is contained in:
Johan Hovold 2015-05-04 17:10:43 +02:00 committed by Linus Walleij
parent e4339ce323
commit 56d30ec14c

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