* [PATCH] staging: media: atomisp: fix memory leak of dvs2_coeff
@ 2026-04-16 6:41 Huihui Huang
2026-04-16 8:08 ` Andy Shevchenko
2026-04-16 13:16 ` [PATCH v2] " Huihui Huang
0 siblings, 2 replies; 4+ messages in thread
From: Huihui Huang @ 2026-04-16 6:41 UTC (permalink / raw)
To: Hans de Goede, Mauro Carvalho Chehab, Andy Shevchenko
Cc: Sakari Ailus, Greg Kroah-Hartman, linux-media, linux-staging,
linux-kernel, Huihui Huang
Our code analyzer reported a memory leak in
drivers/staging/media/atomisp/pci/atomisp_compat_css20.c.
In atomisp_alloc_dis_coef_buf(), dvs2_coeff is allocated by
ia_css_dvs2_coefficients_allocate() and stored in
asd->params.css_param.dvs2_coeff. If the subsequent
ia_css_dvs2_statistics_allocate() for dvs_stat fails, the function
returns -ENOMEM without freeing the previously allocated dvs2_coeff.
My patch adds the missing ia_css_dvs2_coefficients_free() call and
sets the pointer to NULL before returning on the error path.
Signed-off-by: Huihui Huang <hhhuang@smu.edu.sg>
---
drivers/staging/media/atomisp/pci/atomisp_compat_css20.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/media/atomisp/pci/atomisp_compat_css20.c b/drivers/staging/media/atomisp/pci/atomisp_compat_css20.c
index be5f37f4a..d3dc84e14 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_compat_css20.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_compat_css20.c
@@ -1363,8 +1363,11 @@ int atomisp_alloc_dis_coef_buf(struct atomisp_sub_device *asd)
/* DIS projections. */
asd->params.dis_proj_data_valid = false;
asd->params.dvs_stat = ia_css_dvs2_statistics_allocate(dvs_grid);
- if (!asd->params.dvs_stat)
+ if (!asd->params.dvs_stat) {
+ ia_css_dvs2_coefficients_free(asd->params.css_param.dvs2_coeff);
+ asd->params.css_param.dvs2_coeff = NULL;
return -ENOMEM;
+ }
asd->params.dvs_hor_proj_bytes =
dvs_grid->aligned_height * dvs_grid->aligned_width *
--
2.50.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] staging: media: atomisp: fix memory leak of dvs2_coeff
2026-04-16 6:41 [PATCH] staging: media: atomisp: fix memory leak of dvs2_coeff Huihui Huang
@ 2026-04-16 8:08 ` Andy Shevchenko
2026-04-16 13:16 ` [PATCH v2] " Huihui Huang
1 sibling, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2026-04-16 8:08 UTC (permalink / raw)
To: Huihui Huang
Cc: Hans de Goede, Mauro Carvalho Chehab, Andy Shevchenko,
Sakari Ailus, Greg Kroah-Hartman, linux-media, linux-staging,
linux-kernel
On Thu, Apr 16, 2026 at 02:41:52PM +0800, Huihui Huang wrote:
> Our code analyzer reported a memory leak in
> drivers/staging/media/atomisp/pci/atomisp_compat_css20.c.
>
> In atomisp_alloc_dis_coef_buf(), dvs2_coeff is allocated by
> ia_css_dvs2_coefficients_allocate() and stored in
> asd->params.css_param.dvs2_coeff. If the subsequent
> ia_css_dvs2_statistics_allocate() for dvs_stat fails, the function
> returns -ENOMEM without freeing the previously allocated dvs2_coeff.
> My patch adds the missing ia_css_dvs2_coefficients_free() call and
> sets the pointer to NULL before returning on the error path.
Please, read Submitting Patches (find "imperative mood" there).
...
The code looks okay, though.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] staging: media: atomisp: fix memory leak of dvs2_coeff
2026-04-16 6:41 [PATCH] staging: media: atomisp: fix memory leak of dvs2_coeff Huihui Huang
2026-04-16 8:08 ` Andy Shevchenko
@ 2026-04-16 13:16 ` Huihui Huang
2026-04-16 18:32 ` Andy Shevchenko
1 sibling, 1 reply; 4+ messages in thread
From: Huihui Huang @ 2026-04-16 13:16 UTC (permalink / raw)
To: Hans de Goede, Mauro Carvalho Chehab, Andy Shevchenko
Cc: Sakari Ailus, Greg Kroah-Hartman, linux-media, linux-staging,
linux-kernel, Huihui Huang
There is a memory leak in
drivers/staging/media/atomisp/pci/atomisp_compat_css20.c.
In atomisp_alloc_dis_coef_buf(), dvs2_coeff is allocated by
ia_css_dvs2_coefficients_allocate() and stored in
asd->params.css_param.dvs2_coeff. If the subsequent
ia_css_dvs2_statistics_allocate() for dvs_stat fails, the function
returns -ENOMEM without freeing the previously allocated dvs2_coeff.
Add the missing ia_css_dvs2_coefficients_free() call and set the
pointer to NULL before returning on the error path.
Signed-off-by: Huihui Huang <hhhuang@smu.edu.sg>
---
v2: Reword commit message per review feedback (no code change).
---
drivers/staging/media/atomisp/pci/atomisp_compat_css20.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/media/atomisp/pci/atomisp_compat_css20.c b/drivers/staging/media/atomisp/pci/atomisp_compat_css20.c
index be5f37f4a6fd..d3dc84e14877 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_compat_css20.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_compat_css20.c
@@ -1363,8 +1363,11 @@ int atomisp_alloc_dis_coef_buf(struct atomisp_sub_device *asd)
/* DIS projections. */
asd->params.dis_proj_data_valid = false;
asd->params.dvs_stat = ia_css_dvs2_statistics_allocate(dvs_grid);
- if (!asd->params.dvs_stat)
+ if (!asd->params.dvs_stat) {
+ ia_css_dvs2_coefficients_free(asd->params.css_param.dvs2_coeff);
+ asd->params.css_param.dvs2_coeff = NULL;
return -ENOMEM;
+ }
asd->params.dvs_hor_proj_bytes =
dvs_grid->aligned_height * dvs_grid->aligned_width *
--
2.50.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] staging: media: atomisp: fix memory leak of dvs2_coeff
2026-04-16 13:16 ` [PATCH v2] " Huihui Huang
@ 2026-04-16 18:32 ` Andy Shevchenko
0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2026-04-16 18:32 UTC (permalink / raw)
To: Huihui Huang
Cc: Hans de Goede, Mauro Carvalho Chehab, Andy Shevchenko,
Sakari Ailus, Greg Kroah-Hartman, linux-media, linux-staging,
linux-kernel
On Thu, Apr 16, 2026 at 09:16:26PM +0800, Huihui Huang wrote:
> There is a memory leak in
> drivers/staging/media/atomisp/pci/atomisp_compat_css20.c.
>
> In atomisp_alloc_dis_coef_buf(), dvs2_coeff is allocated by
> ia_css_dvs2_coefficients_allocate() and stored in
> asd->params.css_param.dvs2_coeff. If the subsequent
> ia_css_dvs2_statistics_allocate() for dvs_stat fails, the function
> returns -ENOMEM without freeing the previously allocated dvs2_coeff.
> Add the missing ia_css_dvs2_coefficients_free() call and set the
> pointer to NULL before returning on the error path.
Why do we need this?
...
> asd->params.dvs_stat = ia_css_dvs2_statistics_allocate(dvs_grid);
> - if (!asd->params.dvs_stat)
> + if (!asd->params.dvs_stat) {
> + ia_css_dvs2_coefficients_free(asd->params.css_param.dvs2_coeff);
> + asd->params.css_param.dvs2_coeff = NULL;
Actually same Q here: Do we need this NULLification?
> return -ENOMEM;
> + }
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-04-16 18:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-16 6:41 [PATCH] staging: media: atomisp: fix memory leak of dvs2_coeff Huihui Huang
2026-04-16 8:08 ` Andy Shevchenko
2026-04-16 13:16 ` [PATCH v2] " Huihui Huang
2026-04-16 18:32 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox