Skip to contentSkip to conversation

media: atomisp: use kmalloc_objs for array allocations

PATCH In review Pedro Pontes 3 participants 6 messages Apr 16 – Apr 21

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

PATCH 1/1 media: atomisp: use kmalloc_objs for array allocations

Convert manual kmalloc() multiplications to the modern kmalloc_objs() interface to improve type safety and prevent potential integer overflows.

---
This patch is a refresh and modernization of the following work by Qianfeng Rong from August 2025:

The original version used manual multiplications; I have updated it to use the newer kmalloc_objs() macro and enforced pointer-based type inference (e.g., *descr->in_info) as is now the preferred standard for these cleanups.

The patch has been verified with a W=1 build for pci/sh_css.o. Since I don't own the hardware.

Please note that, since I'm a new contributor, I wasn't quite sure in how to proceed in this scenario of "redoing" an older contribution. I've credited the original author with the "Originally-authored-by" tag. Please let me know if I should have done something differently.

 drivers/staging/media/atomisp/pci/sh_css.c | 57 ++++++++++++----------
 1 file changed, 30 insertions(+), 27 deletions(-)
drivers/staging/media/atomisp/pci/sh_css.c +30 -27
index 6cda5925fa45..26b7ea560c02 100644
@@ -5819,36 +5819,37 @@ 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);
+	descr->in_info = kmalloc_objs(*descr->in_info,
+				      descr->num_stage,
+				      GFP_KERNEL);
 	if (!descr->in_info) {
 		err = -ENOMEM;
 		goto ERR;
 	}
-	descr->internal_out_info = kmalloc(descr->num_stage *
-					   sizeof(struct ia_css_frame_info),
-					   GFP_KERNEL);
+	descr->internal_out_info = kmalloc_objs(*descr->internal_out_info,
+						descr->num_stage,
+						GFP_KERNEL);
 	if (!descr->internal_out_info) {
 		err = -ENOMEM;
 		goto ERR;
 	}
-	descr->out_info = kmalloc(descr->num_stage *
-				  sizeof(struct ia_css_frame_info),
-				  GFP_KERNEL);
+	descr->out_info = kmalloc_objs(*descr->out_info,
+				       descr->num_stage,
+				       GFP_KERNEL);
 	if (!descr->out_info) {
 		err = -ENOMEM;
 		goto ERR;
 	}
-	descr->vf_info = kmalloc(descr->num_stage *
-				 sizeof(struct ia_css_frame_info),
-				 GFP_KERNEL);
+	descr->vf_info = kmalloc_objs(*descr->vf_info,
+				      descr->num_stage,
+				      GFP_KERNEL);
 	if (!descr->vf_info) {
 		err = -ENOMEM;
 		goto ERR;
 	}
-	descr->is_output_stage = kmalloc(descr->num_stage * sizeof(bool),
-					 GFP_KERNEL);
+	descr->is_output_stage = kmalloc_objs(*descr->is_output_stage,
+					      descr->num_stage,
+					      GFP_KERNEL);
 	if (!descr->is_output_stage) {
 		err = -ENOMEM;
 		goto ERR;
@@ -5968,35 +5969,37 @@ ia_css_pipe_create_cas_scaler_desc(struct ia_css_pipe *pipe,
 
 	descr->num_stage = num_stages;
 
-	descr->in_info = kmalloc_objs(struct ia_css_frame_info,
-				      descr->num_stage);
+	descr->in_info = kmalloc_objs(*descr->in_info,
+				      descr->num_stage,
+				      GFP_KERNEL);
 	if (!descr->in_info) {
 		err = -ENOMEM;
 		goto ERR;
 	}
-	descr->internal_out_info = kmalloc(descr->num_stage *
-					   sizeof(struct ia_css_frame_info),
-					   GFP_KERNEL);
+	descr->internal_out_info = kmalloc_objs(*descr->internal_out_info,
+						descr->num_stage,
+						GFP_KERNEL);
 	if (!descr->internal_out_info) {
 		err = -ENOMEM;
 		goto ERR;
 	}
-	descr->out_info = kmalloc(descr->num_stage *
-				  sizeof(struct ia_css_frame_info),
-				  GFP_KERNEL);
+	descr->out_info = kmalloc_objs(*descr->out_info,
+				       descr->num_stage,
+				       GFP_KERNEL);
 	if (!descr->out_info) {
 		err = -ENOMEM;
 		goto ERR;
 	}
-	descr->vf_info = kmalloc(descr->num_stage *
-				 sizeof(struct ia_css_frame_info),
-				 GFP_KERNEL);
+	descr->vf_info = kmalloc_objs(*descr->vf_info,
+				      descr->num_stage,
+				      GFP_KERNEL);
 	if (!descr->vf_info) {
 		err = -ENOMEM;
 		goto ERR;
 	}
-	descr->is_output_stage = kmalloc(descr->num_stage * sizeof(bool),
-					 GFP_KERNEL);
+	descr->is_output_stage = kmalloc_objs(*descr->is_output_stage,
+					      descr->num_stage,
+					      GFP_KERNEL);
 	if (!descr->is_output_stage) {
 		err = -ENOMEM;
 		goto ERR;

--
2.53.0

#1 lore raw
Quoted 4 lines · Pedro Pontes

Convert manual kmalloc() multiplications to the modern kmalloc_objs() interface to improve type safety and prevent potential integer overflows.

There is already a patch doing it in a slightly better way. Have you followed the mailing list?
Please, better to help with this driver is to subscribe to the mailing list and review already
submitted ones.

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

There is already a patch doing it in a slightly better way. Have you followed the mailing list?

I searched lore and patchwork but couldn’t find the patch you’re referring to. Could you please point me to it?

Are you referring to the patch I linked in my submission, or a different one?

Quoted 3 lines

Please, better to help with this driver is to subscribe to the mailing list and review already
submitted ones.

Understood, I’ll follow the list more closely and review related patches. Thanks.

reviewer
#3 lore raw
In reply to Andy Shevchenko

Hi Andy,

Quoted 8 lines · Andy Shevchenko
Quoted 4 lines · Pedro Pontes

Convert manual kmalloc() multiplications to the modern kmalloc_objs() interface to improve type safety and prevent potential integer overflows.

There is already a patch doing it in a slightly better way. Have you followed the mailing list?

I must have missed it, too. :-\

Quoted 3 lines

Please, better to help with this driver is to subscribe to the mailing list and review already
submitted ones.

Signature · 3 lines
Regards,

Sakari Ailus
#4 lore raw
Quoted 11 lines · Sakari Ailus
Quoted 8 lines · Andy Shevchenko
Quoted 4 lines · Pedro Pontes

Convert manual kmalloc() multiplications to the modern kmalloc_objs() interface to improve type safety and prevent potential integer overflows.

There is already a patch doing it in a slightly better way. Have you followed the mailing list?

I must have missed it, too. :-\

https://lore.kernel.org/all/CAHp75VcoNkEQs7QQLDg8xZjdouNc8Yc6Vjg+Pdqb7LViqSKysg@mail.gmail.com/

Quoted 3 lines
Quoted 3 lines

Please, better to help with this driver is to subscribe to the mailing list and review already
submitted ones.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw
Quoted 9 lines · Andy Shevchenko
Quoted 7 lines · Sakari Ailus
Quoted 6 lines · Andy Shevchenko
Quoted 4 lines · Pedro Pontes

Convert manual kmalloc() multiplications to the modern kmalloc_objs() interface to improve type safety and prevent potential integer overflows.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

There is already a patch doing it in a slightly better way. Have you followed the mailing list?

I must have missed it, too. :-\

https://lore.kernel.org/all/CAHp75VcoNkEQs7QQLDg8xZjdouNc8Yc6Vjg+Pdqb7LViqSKysg@mail.gmail.com/

Hmm... Now re-reading that it seems they address semantically the same issue, but for different APIs.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Please, better to help with this driver is to subscribe to the mailing list and review already
submitted ones.

Signature · 2 lines
With Best Regards,
Andy Shevchenko