mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 10:00:17 +00:00
iio: gts-helper: Fix memory leaks for the error path of iio_gts_build_avail_scale_table()
commit369f056889upstream. 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: stable@vger.kernel.org Fixes:38416c28e1("iio: light: Add gain-time-scale helpers") Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> Link: https://patch.msgid.link/20241016012453.2013302-1-ruanjinjie@huawei.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
0ac0beb423
commit
b304362ce8
@@ -313,7 +313,7 @@ static int iio_gts_build_avail_scale_table(struct iio_gts *gts)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_free_out:
|
err_free_out:
|
||||||
for (i--; i; i--) {
|
for (i--; i >= 0; i--) {
|
||||||
kfree(per_time_scales[i]);
|
kfree(per_time_scales[i]);
|
||||||
kfree(per_time_gains[i]);
|
kfree(per_time_gains[i]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user