linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] leds: leds-gpio: Fix legacy GPIO number case
@ 2014-11-06 11:23 Geert Uytterhoeven
  2014-11-06 11:50 ` Mika Westerberg
  2014-11-06 17:31 ` Rafael J. Wysocki
  0 siblings, 2 replies; 3+ messages in thread
From: Geert Uytterhoeven @ 2014-11-06 11:23 UTC (permalink / raw)
  To: Mika Westerberg, Rafael J. Wysocki
  Cc: Bryan Wu, Alexandre Courbot, Arnd Bergmann, Grant Likely,
	Richard Purdie, Linus Walleij, linux-leds, linux-arm-kernel,
	linux-sh, linux-kernel, Geert Uytterhoeven

In the legacy case, led_dat->gpiod is initialized correctly, but
overwritten later by template->gpiod, which is NULL, causing leds-gpio
to fail with:

    gpiod_direction_output: invalid GPIO
    leds-gpio: probe of leds-gpio failed with error -22

Move the initialization of led_dat->gpiod from template->gpiod up, and
always use led_dat->gpiod later, to fix this.

Fixes: 5c51277a9ababfa4 ("leds: leds-gpio: Add support for GPIO descriptors")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/leds/leds-gpio.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

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;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-11-06 17:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-06 11:23 [PATCH] leds: leds-gpio: Fix legacy GPIO number case Geert Uytterhoeven
2014-11-06 11:50 ` Mika Westerberg
2014-11-06 17:31 ` Rafael J. Wysocki

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).