hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/leds/trigger/ledtrig-gpio.c
....@@ -1,11 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * ledtrig-gio.c - LED Trigger Based on GPIO events
34 *
45 * Copyright 2009 Felipe Balbi <me@felipebalbi.com>
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License version 2 as
8
- * published by the Free Software Foundation.
96 */
107
118 #include <linux/module.h>
....@@ -102,7 +99,8 @@
10299 gpio_data->inverted = inverted;
103100
104101 /* After inverting, we need to update the LED. */
105
- gpio_trig_irq(0, led);
102
+ if (gpio_is_valid(gpio_data->gpio))
103
+ gpio_trig_irq(0, led);
106104
107105 return n;
108106 }
....@@ -134,10 +132,10 @@
134132 if (gpio_data->gpio == gpio)
135133 return n;
136134
137
- if (!gpio) {
138
- if (gpio_data->gpio != 0)
135
+ if (!gpio_is_valid(gpio)) {
136
+ if (gpio_is_valid(gpio_data->gpio))
139137 free_irq(gpio_to_irq(gpio_data->gpio), led);
140
- gpio_data->gpio = 0;
138
+ gpio_data->gpio = gpio;
141139 return n;
142140 }
143141
....@@ -147,7 +145,7 @@
147145 if (ret) {
148146 dev_err(dev, "request_irq failed with error %d\n", ret);
149147 } else {
150
- if (gpio_data->gpio != 0)
148
+ if (gpio_is_valid(gpio_data->gpio))
151149 free_irq(gpio_to_irq(gpio_data->gpio), led);
152150 gpio_data->gpio = gpio;
153151 /* After changing the GPIO, we need to update the LED. */
....@@ -175,6 +173,8 @@
175173 return -ENOMEM;
176174
177175 gpio_data->led = led;
176
+ gpio_data->gpio = -ENOENT;
177
+
178178 led_set_trigger_data(led, gpio_data);
179179
180180 return 0;
....@@ -184,7 +184,7 @@
184184 {
185185 struct gpio_trig_data *gpio_data = led_get_trigger_data(led);
186186
187
- if (gpio_data->gpio != 0)
187
+ if (gpio_is_valid(gpio_data->gpio))
188188 free_irq(gpio_to_irq(gpio_data->gpio), led);
189189 kfree(gpio_data);
190190 }