From mboxrd@z Thu Jan 1 00:00:00 1970 From: kbuild test robot Subject: [PATCH] megaraid_sas: fix kzalloc-simple.cocci warnings Date: Fri, 18 Dec 2015 22:49:20 +0800 Message-ID: <20151218144920.GA135531@athens> References: <201512182259.Q7txZEEP%fengguang.wu@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from mga01.intel.com ([192.55.52.88]:42025 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751019AbbLROuz (ORCPT ); Fri, 18 Dec 2015 09:50:55 -0500 Content-Disposition: inline In-Reply-To: <1450445228-26571-8-git-send-email-Sumit.Saxena@avagotech.com> Sender: linux-scsi-owner@vger.kernel.org List-Id: linux-scsi@vger.kernel.org Cc: kbuild-all@01.org, jbottomley@parallels.com, hch@infradead.org, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, kashyap.desai@avagotech.com, sumit.saxena@avagotech.com drivers/scsi/megaraid/megaraid_sas_fusion.c:331:20-27: WARNING: kzalloc should be used for fusion -> cmd_list, instead of kmalloc/memset drivers/scsi/megaraid/megaraid_sas_fusion.c:342:24-31: WARNING: kzalloc should be used for fusion -> cmd_list [ i ], instead of kmalloc/memset Use kzalloc rather than kmalloc followed by memset with 0 This considers some simple cases that are common and easy to validate Note in particular that there are no ...s in the rule, so all of the matched code has to be contiguous Generated by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci CC: Sumit Saxena Signed-off-by: Fengguang Wu --- megaraid_sas_fusion.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) --- a/drivers/scsi/megaraid/megaraid_sas_fusion.c +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c @@ -328,25 +328,22 @@ megasas_alloc_cmdlist_fusion(struct mega * 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) { dev_err(&instance->pdev->dev, "Failed from %s %d\n", __func__, __LINE__); return -ENOMEM; } - memset(fusion->cmd_list, 0, - sizeof(struct megasas_cmd_fusion *) * max_cmd); for (i = 0; i < max_cmd; i++) { - fusion->cmd_list[i] = kmalloc(sizeof(struct megasas_cmd_fusion), + fusion->cmd_list[i] = kzalloc(sizeof(struct megasas_cmd_fusion), GFP_KERNEL); if (!fusion->cmd_list[i]) { dev_err(&instance->pdev->dev, "Failed from %s %d\n", __func__, __LINE__); return -ENOMEM; } - memset(fusion->cmd_list[i], 0, sizeof(struct megasas_cmd_fusion)); } return 0; }