Linux LED subsystem development
 help / color / mirror / Atom feed
* [PATCH v2] leds: lp5860: Return an error for an out-of-range 'reg' property
@ 2026-06-18 14:21 Mert Seftali
  0 siblings, 0 replies; only message in thread
From: Mert Seftali @ 2026-06-18 14:21 UTC (permalink / raw)
  To: Lee Jones, Pavel Machek
  Cc: Steffen Trumtrar, linux-leds, linux-kernel, Mert Seftali,
	kernel test robot, Dan Carpenter

lp5860_iterate_subleds() checks the result of reading the "reg" property
and the channel range in a single condition:

	if (ret < 0 || channel > LP5860_MAX_LED)

When fwnode_property_read_u32() succeeds but the channel is out of range,
ret is 0, so the error path passes 0 to dev_err_probe() and returns 0 -
an out-of-range "reg" is silently accepted instead of rejected. The
shared "'reg' property is missing" message is also inaccurate when the
property is present but out of range.

Split the two cases: report a read failure with if (ret), and reject an
out-of-range channel with -EINVAL. Each case now has its own accurate
error message.

Fixes: 3daf2c4ef82b ("leds: Add support for TI LP5860 LED driver chip")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <error27@gmail.com>
Closes: https://lore.kernel.org/r/202605210624.3gcr3prk-lkp@intel.com/
Signed-off-by: Mert Seftali <mertsftl@gmail.com>
---
Changes in v2 (per Lee Jones review):
- Split the combined read/range test into separate checks: use if(ret)
  for the read failure, and reject an out-of-range channel with -EINVAL.
- Give each case its own accurate message instead of the shared
  "missing" one, and drop the nested "if (ret >= 0)".

 drivers/leds/rgb/leds-lp5860-core.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/rgb/leds-lp5860-core.c b/drivers/leds/rgb/leds-lp5860-core.c
index fd0e2f6e6e0f..bc59be87b08f 100644
--- a/drivers/leds/rgb/leds-lp5860-core.c
+++ b/drivers/leds/rgb/leds-lp5860-core.c
@@ -114,13 +114,21 @@ 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) {
+		if (ret) {
 			dev_err_probe(led->chip->dev, ret,
-				      "%pfwP: 'reg' property is missing. Skipping.\n", led_node);
+				      "%pfwP: Cannot read 'reg' property. Skipping.\n", led_node);
 			fwnode_handle_put(led_node);
 			return ret;
 		}
 
+		if (channel > LP5860_MAX_LED) {
+			dev_err_probe(led->chip->dev, -EINVAL,
+				      "%pfwP: 'reg' %u is out of range. Skipping.\n",
+				      led_node, channel);
+			fwnode_handle_put(led_node);
+			return -EINVAL;
+		}
+
 		led->mc_cdev.subled_info[subled].color_index = color_index;
 		led->mc_cdev.subled_info[subled].channel = channel;
 		ret = lp5860_led_init(led, init_data->fwnode, channel);
-- 
2.54.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-06-18 14:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-18 14:21 [PATCH v2] leds: lp5860: Return an error for an out-of-range 'reg' property Mert Seftali

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox