Skip to content

Commit 2e84a5e

Browse files
Johan Adolfssonlag-linaro
authored andcommitted
leds: leds-lp50xx: Handle reg to get correct multi_index
mc_subled used for multi_index needs well defined array indexes, to guarantee the desired result, use reg for that. If devicetree child nodes is processed in random or reverse order you may end up with multi_index "blue green red" instead of the expected "red green blue". If user space apps uses multi_index to deduce how to control the leds they would most likely be broken without this patch if devicetree processing is reversed (which it appears to be). arch/arm/boot/dts/aspeed/aspeed-bmc-facebook-fuji.dts has reg set but I don't see how it can have worked without this change. If reg is not set, an error is returned, If reg is out of range, an error is returned. reg within led child nodes starts with 0, to map to the iout in each bank. Signed-off-by: Johan Adolfsson <[email protected]> Reviewed-by: Jacek Anaszewski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lee Jones <[email protected]>
1 parent 6012ce6 commit 2e84a5e

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

drivers/leds/leds-lp50xx.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,15 +476,24 @@ static int lp50xx_probe_dt(struct lp50xx *priv)
476476
return -ENOMEM;
477477

478478
fwnode_for_each_child_node(child, led_node) {
479+
int multi_index;
479480
ret = fwnode_property_read_u32(led_node, "color",
480481
&color_id);
481482
if (ret) {
482483
fwnode_handle_put(led_node);
483484
dev_err(priv->dev, "Cannot read color\n");
484485
return ret;
485486
}
487+
ret = fwnode_property_read_u32(led_node, "reg", &multi_index);
488+
if (ret != 0) {
489+
dev_err(priv->dev, "reg must be set\n");
490+
return -EINVAL;
491+
} else if (multi_index >= LP50XX_LEDS_PER_MODULE) {
492+
dev_err(priv->dev, "reg %i out of range\n", multi_index);
493+
return -EINVAL;
494+
}
486495

487-
mc_led_info[num_colors].color_index = color_id;
496+
mc_led_info[multi_index].color_index = color_id;
488497
num_colors++;
489498
}
490499

0 commit comments

Comments
 (0)