Re: [PATCH] media: atomisp: use kmalloc_array() for array space allocation

From: Andy Shevchenko
Date: Thu Aug 21 2025 - 00:41:56 EST


On Thu, Aug 21, 2025 at 6:27 AM Qianfeng Rong <rongqianfeng@xxxxxxxx> wrote:
> 在 2025/8/20 23:05, Andy Shevchenko 写道:
> > On Sun, Aug 17, 2025 at 05:29:39PM +0800, Qianfeng Rong wrote:

...

> >> - descr->in_info = kmalloc(descr->num_stage *
> >> - sizeof(struct ia_css_frame_info),
> >> - GFP_KERNEL);
> >> + descr->in_info = kmalloc_array(descr->num_stage,
> >> + sizeof(struct ia_css_frame_info),
> >> + GFP_KERNEL);
> > At the same time it would be nice to use sizeof(*...) variants instead of using
> > type-based.

> I prefer sizeof(type),

Preference for sizeof(*...) is for a reason, and main one is the
robustness against type changes. The shortened line is a bonus.

> but using sizeof(*ptr) here shortens the line and
> is indeed better.


--
With Best Regards,
Andy Shevchenko