* [PATCH] iio: fix memory leak for iio_gts_build_avail_scale_table()
@ 2024-10-31 1:47 Zicheng Qu
2024-10-31 7:32 ` Matti Vaittinen
0 siblings, 1 reply; 3+ messages in thread
From: Zicheng Qu @ 2024-10-31 1:47 UTC (permalink / raw)
To: mazziesaccount, jic23, lars, linux-iio, linux-kernel
Cc: tanghui20, zhangqiao22, judy.chenhui, quzicheng
In iio_gts_build_avail_scale_table(), the memory allocated for
per_time_gains is freed using kfree(per_time_gains) before return 0.
However, the type per_time_gains is 'int **', and the memory allocated
for its inner elements is not being freed, leading to a memory leak.
Cc: stable@vger.kernel.org # v6.6+
Fixes: 38416c28e168 ("iio: light: Add gain-time-scale helpers")
Signed-off-by: Zicheng Qu <quzicheng@huawei.com>
---
drivers/iio/industrialio-gts-helper.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/iio/industrialio-gts-helper.c b/drivers/iio/industrialio-gts-helper.c
index 59d7615c0f56..f2450b2e740d 100644
--- a/drivers/iio/industrialio-gts-helper.c
+++ b/drivers/iio/industrialio-gts-helper.c
@@ -307,6 +307,8 @@ static int iio_gts_build_avail_scale_table(struct iio_gts *gts)
if (ret)
goto err_free_out;
+ for (j = 0; j < gts->num_itime; j++)
+ kfree(per_time_gains[i]);
kfree(per_time_gains);
gts->per_time_avail_scale_tables = per_time_scales;
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: fix memory leak for iio_gts_build_avail_scale_table()
2024-10-31 1:47 [PATCH] iio: fix memory leak for iio_gts_build_avail_scale_table() Zicheng Qu
@ 2024-10-31 7:32 ` Matti Vaittinen
2024-11-01 3:49 ` Zicheng Qu
0 siblings, 1 reply; 3+ messages in thread
From: Matti Vaittinen @ 2024-10-31 7:32 UTC (permalink / raw)
To: Zicheng Qu, jic23, lars, linux-iio, linux-kernel
Cc: tanghui20, zhangqiao22, judy.chenhui
Hi Zicheng
On 31/10/2024 03:47, Zicheng Qu wrote:
> In iio_gts_build_avail_scale_table(), the memory allocated for
> per_time_gains is freed using kfree(per_time_gains) before return 0.
> However, the type per_time_gains is 'int **', and the memory allocated
> for its inner elements is not being freed, leading to a memory leak.
>
> Cc: stable@vger.kernel.org # v6.6+
> Fixes: 38416c28e168 ("iio: light: Add gain-time-scale helpers")
> Signed-off-by: Zicheng Qu <quzicheng@huawei.com>
> ---
> drivers/iio/industrialio-gts-helper.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/iio/industrialio-gts-helper.c b/drivers/iio/industrialio-gts-helper.c
> index 59d7615c0f56..f2450b2e740d 100644
> --- a/drivers/iio/industrialio-gts-helper.c
> +++ b/drivers/iio/industrialio-gts-helper.c
> @@ -307,6 +307,8 @@ static int iio_gts_build_avail_scale_table(struct iio_gts *gts)
> if (ret)
> goto err_free_out;
>
> + for (j = 0; j < gts->num_itime; j++)
> + kfree(per_time_gains[i]);
> kfree(per_time_gains);
> gts->per_time_avail_scale_tables = per_time_scales;
>
You're right, thanks!
This, however, was already fixed by:
https://lore.kernel.org/all/20241011095512.3667549-1-ruanjinjie@huawei.com/
Out of the curiosity (and no need to respond if you don't feel like) -
are you using the gts helpers in some of your project(s)? I am glad
seeing these fixes coming in and just wondered if all these bugs are
found because these helpers are being used outside the ROHM drivers :)
Yours,
-- Matti
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: fix memory leak for iio_gts_build_avail_scale_table()
2024-10-31 7:32 ` Matti Vaittinen
@ 2024-11-01 3:49 ` Zicheng Qu
0 siblings, 0 replies; 3+ messages in thread
From: Zicheng Qu @ 2024-11-01 3:49 UTC (permalink / raw)
To: Matti Vaittinen, linux-iio, linux-kernel
Cc: tanghui20, zhangqiao22, judy.chenhui
Hi Matti,
Thank you for your concern! I haven't used it in my projects yet. I came
across this issue while using smatch for code analysis. After reviewing
the code, I noticed a few minor issues. However, I did not realize that
the patch for the memory leak has already been submitted couple of days
ago. Apologies for not checking the patches thoroughly and submitting a
duplicate.
Yours,
-- Zicheng
On 2024/10/31 15:32, Matti Vaittinen wrote:
> Hi Zicheng
>
> On 31/10/2024 03:47, Zicheng Qu wrote:
>> In iio_gts_build_avail_scale_table(), the memory allocated for
>> per_time_gains is freed using kfree(per_time_gains) before return 0.
>> However, the type per_time_gains is 'int **', and the memory allocated
>> for its inner elements is not being freed, leading to a memory leak.
>>
>> Cc: stable@vger.kernel.org # v6.6+
>> Fixes: 38416c28e168 ("iio: light: Add gain-time-scale helpers")
>> Signed-off-by: Zicheng Qu <quzicheng@huawei.com>
>> ---
>> drivers/iio/industrialio-gts-helper.c | 2 ++
>> 1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/iio/industrialio-gts-helper.c
>> b/drivers/iio/industrialio-gts-helper.c
>> index 59d7615c0f56..f2450b2e740d 100644
>> --- a/drivers/iio/industrialio-gts-helper.c
>> +++ b/drivers/iio/industrialio-gts-helper.c
>> @@ -307,6 +307,8 @@ static int iio_gts_build_avail_scale_table(struct
>> iio_gts *gts)
>> if (ret)
>> goto err_free_out;
>> + for (j = 0; j < gts->num_itime; j++)
>> + kfree(per_time_gains[i]);
>> kfree(per_time_gains);
>> gts->per_time_avail_scale_tables = per_time_scales;
>
> You're right, thanks!
> This, however, was already fixed by:
> https://lore.kernel.org/all/20241011095512.3667549-1-ruanjinjie@huawei.com/
>
>
> Out of the curiosity (and no need to respond if you don't feel like) -
> are you using the gts helpers in some of your project(s)? I am glad
> seeing these fixes coming in and just wondered if all these bugs are
> found because these helpers are being used outside the ROHM drivers :)
>
> Yours,
> -- Matti
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-11-01 3:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-31 1:47 [PATCH] iio: fix memory leak for iio_gts_build_avail_scale_table() Zicheng Qu
2024-10-31 7:32 ` Matti Vaittinen
2024-11-01 3:49 ` Zicheng Qu
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®