* [PATCH] media: atomisp: use kmalloc_objs for array allocations
@ 2026-04-16 13:42 Pedro Pontes
2026-04-16 18:26 ` Andy Shevchenko
0 siblings, 1 reply; 6+ messages in thread
From: Pedro Pontes @ 2026-04-16 13:42 UTC (permalink / raw)
To: hansg, gregkh, mchehab
Cc: andy, sakari.ailus, kees, linux-media, linux-staging,
linux-kernel, Pedro Pontes
Convert manual kmalloc() multiplications to the modern kmalloc_objs()
interface to improve type safety and prevent potential integer
overflows.
Signed-off-by: Pedro Pontes <pontescpedro@gmail.com>
---
This patch is a refresh and modernization of the following work by
Qianfeng Rong from August 2025:
Link: https://lore.kernel.org/all/20250821081746.528018-1-rongqianfeng@vivo.com/
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(-)
diff --git a/drivers/staging/media/atomisp/pci/sh_css.c b/drivers/staging/media/atomisp/pci/sh_css.c
index 6cda5925fa45..26b7ea560c02 100644
--- a/drivers/staging/media/atomisp/pci/sh_css.c
+++ b/drivers/staging/media/atomisp/pci/sh_css.c
@@ -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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] media: atomisp: use kmalloc_objs for array allocations
2026-04-16 13:42 [PATCH] media: atomisp: use kmalloc_objs for array allocations Pedro Pontes
@ 2026-04-16 18:26 ` Andy Shevchenko
2026-04-16 20:06 ` Pedro Pontes
2026-04-21 16:52 ` Sakari Ailus
0 siblings, 2 replies; 6+ messages in thread
From: Andy Shevchenko @ 2026-04-16 18:26 UTC (permalink / raw)
To: Pedro Pontes
Cc: hansg, gregkh, mchehab, andy, sakari.ailus, kees, linux-media,
linux-staging, linux-kernel
On Thu, Apr 16, 2026 at 4:46 PM Pedro Pontes <pontescpedro@gmail.com> wrote:
>
> 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.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] media: atomisp: use kmalloc_objs for array allocations
2026-04-16 18:26 ` Andy Shevchenko
@ 2026-04-16 20:06 ` Pedro Pontes
2026-04-21 16:52 ` Sakari Ailus
1 sibling, 0 replies; 6+ messages in thread
From: Pedro Pontes @ 2026-04-16 20:06 UTC (permalink / raw)
To: Andy Shevchenko
Cc: hansg, gregkh, mchehab, andy, sakari.ailus, kees, linux-media,
linux-staging, linux-kernel
> 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?
> 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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] media: atomisp: use kmalloc_objs for array allocations
2026-04-16 18:26 ` Andy Shevchenko
2026-04-16 20:06 ` Pedro Pontes
@ 2026-04-21 16:52 ` Sakari Ailus
2026-04-21 18:07 ` Andy Shevchenko
1 sibling, 1 reply; 6+ messages in thread
From: Sakari Ailus @ 2026-04-21 16:52 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Pedro Pontes, hansg, gregkh, mchehab, andy, kees, linux-media,
linux-staging, linux-kernel
Hi Andy,
On Thu, Apr 16, 2026 at 09:26:47PM +0300, Andy Shevchenko wrote:
> On Thu, Apr 16, 2026 at 4:46 PM Pedro Pontes <pontescpedro@gmail.com> wrote:
> >
> > 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. :-\
> Please, better to help with this driver is to subscribe to the mailing
> list and review already
> submitted ones.
--
Regards,
Sakari Ailus
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] media: atomisp: use kmalloc_objs for array allocations
2026-04-21 16:52 ` Sakari Ailus
@ 2026-04-21 18:07 ` Andy Shevchenko
2026-04-21 18:09 ` Andy Shevchenko
0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2026-04-21 18:07 UTC (permalink / raw)
To: Sakari Ailus
Cc: Pedro Pontes, hansg, gregkh, mchehab, andy, kees, linux-media,
linux-staging, linux-kernel
On Tue, Apr 21, 2026 at 7:52 PM Sakari Ailus
<sakari.ailus@linux.intel.com> wrote:
> On Thu, Apr 16, 2026 at 09:26:47PM +0300, Andy Shevchenko wrote:
> > On Thu, Apr 16, 2026 at 4:46 PM Pedro Pontes <pontescpedro@gmail.com> wrote:
> > >
> > > 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/
> > Please, better to help with this driver is to subscribe to the mailing
> > list and review already
> > submitted ones.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] media: atomisp: use kmalloc_objs for array allocations
2026-04-21 18:07 ` Andy Shevchenko
@ 2026-04-21 18:09 ` Andy Shevchenko
0 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2026-04-21 18:09 UTC (permalink / raw)
To: Sakari Ailus
Cc: Pedro Pontes, hansg, gregkh, mchehab, andy, kees, linux-media,
linux-staging, linux-kernel
On Tue, Apr 21, 2026 at 9:07 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
> On Tue, Apr 21, 2026 at 7:52 PM Sakari Ailus
> <sakari.ailus@linux.intel.com> wrote:
> > On Thu, Apr 16, 2026 at 09:26:47PM +0300, Andy Shevchenko wrote:
> > > On Thu, Apr 16, 2026 at 4:46 PM Pedro Pontes <pontescpedro@gmail.com> wrote:
> > > >
> > > > 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/
Hmm... Now re-reading that it seems they address semantically the same
issue, but for different APIs.
> > > Please, better to help with this driver is to subscribe to the mailing
> > > list and review already
> > > submitted ones.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-04-21 18:09 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-16 13:42 [PATCH] media: atomisp: use kmalloc_objs for array allocations Pedro Pontes
2026-04-16 18:26 ` Andy Shevchenko
2026-04-16 20:06 ` Pedro Pontes
2026-04-21 16:52 ` Sakari Ailus
2026-04-21 18:07 ` Andy Shevchenko
2026-04-21 18:09 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox