Re: [PATCH] gpiolib: Add 'struct gpio_chip' forward declarationfor !GPIOLIB case

From: Anton Vorontsov
Date: Tue Aug 31 2010 - 13:08:11 EST


On Tue, Aug 31, 2010 at 10:44:14AM -0600, Grant Likely wrote:
> On Tue, Aug 31, 2010 at 2:37 AM, Anton Vorontsov <cbouatmailru@xxxxxxxxx> wrote:
> > On Tue, Aug 31, 2010 at 02:03:44AM -0600, Grant Likely wrote:
> >> On Tue, Aug 24, 2010 at 01:26:23PM +0400, Anton Vorontsov wrote:
> >> > With CONFIG_GPIOLIB=n, the 'struct gpio_chip' is not declared,
> >> > so the following pops up on PowerPC:
> >> >
> >> > Â cc1: warnings being treated as errors
> >> > Â In file included from arch/powerpc/platforms/52xx/mpc52xx_common.c:19:
> >> > Â include/linux/of_gpio.h:74: warning: 'struct gpio_chip' declared
> >> > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â inside parameter list
> >> > Â include/linux/of_gpio.h:74: warning: its scope is only this definition
> >> > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â or declaration, which is probably not what
> >> > Â Â Â Â Â Â Â Â Â Â Â Â Â you want
> >> > Â include/linux/of_gpio.h:75: warning: 'struct gpio_chip' declared
> >> > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â inside parameter list
> >> > Â make[2]: *** [arch/powerpc/platforms/52xx/mpc52xx_common.o] Error 1
> >> >
> >> > This patch fixes the issue by providing the proper forward declaration.
> >> >
> >> > Signed-off-by: Anton Vorontsov <cbouatmailru@xxxxxxxxx>
> >>
> >> This doesn't actually solve the problem, and gpiochip should
> >> remain undefined when CONFIG_GPIOLIB=n to catch exactly these
> >> build failures. ÂThe real problem is that I merged a change
> >> into the mpc5200 code that required CONFIG_GPIOLIB be enabled
> >> without reflecting that requirement in Kconfig.
> >
> > No, look closer. The error is in of_gpio.h, and it's perfectly
> > fine to include it w/o GPIOLIB=y.
>
> Looking even closer, we're both wrong. You're right I didn't look
> carefully enough, and the error is in of_gpio.h, not the .c file.
>
> However, it is not okay to get the definitions from of_gpio.h when
> CONFIG_GPIOLIB=n. If GPIOLIB, or more specifically OF_GPIO isn't set,
> then the of_gpio.h definitions should either not be defined, or should
> be defined as empty stubs (where appropriate).

Grrr. Grant, look again, even closer than you did.

They are stubs!

#else /* CONFIG_OF_GPIO */ <<<<<< !OF_GPIO (or !GPIOLIB) case.

/* Drivers may not strictly depend on the GPIO support, so let them link. */
static inline int of_get_gpio_flags(struct device_node *np, int index,
enum of_gpio_flags *flags)
{
return -ENOSYS;
}

static inline unsigned int of_gpio_count(struct device_node *np)
{
return 0;
}

static inline void of_gpiochip_add(struct gpio_chip *gc) { }
static inline void of_gpiochip_remove(struct gpio_chip *gc) { }

#endif /* CONFIG_OF_GPIO */

The errors are triggered by the of_gpiochip_*() stubs, which
are needed by the drivers/gpio/gpiolib.c.

Do you want to add another #ifdef CONFIG_GPIOLIB around
of_gpiochip_*()? That would be ugly.

There's nothing wrong in providing the forward decls, you
can't dereference it anyway (so you would still catch the
bogus users). And at the same time it's will work great
for these stubs.

--
Anton Vorontsov
email: cbouatmailru@xxxxxxxxx
irc://irc.freenode.net/bd2
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/