From: Andrei Khomenkov <khomenkov@mailbox.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Andy Shevchenko <andy@kernel.org>
Cc: Kees Cook <kees@kernel.org>,
linux-staging@lists.linux.dev, linux-media@vger.kernel.org
Subject: [PATCH v2] media: atomisp: replace kmalloc() with kmalloc_array() in sh_css.c
Date: Sat, 13 Jun 2026 14:07:12 +0300 [thread overview]
Message-ID: <20260613110712.71436-1-khomenkov@mailbox.org> (raw)
Replace arithmetic in the kmalloc() function with the kmalloc_array()
function, as this calculation method is unsafe.
Signed-off-by: Andrei Khomenkov <khomenkov@mailbox.org>
---
v2:
- use 'sizeof(*ptr)' instead of explicit type
drivers/staging/media/atomisp/pci/sh_css.c | 38 ++++++++--------------
1 file changed, 13 insertions(+), 25 deletions(-)
diff --git a/drivers/staging/media/atomisp/pci/sh_css.c b/drivers/staging/media/atomisp/pci/sh_css.c
index 6cda5925fa45..37ab569664c2 100644
--- a/drivers/staging/media/atomisp/pci/sh_css.c
+++ b/drivers/staging/media/atomisp/pci/sh_css.c
@@ -5819,36 +5819,29 @@ 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_array(descr->num_stage, sizeof(*descr->in_info), 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_array(descr->num_stage,
+ sizeof(*descr->internal_out_info), 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_array(descr->num_stage, sizeof(*descr->out_info), 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_array(descr->num_stage, sizeof(*descr->vf_info), 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_array(descr->num_stage, sizeof(*descr->is_output_stage),
+ GFP_KERNEL);
if (!descr->is_output_stage) {
err = -ENOMEM;
goto ERR;
@@ -5974,29 +5967,24 @@ 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);
+ descr->internal_out_info = kmalloc_array(descr->num_stage,
+ sizeof(*descr->internal_out_info), 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_array(descr->num_stage, sizeof(*descr->out_info), 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_array(descr->num_stage, sizeof(*descr->vf_info), 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_array(descr->num_stage, sizeof(*descr->is_output_stage),
+ GFP_KERNEL);
if (!descr->is_output_stage) {
err = -ENOMEM;
goto ERR;
next reply other threads:[~2026-06-13 11:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-13 11:07 Andrei Khomenkov [this message]
2026-06-15 14:09 ` [PATCH v2] media: atomisp: replace kmalloc() with kmalloc_array() in sh_css.c Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260613110712.71436-1-khomenkov@mailbox.org \
--to=khomenkov@mailbox.org \
--cc=andy@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=kees@kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox