[PATCH] staging: media: atomisp: use kmalloc_array() for sh_css_blob_info

Lin YuChen posted 1 patch 3 weeks, 4 days ago
There is a newer version of this series
drivers/staging/media/atomisp/pci/sh_css_firmware.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[PATCH] staging: media: atomisp: use kmalloc_array() for sh_css_blob_info
Posted by Lin YuChen 3 weeks, 4 days ago
Replace the open-coded multiplication in kmalloc() with kmalloc_array()
to provide overflow protection and improve code readability.

Signed-off-by: Lin YuChen <starpt.official@gmail.com>
---
 drivers/staging/media/atomisp/pci/sh_css_firmware.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/media/atomisp/pci/sh_css_firmware.c b/drivers/staging/media/atomisp/pci/sh_css_firmware.c
index 57ecf5549c23..88757076c950 100644
--- a/drivers/staging/media/atomisp/pci/sh_css_firmware.c
+++ b/drivers/staging/media/atomisp/pci/sh_css_firmware.c
@@ -253,9 +253,9 @@ sh_css_load_firmware(struct device *dev, const char *fw_data,
 	sh_css_num_binaries = file_header->binary_nr;
 	/* Only allocate memory for ISP blob info */
 	if (sh_css_num_binaries > NUM_OF_SPS) {
-		sh_css_blob_info = kmalloc(
-		    (sh_css_num_binaries - NUM_OF_SPS) *
-		    sizeof(*sh_css_blob_info), GFP_KERNEL);
+		sh_css_blob_info =
+			kmalloc_array((sh_css_num_binaries - NUM_OF_SPS),
+				      sizeof(*sh_css_blob_info), GFP_KERNEL);
 		if (!sh_css_blob_info)
 			return -ENOMEM;
 	} else {
-- 
2.34.1
Re: [PATCH] staging: media: atomisp: use kmalloc_array() for sh_css_blob_info
Posted by Andy Shevchenko 3 weeks, 4 days ago
On Fri, Mar 13, 2026 at 05:08:01AM +0800, Lin YuChen wrote:
> Replace the open-coded multiplication in kmalloc() with kmalloc_array()
> to provide overflow protection and improve code readability.

...

> +		sh_css_blob_info =
> +			kmalloc_array((sh_css_num_binaries - NUM_OF_SPS),

Too many parentheses.

> +				      sizeof(*sh_css_blob_info), GFP_KERNEL);
>  		if (!sh_css_blob_info)
>  			return -ENOMEM;

-- 
With Best Regards,
Andy Shevchenko