Skip to contentSkip to conversation

megaraid_sas: combine kmalloc+memset into kzalloc

PATCH In review Fengguang Wu 2 participants 2 messages Aug 24, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 megaraid_sas: combine kmalloc+memset into kzalloc

Use kzalloc rather than kmalloc followed by memset with 0.

Generated by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci

---
 drivers/scsi/megaraid/megaraid_sas_fusion.c |    7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/scsi/megaraid/megaraid_sas_fusion.c +2 -5
@@ -461,8 +461,8 @@ megasas_alloc_cmds_fusion(struct megasas
 	 * Allocate the dynamic array first and then allocate individual
 	 * commands.
 	 */
-	fusion->cmd_list = kmalloc(sizeof(struct megasas_cmd_fusion *)
-				   *max_cmd, GFP_KERNEL);
+	fusion->cmd_list = kzalloc(sizeof(struct megasas_cmd_fusion *)
+				   * max_cmd, GFP_KERNEL);
 
 	if (!fusion->cmd_list) {
 		printk(KERN_DEBUG "megasas: out of memory. Could not alloc "
@@ -470,9 +470,6 @@ megasas_alloc_cmds_fusion(struct megasas
 		goto fail_cmd_list;
 	}
 
-	memset(fusion->cmd_list, 0, sizeof(struct megasas_cmd_fusion *)
-	       *max_cmd);
-
 	max_cmd = instance->max_fw_cmds;
 	for (i = 0; i < max_cmd; i++) {
 		fusion->cmd_list[i] = kmalloc(sizeof(struct megasas_cmd_fusion),
Acked-by on v1 1/1
#1 lore raw
Quoted 23 lines · Fengguang Wu

Use kzalloc rather than kmalloc followed by memset with 0.

Generated by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci

---
 drivers/scsi/megaraid/megaraid_sas_fusion.c |    7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/scsi/megaraid/megaraid_sas_fusion.c 2012-08-24 23:25:02.261560445 +0800 renamed from drivers/scsi/megaraid/megaraid_sas_fusion.c 2012-06-07 05:39:57.418846382 +0800 +2 -2
@@ -461,8 +461,8 @@ megasas_alloc_cmds_fusion(struct megasas
         * Allocate the dynamic array first and then allocate individual
         * commands.
         */
-       fusion->cmd_list = kmalloc(sizeof(struct megasas_cmd_fusion *)
-                                  *max_cmd, GFP_KERNEL);
+       fusion->cmd_list = kzalloc(sizeof(struct megasas_cmd_fusion *)
+                                  * max_cmd, GFP_KERNEL);
 
        if (!fusion->cmd_list) {
                printk(KERN_DEBUG "megasas: out of memory. Could not alloc "

drivers/scsi/megaraid/megaraid_sas_fusion.c 2012-08-24 23:25:02.261560445 +0800 megasas_alloc_cmds_fusion(struct megasas · line 475

Quoted 9 lines
drivers/scsi/megaraid/megaraid_sas_fusion.c 2012-08-24 23:25:02.261560445 +0800 renamed from drivers/scsi/megaraid/megaraid_sas_fusion.c 2012-06-07 05:39:57.418846382 +0800 +0 -3
@@ -470,9 +470,6 @@ megasas_alloc_cmds_fusion(struct megasas
                goto fail_cmd_list;
        }
 
-       memset(fusion->cmd_list, 0, sizeof(struct megasas_cmd_fusion *)
-              *max_cmd);
-
        max_cmd = instance->max_fw_cmds;
        for (i = 0; i < max_cmd; i++) {
                fusion->cmd_list[i] = kmalloc(sizeof(struct megasas_cmd_fusion),