mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Trent Piepho <tpiepho@gmail.com>
Cc: David Daney <david.daney@cavium.com>,
	linux-kernel@vger.kernel.org, Richard Purdie <rpurdie@rpsys.net>,
	Grant Likely <grant.likely@secretlab.ca>
Subject: Re: [PATCH] leds/of: leds-gpio.c: Use gpio_get_value_cansleep() when initializing.
Date: Thu, 8 Sep 2011 22:44:27 -0700	[thread overview]
Message-ID: <20110908224427.6685a152.akpm@linux-foundation.org> (raw)
In-Reply-To: <CA+7tXih+4A_JDCHcN1VOVeKjapEfY9aYwCG4cBiHX1iWXb_ECw@mail.gmail.com>

On Thu, 8 Sep 2011 22:30:58 -0700 Trent Piepho <tpiepho@gmail.com> wrote:

> >
> > They're very different. __Why is it OK to replace one with the other??
> 
> What's supposed to happen is chip->get() will be a method that does
> "readl(GPIO_GPLR) & GPIO_GPIO(gpio);" or whatever the inlined bit in
> gpio_get_value() is.  So calling gpio_get_value_cansleep() should
> still get the correct value for the gpio.  It just won't be an inlined
> register read anymore.
> 
> For instance, all the arch versions that use builtin_constant_p() will
> not take the inline path, since the gpio number if obviously not a
> constant when gpio_get_value() is called in this leds function.  So
> they inline into a call to __gpio_get_value().  Which as you've
> pointed out is nearly exactly the same as gpio_get_value_cansleep().
> The only change is debugging related, that of the might_sleep_if() to
> a WARN_ON().
> 
> One could have:
> static inline int __gpio_get_value(gpio) { return
> _gpio_get_value(gpio, GFP_ATOMIC); }
> static inline int gpio_get_value_cansleep(gpio) { return
> _gpio_get_value(gpio, GFP_KERNEL); }
> 
> Then _gpio_get_value(gpio, context) would be the current code that's
> common to both __gpio_get_value() and gpio_get_value_cansleep(),
> except it uses context solely to spit a warning if the gpio can't be
> done from the requested context or if the context isn't allowable from
> whence the call was made.

Well, that may be the case with the current in-tree implementations (I
didn't check), but from a design point of view the core code shouldn't
"know" how the architecture is implementing gpio_get_value().

> And then one would ask if all this complexity in the interface is
> really the best way to throw warnings about sleeping in atomic
> context?  Because if there was a better way to do that, we could just
> s/(gpio_get_value)_cansleep/\1/g and not worry about these someone
> did/didn't call cansleep() when they should done the opposite patches.

Yes, it sounds like the interface around there needs a rethink.

I don't actually know why gpio_get_value_cansleep() exists.  I looked
at the silly comment and for some reason didn't feel like working this
out.

> >> > Asides:
> >> >
> >> > The duplication of code between __gpio_get_value() and
> >> > gpio_get_value_cansleep() is daft.
> >> >
> >> > The comment over gpio_get_value_cansleep() sucks mud rocks.
> >
> > Preserving this...
> 
> Well, inlining code that sits on a waitq doesn't make a lot of sense.

No need for inlining - just a function call.  One which the compiler
might turn into a tailcall for us.


  reply	other threads:[~2011-09-09  5:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-30 23:39 David Daney
2011-09-09  1:35 ` Andrew Morton
2011-09-09  3:54   ` Trent Piepho
2011-09-09  4:07     ` Andrew Morton
2011-09-09  5:30       ` Trent Piepho
2011-09-09  5:44         ` Andrew Morton [this message]
2011-09-09 16:15           ` David Daney
2011-09-09 17:48             ` Andrew Morton
2011-09-09 17:41           ` Trent Piepho

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=20110908224427.6685a152.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=david.daney@cavium.com \
    --cc=grant.likely@secretlab.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rpurdie@rpsys.net \
    --cc=tpiepho@gmail.com \
    /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

Powered by JetHome