backlight: qcom-wled: Fix off-by-one maximum with default num_strings
authorMarijn Suijten <marijn.suijten@somainline.org>
Mon, 15 Nov 2021 20:34:54 +0000 (21:34 +0100)
committerLee Jones <lee.jones@linaro.org>
Wed, 22 Dec 2021 11:16:33 +0000 (11:16 +0000)
commit5ada78b26f935f8751852dffa24f6b545b1d2517
treeb54f780a4385c5f4103f917c6f96f1c6733ea05c
parent0a139358548968b2ff308257b4fbeec7badcc3e1
backlight: qcom-wled: Fix off-by-one maximum with default num_strings

When not specifying num-strings in the DT the default is used, but +1 is
added to it which turns WLED3 into 4 and WLED4/5 into 5 strings instead
of 3 and 4 respectively, causing out-of-bounds reads and register
read/writes.  This +1 exists for a deficiency in the DT parsing code,
and is simply omitted entirely - solving this oob issue - by parsing the
property separately much like qcom,enabled-strings.

This also enables more stringent checks on the maximum value when
qcom,enabled-strings is provided in the DT, by parsing num-strings after
enabled-strings to allow it to check against (and in a subsequent patch
override) the length of enabled-strings: it is invalid to set
num-strings higher than that.
The DT currently utilizes it to get around an incorrect fixed read of
four elements from that array (has been addressed in a prior patch) by
setting a lower num-strings where desired.

Fixes: 93c64f1ea1e8 ("leds: add Qualcomm PM8941 WLED driver")
Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org>
Reviewed-By: AngeloGioacchino Del Regno <angelogioacchino.delregno@somainline.org>
Reviewed-by: Daniel Thompson <daniel.thompson@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Link: https://lore.kernel.org/r/20211115203459.1634079-5-marijn.suijten@somainline.org
drivers/video/backlight/qcom-wled.c