Skip to contentSkip to conversation

media: atomisp: replace kmalloc() with kmalloc_objs() in sh_css.c

PATCH In review Andrei Khomenkov 3 participants 4 messages Jun 15 – Jun 17

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 media: atomisp: replace kmalloc() with kmalloc_objs() in sh_css.c

Replace arithmetic in the kmalloc() function with the kmalloc_objs() macro, as this calculation method is unsafe.

---
v3:
- use 'kmalloc_objs()' macro instead of 'kmalloc_array()' function
- drop unused 'GFP_KERNEL' arguments since they are default
v2:
- use 'sizeof(*ptr)' instead of explicit type

v2: https://lore.kernel.org/linux-staging/[email protected]/
v1: https://lore.kernel.org/linux-staging/[email protected]/

 drivers/staging/media/atomisp/pci/sh_css.c | 34 ++++++----------------
 1 file changed, 9 insertions(+), 25 deletions(-)
drivers/staging/media/atomisp/pci/sh_css.c +9 -25
index 6cda5925fa45..0733d33101b2 100644
@@ -5819,36 +5819,27 @@ static int ia_css_pipe_create_cas_scaler_desc_single_output(
 		i *= max_scale_factor_per_stage;
 	}
 
-	descr->in_info = kmalloc(descr->num_stage *
-				 sizeof(struct ia_css_frame_info),
-				 GFP_KERNEL);
+	kmalloc_objs(descr->in_info, descr->num_stage);
 	if (!descr->in_info) {
 		err = -ENOMEM;
 		goto ERR;
 	}
-	descr->internal_out_info = kmalloc(descr->num_stage *
-					   sizeof(struct ia_css_frame_info),
-					   GFP_KERNEL);
+	kmalloc_objs(descr->internal_out_info, descr->num_stage);
 	if (!descr->internal_out_info) {
 		err = -ENOMEM;
 		goto ERR;
 	}
-	descr->out_info = kmalloc(descr->num_stage *
-				  sizeof(struct ia_css_frame_info),
-				  GFP_KERNEL);
+	kmalloc_objs(descr->out_info, descr->num_stage);
 	if (!descr->out_info) {
 		err = -ENOMEM;
 		goto ERR;
 	}
-	descr->vf_info = kmalloc(descr->num_stage *
-				 sizeof(struct ia_css_frame_info),
-				 GFP_KERNEL);
+	kmalloc_objs(descr->vf_info, descr->num_stage);
 	if (!descr->vf_info) {
 		err = -ENOMEM;
 		goto ERR;
 	}
-	descr->is_output_stage = kmalloc(descr->num_stage * sizeof(bool),
-					 GFP_KERNEL);
+	kmalloc_objs(descr->is_output_stage, descr->num_stage);
 	if (!descr->is_output_stage) {
 		err = -ENOMEM;
 		goto ERR;
@@ -5974,29 +5965,22 @@ ia_css_pipe_create_cas_scaler_desc(struct ia_css_pipe *pipe,
 		err = -ENOMEM;
 		goto ERR;
 	}
-	descr->internal_out_info = kmalloc(descr->num_stage *
-					   sizeof(struct ia_css_frame_info),
-					   GFP_KERNEL);
+	kmalloc_objs(descr->internal_out_info, descr->num_stage);
 	if (!descr->internal_out_info) {
 		err = -ENOMEM;
 		goto ERR;
 	}
-	descr->out_info = kmalloc(descr->num_stage *
-				  sizeof(struct ia_css_frame_info),
-				  GFP_KERNEL);
+	kmalloc_objs(descr->out_info, descr->num_stage);
 	if (!descr->out_info) {
 		err = -ENOMEM;
 		goto ERR;
 	}
-	descr->vf_info = kmalloc(descr->num_stage *
-				 sizeof(struct ia_css_frame_info),
-				 GFP_KERNEL);
+	kmalloc_objs(descr->vf_info, descr->num_stage);
 	if (!descr->vf_info) {
 		err = -ENOMEM;
 		goto ERR;
 	}
-	descr->is_output_stage = kmalloc(descr->num_stage * sizeof(bool),
-					 GFP_KERNEL);
+	kmalloc_objs(descr->is_output_stage, descr->num_stage);
 	if (!descr->is_output_stage) {
 		err = -ENOMEM;
 		goto ERR;
#2 lore raw
In reply to Andrei Khomenkov
Quoted 2 lines · Andrei Khomenkov

Replace arithmetic in the kmalloc() function with the kmalloc_objs() macro, as this calculation method is unsafe.

...

Quoted 1 line

Nope, I haven't suggested the initial idea.

...

What about patches that were sent against this driver for the past year? There were at least two patches of the similar changes. Please, check on the prior work and if needed rebased, updated, upstreamed.

(If you haven't taken that, it has to be explained why.)

https://lore.kernel.org will help you and
https://lore.kernel.org/linux-media/?q=s%3Aatomisp+b%3Akmalloc
as a rough first step.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw

Thanks Andy, thanks Dan

I saw that a similar patch (commit 11f94f5b1d30) was already submitted by Pedro Pontes, so my patch is no longer relevant.

I ran the command

   scripts/get_maintainer.pl --scm -f drivers/staging/media/atomisp/pci/sh_css.c

and saw that when working with this driver, patches should be submitted to the git.linuxtv.org/media.git repository, not to Greg's staging tree. It's also clear now that working against the linux-next tree is a better option.

Andrei