From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: Mike Frysinger <vapier@gentoo.org>
Cc: Grant Likely <grant.likely@secretlab.ca>,
Richard Henderson <rth@twiddle.net>,
Ivan Kokshaysky <ink@jurassic.park.msu.ru>,
Matt Turner <mattst88@gmail.com>,
Haavard Skinnemoen <hskinnemoen@gmail.com>,
Hans-Christian Egtvedt <egtvedt@samfundet.no>,
Tony Luck <tony.luck@intel.com>,
Fenghua Yu <fenghua.yu@intel.com>,
Michal Simek <monstr@monstr.eu>,
Ralf Baechle <ralf@linux-mips.org>,
Paul Mundt <lethal@linux-sh.org>, Jonas Bonn <jonas@southpole.se>,
Paul Mackerras <paulus@samba.org>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
"David S. Miller" <davem@davemloft.net>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
Chris Zankel <chris@zankel.net>,
Guan Xuetao <gxt@mprc.pku.edu.cn>
Subject: Re: [PATCH] asm-generic/gpio.h: merge basic gpiolib wrappers
Date: Thu, 27 Oct 2011 14:11:24 +0100 [thread overview]
Message-ID: <20111027131124.GK19187@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <1319720503-3183-1-git-send-email-vapier@gentoo.org>
On Thu, Oct 27, 2011 at 09:01:43AM -0400, Mike Frysinger wrote:
> diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
> index d494001..622851c 100644
> --- a/include/asm-generic/gpio.h
> +++ b/include/asm-generic/gpio.h
> @@ -170,6 +170,29 @@ extern int __gpio_cansleep(unsigned gpio);
>
> extern int __gpio_to_irq(unsigned gpio);
>
> +#ifndef gpio_get_value
> +#define gpio_get_value(gpio) __gpio_get_value(gpio)
> +#endif
> +
> +#ifndef gpio_set_value
> +#define gpio_set_value(gpio, value) __gpio_set_value(gpio, value)
> +#endif
> +
> +#ifndef gpio_cansleep
> +#define gpio_cansleep(gpio) __gpio_cansleep(gpio)
> +#endif
> +
> +#ifndef gpio_to_irq
> +#define gpio_to_irq(gpio) __gpio_to_irq(gpio)
> +#endif
> +
> +#ifndef irq_to_gpio
> +static inline int irq_to_gpio(unsigned int irq)
> +{
> + return -EINVAL;
> +}
> +#endif
> +
This is extremely dangerous. Consider for example this code
(see ARM mach-davinci's gpio.h):
#include <asm-generic/gpio.h>
static inline int gpio_get_value(unsigned gpio)
{
struct davinci_gpio_controller *ctlr;
if (!__builtin_constant_p(gpio) || gpio >= davinci_soc_info.gpio_num)
return __gpio_get_value(gpio);
ctlr = __gpio_to_controller(gpio);
return __gpio_mask(gpio) & __raw_readl(ctlr->in_data);
}
The result with your changes above will be:
static inline int __gpio_get_value(unsigned gpio)
{
struct davinci_gpio_controller *ctlr;
if (!__builtin_constant_p(gpio) || gpio >= davinci_soc_info.gpio_num)
return __gpio_get_value(gpio);
ctlr = __gpio_to_controller(gpio);
return __gpio_mask(gpio) & __raw_readl(ctlr->in_data);
}
and notice the recursive call there.
This is why I didn't solve this using the preprocessor method in ARM, but
instead used __ARM_GPIOLIB_COMPLEX to control whether these definitions
are required.
next prev parent reply other threads:[~2011-10-27 13:11 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-25 7:33 [PATCH] gpiolib/arches: Centralise bolierplate asm/gpio.h Mark Brown
2011-10-25 7:33 ` Mark Brown
2011-10-25 8:33 ` Grant Likely
2011-10-25 8:39 ` Mark Brown
2011-10-25 23:44 ` Mike Frysinger
2011-10-25 23:44 ` Mike Frysinger
2011-10-26 7:33 ` Mark Brown
2011-10-26 7:33 ` Mark Brown
2012-02-03 23:16 ` Grant Likely
2012-02-03 23:16 ` Grant Likely
2011-10-27 13:01 ` [PATCH] asm-generic/gpio.h: merge basic gpiolib wrappers Mike Frysinger
2011-10-27 13:01 ` Mike Frysinger
2011-10-27 13:11 ` Russell King - ARM Linux [this message]
2011-10-27 13:29 ` Mike Frysinger
2011-10-27 13:43 ` Russell King - ARM Linux
2011-10-28 12:15 ` Mike Frysinger
2011-10-28 12:15 ` Mike Frysinger
2011-10-28 12:42 ` Russell King - ARM Linux
2011-10-28 13:51 ` Linus Walleij
2011-10-28 14:04 ` Mike Frysinger
2011-10-27 13:53 ` Russell King - ARM Linux
2011-10-27 22:52 ` [PATCH v2] " Mike Frysinger
2011-10-27 22:52 ` Mike Frysinger
2011-11-03 3:45 ` [PATCH v3] " Mike Frysinger
2011-11-03 3:45 ` Mike Frysinger
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=20111027131124.GK19187@n2100.arm.linux.org.uk \
--to=linux@arm.linux.org.uk \
--cc=benh@kernel.crashing.org \
--cc=chris@zankel.net \
--cc=davem@davemloft.net \
--cc=egtvedt@samfundet.no \
--cc=fenghua.yu@intel.com \
--cc=grant.likely@secretlab.ca \
--cc=gxt@mprc.pku.edu.cn \
--cc=hpa@zytor.com \
--cc=hskinnemoen@gmail.com \
--cc=ink@jurassic.park.msu.ru \
--cc=jonas@southpole.se \
--cc=lethal@linux-sh.org \
--cc=mattst88@gmail.com \
--cc=mingo@redhat.com \
--cc=monstr@monstr.eu \
--cc=paulus@samba.org \
--cc=ralf@linux-mips.org \
--cc=rth@twiddle.net \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=vapier@gentoo.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).