]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
leds: leds-lp50xx: Handle reg to get correct multi_index
authorJohan Adolfsson <johan.adolfsson@axis.com>
Tue, 17 Jun 2025 10:23:54 +0000 (12:23 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 28 Aug 2025 14:22:45 +0000 (16:22 +0200)
[ Upstream commit 2e84a5e5374232e6f356ce5c079a5658d7e4af2c ]

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 <johan.adolfsson@axis.com>
Reviewed-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
Link: https://lore.kernel.org/r/20250617-led-fix-v7-1-cdbe8efc88fa@axis.com
Signed-off-by: Lee Jones <lee@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/leds/leds-lp50xx.c

index d4529082935b8a8d766bdb5e9225d05ee9e6ce61..279f3958e0ab5ae8e603bb09760f812d4a6eec68 100644 (file)
@@ -493,6 +493,7 @@ static int lp50xx_probe_dt(struct lp50xx *priv)
                }
 
                fwnode_for_each_child_node(child, led_node) {
+                       int multi_index;
                        ret = fwnode_property_read_u32(led_node, "color",
                                                       &color_id);
                        if (ret) {
@@ -500,8 +501,16 @@ static int lp50xx_probe_dt(struct lp50xx *priv)
                                dev_err(priv->dev, "Cannot read color\n");
                                goto child_out;
                        }
+                       ret = fwnode_property_read_u32(led_node, "reg", &multi_index);
+                       if (ret != 0) {
+                               dev_err(priv->dev, "reg must be set\n");
+                               return -EINVAL;
+                       } else if (multi_index >= LP50XX_LEDS_PER_MODULE) {
+                               dev_err(priv->dev, "reg %i out of range\n", multi_index);
+                               return -EINVAL;
+                       }
 
-                       mc_led_info[num_colors].color_index = color_id;
+                       mc_led_info[multi_index].color_index = color_id;
                        num_colors++;
                }