All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] leds: lp5860: Return an error for an out-of-range 'reg' property
@ 2026-06-12 20:16 Mert Seftali
  2026-06-18 11:55 ` Lee Jones
  0 siblings, 1 reply; 3+ messages in thread
From: Mert Seftali @ 2026-06-12 20:16 UTC (permalink / raw)
  To: Lee Jones, Pavel Machek
  Cc: Steffen Trumtrar, Dan Carpenter, linux-leds, linux-kernel,
	Mert Seftali, kernel test robot

When fwnode_property_read_u32() succeeds but the channel number exceeds
LP5860_MAX_LED, ret is 0. The error path then passes 0 to dev_err_probe()
and returns 0, so an out-of-range "reg" value is silently treated as
success instead of being rejected.

Set ret to -EINVAL in that case so the invalid channel is reported and
propagated as an error.

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>
---
 drivers/leds/rgb/leds-lp5860-core.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/leds/rgb/leds-lp5860-core.c b/drivers/leds/rgb/leds-lp5860-core.c
index fd0e2f6e6e0f..9eeb01b3e56a 100644
--- a/drivers/leds/rgb/leds-lp5860-core.c
+++ b/drivers/leds/rgb/leds-lp5860-core.c
@@ -115,6 +115,8 @@ 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 >= 0)
+				ret = -EINVAL;
 			dev_err_probe(led->chip->dev, ret,
 				      "%pfwP: 'reg' property is missing. Skipping.\n", led_node);
 			fwnode_handle_put(led_node);
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] leds: lp5860: Return an error for an out-of-range 'reg' property
  2026-06-12 20:16 [PATCH] leds: lp5860: Return an error for an out-of-range 'reg' property Mert Seftali
@ 2026-06-18 11:55 ` Lee Jones
  2026-06-18 14:25   ` Mert Seftali
  0 siblings, 1 reply; 3+ messages in thread
From: Lee Jones @ 2026-06-18 11:55 UTC (permalink / raw)
  To: Mert Seftali
  Cc: Pavel Machek, Steffen Trumtrar, Dan Carpenter, linux-leds,
	linux-kernel, kernel test robot

On Fri, 12 Jun 2026, Mert Seftali wrote:

> When fwnode_property_read_u32() succeeds but the channel number exceeds
> LP5860_MAX_LED, ret is 0. The error path then passes 0 to dev_err_probe()
> and returns 0, so an out-of-range "reg" value is silently treated as
> success instead of being rejected.
> 
> Set ret to -EINVAL in that case so the invalid channel is reported and
> propagated as an error.
> 
> 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>
> ---
>  drivers/leds/rgb/leds-lp5860-core.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/leds/rgb/leds-lp5860-core.c b/drivers/leds/rgb/leds-lp5860-core.c
> index fd0e2f6e6e0f..9eeb01b3e56a 100644
> --- a/drivers/leds/rgb/leds-lp5860-core.c
> +++ b/drivers/leds/rgb/leds-lp5860-core.c
> @@ -115,6 +115,8 @@ 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) {

Whilst we're hear, let's split this out.  If 'fwnode_property_read_u32()'
fails, 'channel' is not populated.  While short-circuit evaluation protects
us here, separating the error paths would allow us to use the preferred
'if (ret)' check instead of 'if (ret < 0)'.  It would also let us provide a
more accurate error message, as 'reg' is not missing when it is simply out of
range.

> +			if (ret >= 0)
> +				ret = -EINVAL;

Avoid this nested check entirely by assigning 'ret = -EINVAL' directly
within a separate block for the out-of-range check.  This would keep the
flow a bit cleaner and easier to follow.

>  			dev_err_probe(led->chip->dev, ret,
>  				      "%pfwP: 'reg' property is missing. Skipping.\n", led_node);
>  			fwnode_handle_put(led_node);
> -- 
> 2.54.0
> 

-- 
Lee Jones

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] leds: lp5860: Return an error for an out-of-range 'reg' property
  2026-06-18 11:55 ` Lee Jones
@ 2026-06-18 14:25   ` Mert Seftali
  0 siblings, 0 replies; 3+ messages in thread
From: Mert Seftali @ 2026-06-18 14:25 UTC (permalink / raw)
  To: Lee Jones
  Cc: Pavel Machek, Steffen Trumtrar, Dan Carpenter, linux-leds,
	linux-kernel, kernel test robot

Hello Mr. Jones,

Thanks, that's clearer. Did it as two checks in v2: if (ret) for the
read failure, then a separate block that returns -EINVAL when the
channel is out of range, each with its own message. Dropped the nested
if (ret >= 0).

Mert


Am Do., 18. Juni 2026 um 13:55 Uhr schrieb Lee Jones <lee@kernel.org>:
>
> On Fri, 12 Jun 2026, Mert Seftali wrote:
>
> > When fwnode_property_read_u32() succeeds but the channel number exceeds
> > LP5860_MAX_LED, ret is 0. The error path then passes 0 to dev_err_probe()
> > and returns 0, so an out-of-range "reg" value is silently treated as
> > success instead of being rejected.
> >
> > Set ret to -EINVAL in that case so the invalid channel is reported and
> > propagated as an error.
> >
> > 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>
> > ---
> >  drivers/leds/rgb/leds-lp5860-core.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/leds/rgb/leds-lp5860-core.c b/drivers/leds/rgb/leds-lp5860-core.c
> > index fd0e2f6e6e0f..9eeb01b3e56a 100644
> > --- a/drivers/leds/rgb/leds-lp5860-core.c
> > +++ b/drivers/leds/rgb/leds-lp5860-core.c
> > @@ -115,6 +115,8 @@ 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) {
>
> Whilst we're hear, let's split this out.  If 'fwnode_property_read_u32()'
> fails, 'channel' is not populated.  While short-circuit evaluation protects
> us here, separating the error paths would allow us to use the preferred
> 'if (ret)' check instead of 'if (ret < 0)'.  It would also let us provide a
> more accurate error message, as 'reg' is not missing when it is simply out of
> range.
>
> > +                     if (ret >= 0)
> > +                             ret = -EINVAL;
>
> Avoid this nested check entirely by assigning 'ret = -EINVAL' directly
> within a separate block for the out-of-range check.  This would keep the
> flow a bit cleaner and easier to follow.
>
> >                       dev_err_probe(led->chip->dev, ret,
> >                                     "%pfwP: 'reg' property is missing. Skipping.\n", led_node);
> >                       fwnode_handle_put(led_node);
> > --
> > 2.54.0
> >
>
> --
> Lee Jones

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-06-18 14:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-12 20:16 [PATCH] leds: lp5860: Return an error for an out-of-range 'reg' property Mert Seftali
2026-06-18 11:55 ` Lee Jones
2026-06-18 14:25   ` Mert Seftali

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.