From: Linus Walleij <linus.walleij@linaro.org>
To: linux-gpio@vger.kernel.org,
Alexandre Courbot <acourbot@nvidia.com>,
Johan Hovold <johan@kernel.org>,
Michael Welling <mwelling@ieee.org>,
Markus Pargmann <mpa@pengutronix.de>
Cc: Bamvor Jian Zhang <bamvor.zhangjian@linaro.org>,
Grant Likely <grant.likely@linaro.org>,
Linus Walleij <linus.walleij@linaro.org>
Subject: [PATCH 5/6] gpio: reference count the gpio device for each desc
Date: Thu, 11 Feb 2016 11:26:22 +0100 [thread overview]
Message-ID: <1455186383-28004-6-git-send-email-linus.walleij@linaro.org> (raw)
In-Reply-To: <1455186383-28004-1-git-send-email-linus.walleij@linaro.org>
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: Linus Walleij <linus.walleij@linaro.org>
---
drivers/gpio/gpiolib.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index cbc9c764a7fb..157ab40d19b1 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1205,6 +1205,8 @@ int gpiod_request(struct gpio_desc *desc, const char *label)
status = __gpiod_request(desc, label);
if (status < 0)
module_put(gdev->owner);
+ else
+ get_device(&gdev->dev);
}
if (status)
@@ -1248,10 +1250,12 @@ static bool __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);
- else
+ put_device(&desc->gdev->dev);
+ } else {
WARN_ON(extra_checks);
+ }
}
/**
--
2.4.3
next prev parent reply other threads:[~2016-02-11 10:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-11 10:26 [PATCH 0/6] gpiolib refactorings after device addition Linus Walleij
2016-02-11 10:26 ` [PATCH 1/6] gpio: remember to finally free gpio_device Linus Walleij
2016-02-11 10:26 ` [PATCH 2/6] gpio: move sysfs mock device to the gpio_device Linus Walleij
2016-02-11 10:26 ` [PATCH 3/6] gpio: move descriptors into gpio_device Linus Walleij
2016-02-11 10:26 ` [PATCH 4/6] gpio: reflect base and ngpio " Linus Walleij
2016-02-11 10:26 ` Linus Walleij [this message]
2016-02-11 10:26 ` [PATCH 6/6] gpio: move the pin ranges " Linus Walleij
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1455186383-28004-6-git-send-email-linus.walleij@linaro.org \
--to=linus.walleij@linaro.org \
--cc=acourbot@nvidia.com \
--cc=bamvor.zhangjian@linaro.org \
--cc=grant.likely@linaro.org \
--cc=johan@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=mpa@pengutronix.de \
--cc=mwelling@ieee.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).