Skip to content

Commit 8ed1c68

Browse files
Zicheng QuWen Zhiwei
authored andcommitted
iio: gts: fix infinite loop for gain_to_scaletables()
stable inclusion from stable-v6.6.64 commit 1bdff8a19cd6f7ef76eba3e6739d0f1702d49f06 category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IBL4B6 Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=1bdff8a19cd6f7ef76eba3e6739d0f1702d49f06 -------------------------------- commit 7452f8a0814bb73f739ee0dab60f099f3361b151 upstream. In iio_gts_build_avail_time_table(), it is checked that gts->num_itime is non-zero, but gts->num_itime is not checked in gain_to_scaletables(). The variable time_idx is initialized as gts->num_itime - 1. This implies that time_idx might initially be set to -1 (0 - 1 = -1). Consequently, using while (time_idx--) could lead to an infinite loop. Cc: [email protected] # v6.6+ Fixes: 38416c2 ("iio: light: Add gain-time-scale helpers") Signed-off-by: Zicheng Qu <[email protected]> Reviewed-by: Matti Vaittinen <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jonathan Cameron <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Wen Zhiwei <[email protected]>
1 parent 14659c1 commit 8ed1c68

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/iio/industrialio-gts-helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ static int gain_to_scaletables(struct iio_gts *gts, int **gains, int **scales)
205205
memcpy(all_gains, gains[time_idx], gain_bytes);
206206
new_idx = gts->num_hwgain;
207207

208-
while (time_idx--) {
208+
while (time_idx-- > 0) {
209209
for (j = 0; j < gts->num_hwgain; j++) {
210210
int candidate = gains[time_idx][j];
211211
int chk;

0 commit comments

Comments
 (0)