leds: lp5523: fix out-of-bounds bug in lp5523_selftest()
authorMaarten Zanders <maarten.zanders@mind.be>
Fri, 28 Oct 2022 10:56:43 +0000 (12:56 +0200)
committerPavel Machek <pavel@ucw.cz>
Fri, 28 Oct 2022 15:12:27 +0000 (17:12 +0200)
commit17c13c724b143c835fe3a9109daab524dff3d06f
tree9fb8e63338d2384b371251ad00c21fd9956e559c
parent5f52a8ba7e91215c3d046d298fb328d1b9f7897d
leds: lp5523: fix out-of-bounds bug in lp5523_selftest()

When not all LED channels of the led chip are configured, the
sysfs selftest functionality gives erroneous results and tries to
test all channels of the chip.
There is a potential for LED overcurrent conditions since the
test current will be set to values from out-of-bound regions.

It is wrong to use pdata->led_config[i].led_current to skip absent
channels as led_config[] only contains the configured LED channels.

Instead of iterating over all the physical channels of the device,
loop over the available LED configurations and use led->chan_nr to
access the correct i2c registers. Keep the zero-check for the LED
current as existing users might depend on this to disable a channel.

Reported-by: Arne Staessen <a.staessen@televic.com>
Signed-off-by: Maarten Zanders <maarten.zanders@mind.be>
Signed-off-by: Pavel Machek <pavel@ucw.cz>
drivers/leds/leds-lp5523.c