From: Matti Vaittinen <mazziesaccount@gmail.com>
To: Jinjie Ruan <ruanjinjie@huawei.com>,
jic23@kernel.org, lars@metafoo.de, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: gts-helper: Fix memory leaks for i = 1 error path
Date: Tue, 15 Oct 2024 12:03:40 +0300 [thread overview]
Message-ID: <76d96ab6-4e13-42b9-bff0-03a2e1b96f57@gmail.com> (raw)
In-Reply-To: <20241014013144.576701-1-ruanjinjie@huawei.com>
Thanks a lot Jinjie. I appreciate your fixes!
On 14/10/2024 04:31, Jinjie Ruan wrote:
> 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.
I guess the loop never frees the memory pointed by the first pointer in
these arrays. I mean, the freeing is not working as it should even if
the 'i' was something else but 1.
>
> Fix it by checking if i >= 0.
The fix seems good to me. So, with a tiny change in commit message:
Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>
>
> Cc: stable@vger.kernel.org
> Fixes: 38416c28e168 ("iio: light: Add gain-time-scale helpers")
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.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]);
> }
next prev parent reply other threads:[~2024-10-15 9:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-14 1:31 Jinjie Ruan
2024-10-15 9:03 ` Matti Vaittinen [this message]
2024-10-15 9:10 ` Jinjie Ruan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=76d96ab6-4e13-42b9-bff0-03a2e1b96f57@gmail.com \
--to=mazziesaccount@gmail.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ruanjinjie@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®