On Thu, Nov 06, 2014 at 12:12:04PM +0100, Geert Uytterhoeven wrote:
> Hi Mika,
> 
> On Thu, Nov 6, 2014 at 11:58 AM, Mika Westerberg
> <mika.westerb...@linux.intel.com> wrote:
> > On Thu, Nov 06, 2014 at 11:32:19AM +0100, Geert Uytterhoeven wrote:
> >> On Thu, Nov 6, 2014 at 11:30 AM, Mika Westerberg
> >> <mika.westerb...@linux.intel.com> wrote:
> >> >> "leds: leds-gpio: Add support for GPIO descriptors" broke leds-gpio on
> >> >> non-DT platforms for me:
> >> >>
> >> >>     gpiod_direction_output: invalid GPIO
> >> >>     leds-gpio: probe of leds-gpio failed with error -22
> >> >>
> >> >> (desc is NULL in gpiod_direction_output()).
> >> >>
> >> >> DT shmobile reference/multi-platform are fine.
> >> >>
> >> >> I noticed the hard way, as I wanted to add some LEDs to a new platform,
> >> >> but couldn't get it work. It turned out it also had stopped working on
> >> >> r8a7740/armadillo-legacy, so I started bisecting...
> >> >
> >> > Which board file that is?
> >> >
> >> > There is a bug that gpio_to_desc() returns NULL instead if ERR_PTR() in
> >> > that patch but I wonder why gpio_is_valid() and devm_gpio_request_one()
> >> > do not complain about that prior.
> >>
> >> arch/arm/mach-shmobile/board-armadillo800eva.c
> >
> > Are you able to put some printks() to the 'if (!template->gpiod)' branch
> > so that it prints out gpio number and what does devm_gpio_request_one()
> > return?
> >
> > Something like:
> >
> >         if (!template->gpiod) {
> >                 ...
> >                 ret = devm_gpio_request_one(parent, template->gpio, flags,
> >                                             template->name);
> >                 dev_info(parent, "GPIO %u, ret: %d\n", template->gpio, ret);
> >                 if (ret < 0)
> >                         ...
> >
> >                 led_dat->gpiod = gpio_to_desc(template->gpio);
> >                 dev_info(parent, "GPIOD: %p\n", led_dat->gpiod);
> 
> Sure:
> 
>     leds-gpio leds-gpio: GPIO 102, ret: 0
>     leds-gpio leds-gpio: GPIOD: c050e970
> 
> So led_dat is non-NULL. But it's overwritten by NULL later:
> 
>     led_dat->gpiod = template->gpiod;

Ah, that's it. Nice catch!

> Whitespace damaged fix below, to fold into the original.
> If you prefer a proper separate patch, let me know.

It is up to Rafael. I think he wants to stabilize this branch so in that
case separate patch on top would work better.

Feel free to add,

Reviewed-by: Mika Westerberg <mika.westerb...@linux.intel.com>

to the patch.

> 
> diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
> index ba4698c32bb04bde..b3c5d9d6a42bcd8b 100644
> --- a/drivers/leds/leds-gpio.c
> +++ b/drivers/leds/leds-gpio.c
> @@ -92,7 +92,8 @@ static int create_gpio_led(const struct gpio_led *template,
>  {
>         int ret, state;
> 
> -       if (!template->gpiod) {
> +       led_dat->gpiod = template->gpiod;
> +       if (!led_dat->gpiod) {
>                 /*
>                  * This is the legacy code path for platform code that
>                  * still uses GPIO numbers. Ultimately we would like to get
> @@ -122,8 +123,7 @@ static int create_gpio_led(const struct gpio_led 
> *template,
> 
>         led_dat->cdev.name = template->name;
>         led_dat->cdev.default_trigger = template->default_trigger;
> -       led_dat->gpiod = template->gpiod;
> -       led_dat->can_sleep = gpiod_cansleep(template->gpiod);
> +       led_dat->can_sleep = gpiod_cansleep(led_dat->gpiod);
>         led_dat->blinking = 0;
>         if (blink_set) {
>                 led_dat->platform_gpio_blink_set = blink_set;
> 
> Gr{oetje,eeting}s,
> 
>                         Geert
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- 
> ge...@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like 
> that.
>                                 -- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to