Re: [PATCH v2 2/3] staging: media: atomisp: use kvmalloc_objs() for overflow-safe allocation

From: Andy Shevchenko

Date: Tue Jun 23 2026 - 06:26:41 EST


On Mon, Jun 22, 2026 at 07:42:43PM -0300, Rodrigo Gobbi wrote:
> Several allocations in sh_css_params.c still size their buffers with
> open-coded multiplication (e.g. width * height * sizeof(*p)), which can
> silently overflow and under-allocate.
>
> Convert them to kvmalloc_objs() with array_size(), which saturate to
> SIZE_MAX on overflow so kvmalloc() returns NULL instead of allocating
> too few bytes.

...

> + me->hor_coefs = kvmalloc_objs(*me->hor_coefs,
> + array_size(grid->num_hor_coefs,
> + IA_CSS_DVS_NUM_COEF_TYPES));

Here and elsewhere with long line, do like you have done in one case
with a temporary variable cnt. It makes same number of lines of code,
but readability is better.

> if (!me->hor_coefs)
> goto err;

--
With Best Regards,
Andy Shevchenko