linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: grant.likely@secretlab.ca (Grant Likely)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v4 4/6] gpio: introduce lock mechanism for gpiochip_find
Date: Wed, 30 May 2012 14:33:25 +0800	[thread overview]
Message-ID: <20120530063325.0F6AA3E065C@localhost> (raw)
In-Reply-To: <20120530041058.GB2235@b29396-Latitude-E6410>

On Wed, 30 May 2012 12:10:58 +0800, Dong Aisheng <dongas86@gmail.com> wrote:
> Hi Grant,
> 
> On Fri, May 25, 2012 at 06:25:00PM -0600, Grant Likely wrote:
> > On Fri, 25 May 2012 21:36:18 +0800, Dong Aisheng <b29396@freescale.com> wrote:
> > > From: Dong Aisheng <dong.aisheng@linaro.org>
> > > 
> > > The module lock will be automatically claimed for gpiochip_find function
> > > in case the gpio module is removed during the using of gpiochip instance.
> > > Users are responsible to call gpiochip_put to release the lock after
> > > the using.
> > > 
> > > Signed-off-by: Dong Aisheng <dong.aisheng@linaro.org>
> > 
> ...
> > Also, it doesn't do anything to protect against the gpio_chip being
> > removed after the gpio number is resolved, which means the gpio number
> > may no longer be valid, or may no longer point to the same gpio chip.
> > It looks like the locking protection needs to be wider to be useful.
> > 
> I understand the issue now.
> It's correct that we did not lock gpio_chip before calling gpio_request
> after the gpio number is resolved.
> 
> I thought about adding a new API called of_gpio_request to hide the lock
> to users like:
> int of_gpio_request(..)
> {
> 	spin_lock_irqsave(&gpio_lock, flags);
> 	ret = of_get_named_gpio(..);
> 	if (ret < 0)
> 		do_err..
> 	ret = gpio_request(..)
> 
> 	spin_unlock_irqrestore(&gpio_lock, flags);
> 	return ret;
> }
> But it seems it does not work since the gpio_request may sleep and we may
> need a new sleepable lock rather using the exist gpio_lock.
> 
> In the same time, i'm also thinking about a question that do we really
> need to do this to protect gpio_chip being removed afer gpio number is
> resolved?

Probably not (for this series) because it shouldn't cause an oops if
it happens.  Ultimately however it would be good to have proper
reference counting on gpio chips to prevent any problems.

g.

  reply	other threads:[~2012-05-30  6:33 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-25 13:36 [PATCH v4 1/6] gpio: fix a typo of comment message Dong Aisheng
2012-05-25 13:36 ` [PATCH v4 2/6] gpio: re-add of_node_to_gpiochip function Dong Aisheng
2012-05-26  0:01   ` Grant Likely
2012-05-26 16:15     ` Dong Aisheng
2012-05-25 13:36 ` [PATCH v4 3/6] of: release node fix for of_parse_phandle_with_args Dong Aisheng
2012-05-26  0:09   ` Grant Likely
2012-05-25 13:36 ` [PATCH v4 4/6] gpio: introduce lock mechanism for gpiochip_find Dong Aisheng
2012-05-26  0:25   ` Grant Likely
2012-05-26 16:17     ` Dong Aisheng
2012-05-30  4:10     ` Dong Aisheng
2012-05-30  6:33       ` Grant Likely [this message]
2012-05-25 13:36 ` [PATCH v4 5/6] of: add of_parse_phandle_with_args_ext function Dong Aisheng
2012-05-25 16:50   ` Stephen Warren
2012-05-25 13:36 ` [PATCH v4 6/6] pinctrl: add pinctrl gpio binding support Dong Aisheng
2012-05-25 17:03   ` Stephen Warren
2012-05-26 16:52     ` Dong Aisheng
2012-05-27 15:39       ` Stephen Warren
2012-05-30  3:01         ` Dong Aisheng
2012-05-30  3:52           ` Stephen Warren
2012-05-30  6:35     ` Grant Likely
2012-05-26  0:29   ` Grant Likely
2012-05-26 16:58     ` Dong Aisheng
2012-05-30  6:46       ` Grant Likely
2012-05-30  7:29         ` Dong Aisheng
2012-05-25 23:57 ` [PATCH v4 1/6] gpio: fix a typo of comment message Grant Likely

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=20120530063325.0F6AA3E065C@localhost \
    --to=grant.likely@secretlab.ca \
    --cc=linux-arm-kernel@lists.infradead.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).