Skip to contentSkip to conversation

staging: media: atomisp: use kmalloc_array() for sh_css_blob_info

PATCH In review Lin YuChen 2 participants 2 messages Mar 12 – Mar 13

Subsystems (4)
lore
Share & tools
lore

Lin YuChen

author
#0 lore raw

PATCH 1/1 staging: media: atomisp: use kmalloc_array() for sh_css_blob_info

Replace the open-coded multiplication in kmalloc() with kmalloc_array() to provide overflow protection and improve code readability.

---
 drivers/staging/media/atomisp/pci/sh_css_firmware.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/media/atomisp/pci/sh_css_firmware.c +3 -3
index 57ecf5549c23..88757076c950 100644
@@ -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 {
Signature · 1 line
2.34.1
#1 lore raw
Quoted 2 lines · Lin YuChen

Replace the open-coded multiplication in kmalloc() with kmalloc_array() to provide overflow protection and improve code readability.

...

drivers/staging/media/atomisp/pci/sh_css_firmware.c sh_css_load_firmware(struct device *dev, const char *fw_data, · line 257

Quoted 2 lines
drivers/staging/media/atomisp/pci/sh_css_firmware.c +2 -0
+		sh_css_blob_info =
+			kmalloc_array((sh_css_num_binaries - NUM_OF_SPS),

Too many parentheses.

Quoted 3 lines
drivers/staging/media/atomisp/pci/sh_css_firmware.c +1 -0
+				      sizeof(*sh_css_blob_info), GFP_KERNEL);
 		if (!sh_css_blob_info)
 			return -ENOMEM;
Signature · 2 lines
With Best Regards,
Andy Shevchenko