Skip to content

Commit

Permalink
leds: trigger: gpio: GPIO 0 is valid
Browse files Browse the repository at this point in the history
Allow all valid GPIOs to be used in the driver.

Fixes: 17354bf ("leds: Add gpio-led trigger")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
  • Loading branch information
andy-shev authored and jacek-anaszewski committed Sep 1, 2019
1 parent d4b0220 commit 4e42104
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions drivers/leds/trigger/ledtrig-gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ static ssize_t gpio_trig_gpio_store(struct device *dev,
if (gpio_data->gpio == gpio)
return n;

if (!gpio) {
if (gpio_data->gpio != 0)
if (!gpio_is_valid(gpio)) {
if (gpio_is_valid(gpio_data->gpio))
free_irq(gpio_to_irq(gpio_data->gpio), led);
gpio_data->gpio = 0;
gpio_data->gpio = gpio;
return n;
}

Expand All @@ -144,7 +144,7 @@ static ssize_t gpio_trig_gpio_store(struct device *dev,
if (ret) {
dev_err(dev, "request_irq failed with error %d\n", ret);
} else {
if (gpio_data->gpio != 0)
if (gpio_is_valid(gpio_data->gpio))
free_irq(gpio_to_irq(gpio_data->gpio), led);
gpio_data->gpio = gpio;
/* After changing the GPIO, we need to update the LED. */
Expand Down Expand Up @@ -172,6 +172,8 @@ static int gpio_trig_activate(struct led_classdev *led)
return -ENOMEM;

gpio_data->led = led;
gpio_data->gpio = -ENOENT;

led_set_trigger_data(led, gpio_data);

return 0;
Expand All @@ -181,7 +183,7 @@ static void gpio_trig_deactivate(struct led_classdev *led)
{
struct gpio_trig_data *gpio_data = led_get_trigger_data(led);

if (gpio_data->gpio != 0)
if (gpio_is_valid(gpio_data->gpio))
free_irq(gpio_to_irq(gpio_data->gpio), led);
kfree(gpio_data);
}
Expand Down

0 comments on commit 4e42104

Please sign in to comment.