* [PATCH 1/3] Trivial: Fix coding style in worker thread code for ledtrig-gpio.
@ 2009-07-14 17:03 Thadeu Lima de Souza Cascardo
2009-07-14 17:03 ` [PATCH 2/3] Fix multiple requests and releases of IRQ for GPIO LED Trigger Thadeu Lima de Souza Cascardo
2009-07-14 17:58 ` [PATCH] Trivial: Fix coding style in worker thread code for ledtrig-gpio Thadeu Lima de Souza Cascardo
0 siblings, 2 replies; 4+ messages in thread
From: Thadeu Lima de Souza Cascardo @ 2009-07-14 17:03 UTC (permalink / raw)
To: me; +Cc: linux-kernel, rpurdie, rpurdie, srcvale, Thadeu Lima de Souza Cascardo
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Signed-off-by: Samuel R. C. Vale <srcvale@holoscopio.com>
---
drivers/leds/ledtrig-gpio.c | 26 +++++++++++++-------------
1 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/drivers/leds/ledtrig-gpio.c b/drivers/leds/ledtrig-gpio.c
index a247ae6..6b7bb12 100644
--- a/drivers/leds/ledtrig-gpio.c
+++ b/drivers/leds/ledtrig-gpio.c
@@ -44,22 +44,22 @@ static void gpio_trig_work(struct work_struct *work)
struct gpio_trig_data, work);
int tmp;
- if (!gpio_data->gpio)
+ if (!gpio_data->gpio)
return;
- tmp = gpio_get_value(gpio_data->gpio);
- if (gpio_data->inverted)
- tmp = !tmp;
-
- if (tmp) {
- if (gpio_data->desired_brightness)
- led_set_brightness(gpio_data->led,
- gpio_data->desired_brightness);
- else
- led_set_brightness(gpio_data->led, LED_FULL);
- } else {
- led_set_brightness(gpio_data->led, LED_OFF);
- }
+ tmp = gpio_get_value(gpio_data->gpio);
+ if (gpio_data->inverted)
+ tmp = !tmp;
+
+ if (tmp) {
+ if (gpio_data->desired_brightness)
+ led_set_brightness(gpio_data->led,
+ gpio_data->desired_brightness);
+ else
+ led_set_brightness(gpio_data->led, LED_FULL);
+ } else {
+ led_set_brightness(gpio_data->led, LED_OFF);
+ }
}
static ssize_t gpio_trig_brightness_show(struct device *dev,
--
1.6.3.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/3] Fix multiple requests and releases of IRQ for GPIO LED Trigger.
2009-07-14 17:03 [PATCH 1/3] Trivial: Fix coding style in worker thread code for ledtrig-gpio Thadeu Lima de Souza Cascardo
@ 2009-07-14 17:03 ` Thadeu Lima de Souza Cascardo
2009-07-14 17:03 ` [PATCH 3/3] After setting inverted attribute, we must update the LED Thadeu Lima de Souza Cascardo
2009-07-14 17:58 ` [PATCH] Trivial: Fix coding style in worker thread code for ledtrig-gpio Thadeu Lima de Souza Cascardo
1 sibling, 1 reply; 4+ messages in thread
From: Thadeu Lima de Souza Cascardo @ 2009-07-14 17:03 UTC (permalink / raw)
To: me; +Cc: linux-kernel, rpurdie, rpurdie, srcvale, Thadeu Lima de Souza Cascardo
When setting the same GPIO number, multiple IRQ shared requests will be
done without freing the previous request. It will also try to free a
failed request or an already freed IRQ if 0 was written to the gpio
file.
All these oops and leaks were fixed with the following solution: keep
the previous allocated GPIO (if any) still allocated in case the new
request fails. The alternative solution would desallocate the previous
allocated GPIO and set gpio as 0.
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Signed-off-by: Samuel R. C. Vale <srcvale@holoscopio.com>
---
drivers/leds/ledtrig-gpio.c | 21 ++++++++++++++-------
1 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/drivers/leds/ledtrig-gpio.c b/drivers/leds/ledtrig-gpio.c
index 6b7bb12..7c9aff9 100644
--- a/drivers/leds/ledtrig-gpio.c
+++ b/drivers/leds/ledtrig-gpio.c
@@ -146,20 +146,26 @@ static ssize_t gpio_trig_gpio_store(struct device *dev,
return -EINVAL;
}
+ if (gpio_data->gpio == gpio)
+ return n;
+
if (!gpio) {
- free_irq(gpio_to_irq(gpio_data->gpio), led);
+ if (gpio_data->gpio != 0)
+ free_irq(gpio_to_irq(gpio_data->gpio), led);
+ gpio_data->gpio = 0;
return n;
}
- if (gpio_data->gpio > 0 && gpio_data->gpio != gpio)
- free_irq(gpio_to_irq(gpio_data->gpio), led);
-
- gpio_data->gpio = gpio;
ret = request_irq(gpio_to_irq(gpio), gpio_trig_irq,
IRQF_SHARED | IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING, "ledtrig-gpio", led);
- if (ret)
+ if (ret) {
dev_err(dev, "request_irq failed with error %d\n", ret);
+ } else {
+ if (gpio_data->gpio != 0)
+ free_irq(gpio_to_irq(gpio_data->gpio), led);
+ gpio_data->gpio = gpio;
+ }
return ret ? ret : n;
}
@@ -211,7 +217,8 @@ static void gpio_trig_deactivate(struct led_classdev *led)
device_remove_file(led->dev, &dev_attr_inverted);
device_remove_file(led->dev, &dev_attr_desired_brightness);
flush_work(&gpio_data->work);
- free_irq(gpio_to_irq(gpio_data->gpio),led);
+ if (gpio_data->gpio != 0)
+ free_irq(gpio_to_irq(gpio_data->gpio), led);
kfree(gpio_data);
}
}
--
1.6.3.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 3/3] After setting inverted attribute, we must update the LED.
2009-07-14 17:03 ` [PATCH 2/3] Fix multiple requests and releases of IRQ for GPIO LED Trigger Thadeu Lima de Souza Cascardo
@ 2009-07-14 17:03 ` Thadeu Lima de Souza Cascardo
0 siblings, 0 replies; 4+ messages in thread
From: Thadeu Lima de Souza Cascardo @ 2009-07-14 17:03 UTC (permalink / raw)
To: me; +Cc: linux-kernel, rpurdie, rpurdie, srcvale, Thadeu Lima de Souza Cascardo
If we change the inverted attribute to another value, the LED will not
be inverted until we change the GPIO state.
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
---
drivers/leds/ledtrig-gpio.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/drivers/leds/ledtrig-gpio.c b/drivers/leds/ledtrig-gpio.c
index 7c9aff9..1136f50 100644
--- a/drivers/leds/ledtrig-gpio.c
+++ b/drivers/leds/ledtrig-gpio.c
@@ -117,6 +117,9 @@ static ssize_t gpio_trig_inverted_store(struct device *dev,
gpio_data->inverted = !!inverted;
+ /* After inverting, we need to update the LED. */
+ schedule_work(&gpio_data->work);
+
return n;
}
static DEVICE_ATTR(inverted, 0644, gpio_trig_inverted_show,
--
1.6.3.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] Trivial: Fix coding style in worker thread code for ledtrig-gpio.
2009-07-14 17:03 [PATCH 1/3] Trivial: Fix coding style in worker thread code for ledtrig-gpio Thadeu Lima de Souza Cascardo
2009-07-14 17:03 ` [PATCH 2/3] Fix multiple requests and releases of IRQ for GPIO LED Trigger Thadeu Lima de Souza Cascardo
@ 2009-07-14 17:58 ` Thadeu Lima de Souza Cascardo
1 sibling, 0 replies; 4+ messages in thread
From: Thadeu Lima de Souza Cascardo @ 2009-07-14 17:58 UTC (permalink / raw)
To: me
Cc: trivial, linux-kernel, rpurdie, rpurdie, srcvale,
Thadeu Lima de Souza Cascardo
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Signed-off-by: Samuel R. C. Vale <srcvale@holoscopio.com>
---
drivers/leds/ledtrig-gpio.c | 28 ++++++++++++++--------------
1 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/drivers/leds/ledtrig-gpio.c b/drivers/leds/ledtrig-gpio.c
index 1bc5db4..f591337 100644
--- a/drivers/leds/ledtrig-gpio.c
+++ b/drivers/leds/ledtrig-gpio.c
@@ -44,22 +44,22 @@ static void gpio_trig_work(struct work_struct *work)
struct gpio_trig_data, work);
int tmp;
- if (!gpio_data->gpio)
- return;
-
- tmp = gpio_get_value(gpio_data->gpio);
- if (gpio_data->inverted)
- tmp = !tmp;
-
- if (tmp) {
- if (gpio_data->desired_brightness)
- led_set_brightness(gpio_data->led,
- gpio_data->desired_brightness);
- else
- led_set_brightness(gpio_data->led, LED_FULL);
- } else {
- led_set_brightness(gpio_data->led, LED_OFF);
- }
+ if (!gpio_data->gpio)
+ return;
+
+ tmp = gpio_get_value(gpio_data->gpio);
+ if (gpio_data->inverted)
+ tmp = !tmp;
+
+ if (tmp) {
+ if (gpio_data->desired_brightness)
+ led_set_brightness(gpio_data->led,
+ gpio_data->desired_brightness);
+ else
+ led_set_brightness(gpio_data->led, LED_FULL);
+ } else {
+ led_set_brightness(gpio_data->led, LED_OFF);
+ }
}
static ssize_t gpio_trig_brightness_show(struct device *dev,
--
1.6.3.3
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-07-14 17:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-14 17:03 [PATCH 1/3] Trivial: Fix coding style in worker thread code for ledtrig-gpio Thadeu Lima de Souza Cascardo
2009-07-14 17:03 ` [PATCH 2/3] Fix multiple requests and releases of IRQ for GPIO LED Trigger Thadeu Lima de Souza Cascardo
2009-07-14 17:03 ` [PATCH 3/3] After setting inverted attribute, we must update the LED Thadeu Lima de Souza Cascardo
2009-07-14 17:58 ` [PATCH] Trivial: Fix coding style in worker thread code for ledtrig-gpio Thadeu Lima de Souza Cascardo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®