Skip to content

Commit 369f056

Browse files
Jinjie Ruanjic23
authored andcommitted
iio: gts-helper: Fix memory leaks for the error path of iio_gts_build_avail_scale_table()
If per_time_scales[i] or per_time_gains[i] kcalloc fails in the for loop of iio_gts_build_avail_scale_table(), the err_free_out will fail to call kfree() each time when i is reduced to 0, so all the per_time_scales[0] and per_time_gains[0] will not be freed, which will cause memory leaks. Fix it by checking if i >= 0. Cc: [email protected] Fixes: 38416c2 ("iio: light: Add gain-time-scale helpers") Reviewed-by: Matti Vaittinen <[email protected]> Signed-off-by: Jinjie Ruan <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 691e79f commit 369f056

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
@@ -315,7 +315,7 @@ static int iio_gts_build_avail_scale_table(struct iio_gts *gts)
315315
return 0;
316316

317317
err_free_out:
318-
for (i--; i; i--) {
318+
for (i--; i >= 0; i--) {
319319
kfree(per_time_scales[i]);
320320
kfree(per_time_gains[i]);
321321
}

0 commit comments

Comments
 (0)