[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241014013144.576701-1-ruanjinjie@huawei.com>
Date: Mon, 14 Oct 2024 09:31:44 +0800
From: Jinjie Ruan <ruanjinjie@...wei.com>
To: <mazziesaccount@...il.com>, <jic23@...nel.org>, <lars@...afoo.de>,
<linux-iio@...r.kernel.org>, <linux-kernel@...r.kernel.org>
CC: <ruanjinjie@...wei.com>
Subject: [PATCH] iio: gts-helper: Fix memory leaks for i = 1 error path
If i = 1, and per_time_scales[i] or per_time_gains[i] kcalloc fails in
iio_gts_build_avail_scale_table(), the err_free_out will fail to enter
kfree for loop because i-- is 0, and 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@...r.kernel.org
Fixes: 38416c28e168 ("iio: light: Add gain-time-scale helpers")
Signed-off-by: Jinjie Ruan <ruanjinjie@...wei.com>
---
drivers/iio/industrialio-gts-helper.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/industrialio-gts-helper.c b/drivers/iio/industrialio-gts-helper.c
index 7326c7949244..5f131bc1a01e 100644
--- a/drivers/iio/industrialio-gts-helper.c
+++ b/drivers/iio/industrialio-gts-helper.c
@@ -315,7 +315,7 @@ static int iio_gts_build_avail_scale_table(struct iio_gts *gts)
return 0;
err_free_out:
- for (i--; i; i--) {
+ for (i--; i >= 0; i--) {
kfree(per_time_scales[i]);
kfree(per_time_gains[i]);
}
--
2.34.1
Powered by blists - more mailing lists