Skip to contentSkip to conversation

leds-gpio: Fix default state handling on OF platforms

PATCH In review Anton Vorontsov 3 participants 4 messages Feb 5, 2010 – Feb 15, 2010 LED

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 leds-gpio: Fix default state handling on OF platforms

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.

---
 drivers/leds/leds-gpio.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/leds/leds-gpio.c +1 -2
index e5225d2..0823e26 100644
@@ -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;
 
Signature · 1 line
1.6.5.7
#1 lore raw
Quoted 16 lines · On Fri, 5 Feb 2010 23:54:37 +0300 Anton Vorontsov <[email protected]>…

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, ...);
}
Quoted 2 lines

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 :(

#2 lore raw
Quoted 5 lines · Andrew Morton
Quoted 2 lines · On Fri, 5 Feb 2010 23:54:37 +0300 Anton Vorontsov <[email protected]>…

The driver wrongly sets default state for LEDs that don't specify default-state property.

[...]

Quoted 1 line

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

Quoted 3 lines

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!

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
Acked-by on v1 1/1
#3 lore raw
In reply to Anton Vorontsov
Quoted 11 lines · Anton Vorontsov

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) {
=A0 =A0 =A0 =A0state =3D of_get_property(child, "default-state", NULL); =A0 =A0 =A0 =A0if (state) {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (!strcmp(state, "keep"))
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0led.default_state =3D LEDS=

_GPIO_DEFSTATE_KEEP;

Quoted 5 lines

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0...
=A0 =A0 =A0 =A0}
=A0 =A0 =A0 =A0ret =3D create_gpio_led(&led, ...); }

Quoted 7 lines

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.

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

g.

drivers/leds/leds-gpio.c static int __devinit of_gpio_leds_probe(struct of_dev=

Quoted 9 lines

---
=A0drivers/leds/leds-gpio.c | =A0 =A03 +-- =A01 files changed, 1 insertions(+), 2 deletions(-)

drivers/leds/leds-gpio.c +0 -0
index e5225d2..0823e26 100644
@@ -211,7 +211,6 @@ static int __devinit of_gpio_leds_probe(struct of_dev=

ice *ofdev,

Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =

=A0 =A0const struct of_device_id *match)

drivers/leds/leds-gpio.c static int __devinit of_gpio_leds_probe(struct of_dev=

Quoted 7 lines

=A0{
=A0 =A0 =A0 =A0struct device_node *np =3D ofdev->node, *child;
- =A0 =A0 =A0 struct gpio_led led;
=A0 =A0 =A0 =A0struct gpio_led_of_platform_data *pdata; =A0 =A0 =A0 =A0int count =3D 0, ret;

drivers/leds/leds-gpio.c +0 -0
@@ -226,8 +225,8 @@ static int __devinit of_gpio_leds_probe(struct of_dev=

ice *ofdev,

Quoted 10 lines
drivers/leds/leds-gpio.c +1 -2
 =A0 =A0 =A0 =A0if (!pdata)
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return -ENOMEM;
 
- =A0 =A0 =A0 memset(&led, 0, sizeof(led));
 =A0 =A0 =A0 =A0for_each_child_of_node(np, child) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct gpio_led led =3D {};
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0enum of_gpio_flags flags;
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0const char *state;
 
--
Quoted 3 lines

1.6.5.7
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" i=

n

Quoted 4 lines

the body of a message to [email protected]
More majordomo info at =A0http://vger.kernel.org/majordomo-info.html Please read the FAQ at =A0http://www.tux.org/lkml/

--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.