linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: lpfc: fix kzalloc-simple.cocci warnings
@ 2017-10-11 19:42 Vasyl Gomonovych
  2017-11-03 15:50 ` James Smart
  2017-11-03 16:26 ` Martin K. Petersen
  0 siblings, 2 replies; 3+ messages in thread
From: Vasyl Gomonovych @ 2017-10-11 19:42 UTC (permalink / raw)
  To: linux-scsi, linux-kernel
  Cc: james.smart, dick.kennedy, jejb, martin.petersen, gomonovych

drivers/scsi/lpfc/lpfc_debugfs.c:5460:22-29: WARNING: kzalloc should be used for phba -> nvmeio_trc, instead of kmalloc/memset
drivers/scsi/lpfc/lpfc_debugfs.c:2230:20-27: WARNING: kzalloc should be used for phba -> nvmeio_trc, instead of kmalloc/memset

 Use kzalloc rather than kmalloc followed by memset with 0

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

Signed-off-by: Vasyl Gomonovych <gomonovych@gmail.com>
---
 drivers/scsi/lpfc/lpfc_debugfs.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
index d50c481..2bf5ad3 100644
--- a/drivers/scsi/lpfc/lpfc_debugfs.c
+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
@@ -2227,7 +2227,7 @@
 	kfree(phba->nvmeio_trc);
 
 	/* Allocate new trace buffer and initialize */
-	phba->nvmeio_trc = kmalloc((sizeof(struct lpfc_debugfs_nvmeio_trc) *
+	phba->nvmeio_trc = kzalloc((sizeof(struct lpfc_debugfs_nvmeio_trc) *
 				    sz), GFP_KERNEL);
 	if (!phba->nvmeio_trc) {
 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
@@ -2235,8 +2235,6 @@
 				"nvmeio_trc buffer\n");
 		return -ENOMEM;
 	}
-	memset(phba->nvmeio_trc, 0,
-	       (sizeof(struct lpfc_debugfs_nvmeio_trc) * sz));
 	atomic_set(&phba->nvmeio_trc_cnt, 0);
 	phba->nvmeio_trc_on = 0;
 	phba->nvmeio_trc_output_idx = 0;
@@ -5457,7 +5455,7 @@ static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
 			phba->nvmeio_trc_size = lpfc_debugfs_max_nvmeio_trc;
 
 			/* Allocate trace buffer and initialize */
-			phba->nvmeio_trc = kmalloc(
+			phba->nvmeio_trc = kzalloc(
 				(sizeof(struct lpfc_debugfs_nvmeio_trc) *
 				phba->nvmeio_trc_size), GFP_KERNEL);
 
@@ -5467,9 +5465,6 @@ static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
 						"nvmeio_trc buffer\n");
 				goto nvmeio_off;
 			}
-			memset(phba->nvmeio_trc, 0,
-			       (sizeof(struct lpfc_debugfs_nvmeio_trc) *
-			       phba->nvmeio_trc_size));
 			phba->nvmeio_trc_on = 1;
 			phba->nvmeio_trc_output_idx = 0;
 			phba->nvmeio_trc = NULL;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi: lpfc: fix kzalloc-simple.cocci warnings
  2017-10-11 19:42 [PATCH] scsi: lpfc: fix kzalloc-simple.cocci warnings Vasyl Gomonovych
@ 2017-11-03 15:50 ` James Smart
  2017-11-03 16:26 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: James Smart @ 2017-11-03 15:50 UTC (permalink / raw)
  To: Vasyl Gomonovych, linux-scsi, linux-kernel
  Cc: dick.kennedy, jejb, martin.petersen

On 10/11/2017 12:42 PM, Vasyl Gomonovych wrote:
> drivers/scsi/lpfc/lpfc_debugfs.c:5460:22-29: WARNING: kzalloc should be used for phba -> nvmeio_trc, instead of kmalloc/memset
> drivers/scsi/lpfc/lpfc_debugfs.c:2230:20-27: WARNING: kzalloc should be used for phba -> nvmeio_trc, instead of kmalloc/memset
>
>   Use kzalloc rather than kmalloc followed by memset with 0
>
> Generated by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
>
> Signed-off-by: Vasyl Gomonovych <gomonovych@gmail.com>
> ---
>   drivers/scsi/lpfc/lpfc_debugfs.c | 9 ++-------
>   1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
> index d50c481..2bf5ad3 100644
> --- a/drivers/scsi/lpfc/lpfc_debugfs.c
> +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
> @@ -2227,7 +2227,7 @@
>   	kfree(phba->nvmeio_trc);
>   
>   	/* Allocate new trace buffer and initialize */
> -	phba->nvmeio_trc = kmalloc((sizeof(struct lpfc_debugfs_nvmeio_trc) *
> +	phba->nvmeio_trc = kzalloc((sizeof(struct lpfc_debugfs_nvmeio_trc) *
>   				    sz), GFP_KERNEL);
>   	if (!phba->nvmeio_trc) {
>   		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
> @@ -2235,8 +2235,6 @@
>   				"nvmeio_trc buffer\n");
>   		return -ENOMEM;
>   	}
> -	memset(phba->nvmeio_trc, 0,
> -	       (sizeof(struct lpfc_debugfs_nvmeio_trc) * sz));
>   	atomic_set(&phba->nvmeio_trc_cnt, 0);
>   	phba->nvmeio_trc_on = 0;
>   	phba->nvmeio_trc_output_idx = 0;
> @@ -5457,7 +5455,7 @@ static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
>   			phba->nvmeio_trc_size = lpfc_debugfs_max_nvmeio_trc;
>   
>   			/* Allocate trace buffer and initialize */
> -			phba->nvmeio_trc = kmalloc(
> +			phba->nvmeio_trc = kzalloc(
>   				(sizeof(struct lpfc_debugfs_nvmeio_trc) *
>   				phba->nvmeio_trc_size), GFP_KERNEL);
>   
> @@ -5467,9 +5465,6 @@ static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
>   						"nvmeio_trc buffer\n");
>   				goto nvmeio_off;
>   			}
> -			memset(phba->nvmeio_trc, 0,
> -			       (sizeof(struct lpfc_debugfs_nvmeio_trc) *
> -			       phba->nvmeio_trc_size));
>   			phba->nvmeio_trc_on = 1;
>   			phba->nvmeio_trc_output_idx = 0;
>   			phba->nvmeio_trc = NULL;

looks good.


Signed-off-by:  James Smart <james.smart@broadcom.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi: lpfc: fix kzalloc-simple.cocci warnings
  2017-10-11 19:42 [PATCH] scsi: lpfc: fix kzalloc-simple.cocci warnings Vasyl Gomonovych
  2017-11-03 15:50 ` James Smart
@ 2017-11-03 16:26 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2017-11-03 16:26 UTC (permalink / raw)
  To: Vasyl Gomonovych
  Cc: linux-scsi, linux-kernel, james.smart, dick.kennedy, jejb,
	martin.petersen


Vasyl,

> drivers/scsi/lpfc/lpfc_debugfs.c:5460:22-29: WARNING: kzalloc should be used for phba -> nvmeio_trc, instead of kmalloc/memset
> drivers/scsi/lpfc/lpfc_debugfs.c:2230:20-27: WARNING: kzalloc should be used for phba -> nvmeio_trc, instead of kmalloc/memset
>
>  Use kzalloc rather than kmalloc followed by memset with 0

Applied to 4.15/scsi-queue.

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-11-03 16:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-11 19:42 [PATCH] scsi: lpfc: fix kzalloc-simple.cocci warnings Vasyl Gomonovych
2017-11-03 15:50 ` James Smart
2017-11-03 16:26 ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).