Skip to content

Commit 28a2e04

Browse files
committed
leds: qcom-lpg: Check for array overflow when selecting the high resolution
commit d45963a upstream. When selecting the high resolution values from the array, FIELD_GET() is used to pull from a 3 bit register, yet the array being indexed has only 5 values in it. Odds are the hardware is sane, but just to be safe, properly check before just overflowing and reading random data and then setting up chip values based on that. Cc: stable <stable@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Link: https://patch.msgid.link/2026021934-nearby-playroom-036b@gregkh Signed-off-by: Lee Jones <lee@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fa297e9 commit 28a2e04

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

drivers/leds/rgb/leds-qcom-lpg.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,12 @@ static int lpg_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
10431043
return ret;
10441044

10451045
if (chan->subtype == LPG_SUBTYPE_HI_RES_PWM) {
1046-
refclk = lpg_clk_rates_hi_res[FIELD_GET(PWM_CLK_SELECT_HI_RES_MASK, val)];
1046+
unsigned int clk_idx = FIELD_GET(PWM_CLK_SELECT_HI_RES_MASK, val);
1047+
1048+
if (clk_idx >= ARRAY_SIZE(lpg_clk_rates_hi_res))
1049+
return -EINVAL;
1050+
1051+
refclk = lpg_clk_rates_hi_res[clk_idx];
10471052
resolution = lpg_pwm_resolution_hi_res[FIELD_GET(PWM_SIZE_HI_RES_MASK, val)];
10481053
} else {
10491054
refclk = lpg_clk_rates[FIELD_GET(PWM_CLK_SELECT_MASK, val)];

0 commit comments

Comments
 (0)