Skip to content

Commit 7452f8a

Browse files
Zicheng Qujic23
authored andcommitted
iio: gts: fix infinite loop for gain_to_scaletables()
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]>
1 parent e2fb2f8 commit 7452f8a

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)