Commit 33a68e86 authored by Linus Walleij's avatar Linus Walleij

gpio: reference count the gpio device for each desc

Every time a descriptor is retrieved from the gpiolib, we issue
module_get() to reference count the module supplying the GPIOs.
We also need to call device_get() and device_put() as we also
reference the backing gpio_device when doing this.

Since the sysfs GPIO interface is using gpiod_get() this will
also reference count the sysfs requests until all GPIOs are
unexported.
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent fdeb8e15
...@@ -1205,6 +1205,8 @@ int gpiod_request(struct gpio_desc *desc, const char *label) ...@@ -1205,6 +1205,8 @@ int gpiod_request(struct gpio_desc *desc, const char *label)
status = __gpiod_request(desc, label); status = __gpiod_request(desc, label);
if (status < 0) if (status < 0)
module_put(gdev->owner); module_put(gdev->owner);
else
get_device(&gdev->dev);
} }
if (status) if (status)
...@@ -1248,10 +1250,12 @@ static bool __gpiod_free(struct gpio_desc *desc) ...@@ -1248,10 +1250,12 @@ static bool __gpiod_free(struct gpio_desc *desc)
void gpiod_free(struct gpio_desc *desc) void gpiod_free(struct gpio_desc *desc)
{ {
if (desc && __gpiod_free(desc)) if (desc && desc->gdev && __gpiod_free(desc)) {
module_put(desc->gdev->owner); module_put(desc->gdev->owner);
else put_device(&desc->gdev->dev);
} else {
WARN_ON(extra_checks); WARN_ON(extra_checks);
}
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment