[PATCH v5 1/4] leds: rgb: lp5860: Fix off-by-one bounds checks for LED channels
From: Peter LaDow via B4 Relay
Date: Fri Dec 04 2026 - 09:40:48 EST
From: Peter LaDow <pladow@xxxxxxxxx>
Valid LP5860 dot indices and LED channel numbers are 0-indexed up to
LP5860_MAX_LED - 1 (197). Using '>' instead of '>=' allows an
out-of-bounds value equal to LP5860_MAX_LED to pass validation.
Additionally, in lp5860_iterate_subleds(), when fwnode_property_read_u32()
succeeds with an out-of-range channel, 'ret' is 0, causing the error
path to log and return 0 (success) while leaving the subled entry
uninitialized.
Change both bounds checks to '>=' and separate the out-of-range channel
check so it logs and returns -EINVAL.
Fixes: f0a66563aa2d ("leds: Add support for TI LP5860 LED driver chip")
Signed-off-by: Peter LaDow <pladow@xxxxxxxxx>
---
drivers/leds/rgb/leds-lp5860-core.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/drivers/leds/rgb/leds-lp5860-core.c b/drivers/leds/rgb/leds-lp5860-core.c
index e21d5f2302be..0ad99d11dfdf 100644
--- a/drivers/leds/rgb/leds-lp5860-core.c
+++ b/drivers/leds/rgb/leds-lp5860-core.c
@@ -24,7 +24,7 @@ static int lp5860_set_dot_onoff(struct lp5860_led *led, unsigned int dot, bool e
unsigned int offset = dot / LP5860_MAX_DOT_ONOFF_GROUP_NUM;
unsigned int mask = BIT(dot % LP5860_MAX_DOT_ONOFF_GROUP_NUM);
- if (dot > LP5860_MAX_LED)
+ if (dot >= LP5860_MAX_LED)
return -EINVAL;
return regmap_update_bits(led->chip->regmap,
@@ -114,11 +114,18 @@ static int lp5860_iterate_subleds(struct lp5860_led *led, struct led_init_data *
}
ret = fwnode_property_read_u32(led_node, "reg", &channel);
- if (ret < 0 || channel > LP5860_MAX_LED) {
- dev_err_probe(led->chip->dev, ret,
- "%pfwP: 'reg' property is missing. Skipping.\n", led_node);
+ if (ret < 0) {
fwnode_handle_put(led_node);
- return ret;
+ return dev_err_probe(led->chip->dev, ret,
+ "%pfwP: 'reg' property is missing. Skipping.\n",
+ led_node);
+ }
+
+ if (channel >= LP5860_MAX_LED) {
+ fwnode_handle_put(led_node);
+ return dev_err_probe(led->chip->dev, -EINVAL,
+ "%pfwP: invalid 'reg' channel %u\n",
+ led_node, channel);
}
led->mc_cdev.subled_info[subled].color_index = color_index;
--
2.43.0