diff mbox

leds-gpio: Fix default state handling on OF platforms

Message ID 20100205205437.GA4733@oksana.dev.rtsoft.ru (mailing list archive)
State Not Applicable
Delegated to: Grant Likely
Headers show

Commit Message

Anton Vorontsov Feb. 5, 2010, 8:54 p.m. UTC
The driver wrongly sets default state for LEDs that don't specify
default-state property.

Currently the driver handles default state this way:

memset(&led, 0, sizeof(led));
for_each_child_of_node(np, child) {
	state = of_get_property(child, "default-state", NULL);
	if (state) {
		if (!strcmp(state, "keep"))
			led.default_state = LEDS_GPIO_DEFSTATE_KEEP;
		...
	}
	ret = create_gpio_led(&led, ...);
}

Which means that all LEDs that do not specify default-state will
inherit the last value of the default-state property, which is wrong.

This patch fixes the issue by moving LED's template initialization
into the loop body.

Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
---
 drivers/leds/leds-gpio.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

Comments

Andrew Morton Feb. 8, 2010, 9:04 p.m. UTC | #1
On Fri, 5 Feb 2010 23:54:37 +0300
Anton Vorontsov <avorontsov@ru.mvista.com> wrote:

> The driver wrongly sets default state for LEDs that don't specify
> default-state property.
> 
> Currently the driver handles default state this way:
> 
> memset(&led, 0, sizeof(led));
> for_each_child_of_node(np, child) {
> 	state = of_get_property(child, "default-state", NULL);
> 	if (state) {
> 		if (!strcmp(state, "keep"))
> 			led.default_state = LEDS_GPIO_DEFSTATE_KEEP;
> 		...
> 	}
> 	ret = create_gpio_led(&led, ...);
> }
> 
> Which means that all LEDs that do not specify default-state will
> inherit the last value of the default-state property, which is wrong.


Does this actually happen in any 2.6.33 driver code?  If so, we might
want to merge this into 2.6.33.  And perhaps earlier kernels.  Or not. 
There's no way for me to tell :(
Anton Vorontsov Feb. 8, 2010, 10:23 p.m. UTC | #2
On Mon, Feb 08, 2010 at 01:04:55PM -0800, Andrew Morton wrote:
> On Fri, 5 Feb 2010 23:54:37 +0300
> Anton Vorontsov <avorontsov@ru.mvista.com> wrote:
> 
> > The driver wrongly sets default state for LEDs that don't specify
> > default-state property.
[...]
> Does this actually happen in any 2.6.33 driver code?

Well, the code that I fixed constructs Linux structures out of
OpenFirmware device tree. OF tree is somewhat similar to ACPI or
DMI tables in x86 world. So, in general, OF isn't kernel version
dependant.

(We have an in-tree depot of device trees for reference/devel boards
in arch/powerpc/boot/dts/, but this is surely not a conclusive
list of device trees in the wild.)

> If so, we might
> want to merge this into 2.6.33.  And perhaps earlier kernels.  Or not. 
> There's no way for me to tell :(

Since the fix is trivial, I'd say 2.6.33. But the issue isn't major,
so no big deal if it won't make it.

Thanks!
Grant Likely Feb. 15, 2010, 7:39 p.m. UTC | #3
On Fri, Feb 5, 2010 at 1:54 PM, Anton Vorontsov
<avorontsov@ru.mvista.com> wrote:
> The driver wrongly sets default state for LEDs that don't specify
> default-state property.
>
> Currently the driver handles default state this way:
>
> memset(&led, 0, sizeof(led));
> for_each_child_of_node(np, child) {
>        state = of_get_property(child, "default-state", NULL);
>        if (state) {
>                if (!strcmp(state, "keep"))
>                        led.default_state = LEDS_GPIO_DEFSTATE_KEEP;
>                ...
>        }
>        ret = create_gpio_led(&led, ...);
> }
>
> Which means that all LEDs that do not specify default-state will
> inherit the last value of the default-state property, which is wrong.
>
> This patch fixes the issue by moving LED's template initialization
> into the loop body.
>
> Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>

Acked-by: Grant Likely <grant.likely@secretlab.ca>

Richard, I assume you'll pick this one up via your tree?

g.

> ---
>  drivers/leds/leds-gpio.c |    3 +--
>  1 files changed, 1 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
> index e5225d2..0823e26 100644
> --- a/drivers/leds/leds-gpio.c
> +++ b/drivers/leds/leds-gpio.c
> @@ -211,7 +211,6 @@ static int __devinit of_gpio_leds_probe(struct of_device *ofdev,
>                                        const struct of_device_id *match)
>  {
>        struct device_node *np = ofdev->node, *child;
> -       struct gpio_led led;
>        struct gpio_led_of_platform_data *pdata;
>        int count = 0, ret;
>
> @@ -226,8 +225,8 @@ static int __devinit of_gpio_leds_probe(struct of_device *ofdev,
>        if (!pdata)
>                return -ENOMEM;
>
> -       memset(&led, 0, sizeof(led));
>        for_each_child_of_node(np, child) {
> +               struct gpio_led led = {};
>                enum of_gpio_flags flags;
>                const char *state;
>
> --
> 1.6.5.7
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>
diff mbox

Patch

diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index e5225d2..0823e26 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -211,7 +211,6 @@  static int __devinit of_gpio_leds_probe(struct of_device *ofdev,
 					const struct of_device_id *match)
 {
 	struct device_node *np = ofdev->node, *child;
-	struct gpio_led led;
 	struct gpio_led_of_platform_data *pdata;
 	int count = 0, ret;
 
@@ -226,8 +225,8 @@  static int __devinit of_gpio_leds_probe(struct of_device *ofdev,
 	if (!pdata)
 		return -ENOMEM;
 
-	memset(&led, 0, sizeof(led));
 	for_each_child_of_node(np, child) {
+		struct gpio_led led = {};
 		enum of_gpio_flags flags;
 		const char *state;