Skip to contentSkip to conversation

leds: pwm: clear the led structure before parsing each child node

PATCH Applied Hui Wang 2 participants 2 messages Dec 20, 2022 – Jan 4, 2023 LED

lore
Share & tools
lore

Hui Wang

author
#0 lore raw

PATCH 1/1 leds: pwm: clear the led structure before parsing each child node

I defined 2 leds in the device tree, in the 1st led node, the max-brightness is set to 248, while in the 2nd led node, I mis-spelled the max-brightness to max-brighttness, but the driver is still able to get the max-brightness 248 for the 2nd node, that is because the led structure is not cleared before parsing each child node.

	pwmleds {
		compatible = "pwm-leds";

		pwm-green {
			...
			max-brightness = <248>;
		};

		pwm-red {
		        ...
			max-brighttness = <128>;
		};
---
 drivers/leds/leds-pwm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/leds/leds-pwm.c +2 -2
index 6832180c1c54..29194cc382af 100644
@@ -138,9 +138,9 @@ static int led_pwm_create_fwnode(struct device *dev, struct led_pwm_priv *priv)
 	struct led_pwm led;
 	int ret;
 
-	memset(&led, 0, sizeof(led));
-
 	device_for_each_child_node(dev, fwnode) {
+		memset(&led, 0, sizeof(led));
+
 		ret = fwnode_property_read_string(fwnode, "label", &led.name);
 		if (ret && is_of_node(fwnode))
 			led.name = to_of_node(fwnode)->name;
Signature · 1 line
2.34.1
maintainer Applied
#1 lore raw
Quoted 20 lines · Hui Wang

I defined 2 leds in the device tree, in the 1st led node, the max-brightness is set to 248, while in the 2nd led node, I mis-spelled the max-brightness to max-brighttness, but the driver is still able to get the max-brightness 248 for the 2nd node, that is because the led structure is not cleared before parsing each child node.

	pwmleds {
		compatible = "pwm-leds";

		pwm-green {
			...
			max-brightness = <248>;
		};

		pwm-red {
		        ...
			max-brighttness = <128>;
		};
Quoted 4 lines
---
 drivers/leds/leds-pwm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Applied, thanks

Signature · 1 line
Lee Jones [李琼斯]