Message ID | 20220312102705.71413-5-Julia.Lawall@inria.fr |
---|---|
State | New |
Headers | show |
Series | use kzalloc | expand |
On Sat, 2022-03-12 at 11:27 +0100, Julia Lawall wrote: > Use kzalloc instead of kmalloc + memset. [] > diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c [] > @@ -6272,10 +6272,8 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport) > phba->hba_debugfs_root, > phba, &lpfc_debugfs_op_slow_ring_trc); > if (!phba->slow_ring_trc) { > - phba->slow_ring_trc = kmalloc( > - (sizeof(struct lpfc_debugfs_trc) * > - lpfc_debugfs_max_slow_ring_trc), > - GFP_KERNEL); > + phba->slow_ring_trc = kzalloc((sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_slow_ring_trc), > + GFP_KERNEL); kcalloc
On Sat, Mar 12, 2022 at 01:45:01PM -0800, Joe Perches wrote: > On Sat, 2022-03-12 at 11:27 +0100, Julia Lawall wrote: > > Use kzalloc instead of kmalloc + memset. > [] > > diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c > [] > > @@ -6272,10 +6272,8 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport) > > phba->hba_debugfs_root, > > phba, &lpfc_debugfs_op_slow_ring_trc); > > if (!phba->slow_ring_trc) { > > - phba->slow_ring_trc = kmalloc( > > - (sizeof(struct lpfc_debugfs_trc) * > > - lpfc_debugfs_max_slow_ring_trc), > > - GFP_KERNEL); > > + phba->slow_ring_trc = kzalloc((sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_slow_ring_trc), > > + GFP_KERNEL); > > kcalloc > Did someone have a Coccinelle script that converted kzalloc() to kcalloc()? regards, dan carpenter
On Mon, 14 Mar 2022, Dan Carpenter wrote: > On Sat, Mar 12, 2022 at 01:45:01PM -0800, Joe Perches wrote: > > On Sat, 2022-03-12 at 11:27 +0100, Julia Lawall wrote: > > > Use kzalloc instead of kmalloc + memset. > > [] > > > diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c > > [] > > > @@ -6272,10 +6272,8 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport) > > > phba->hba_debugfs_root, > > > phba, &lpfc_debugfs_op_slow_ring_trc); > > > if (!phba->slow_ring_trc) { > > > - phba->slow_ring_trc = kmalloc( > > > - (sizeof(struct lpfc_debugfs_trc) * > > > - lpfc_debugfs_max_slow_ring_trc), > > > - GFP_KERNEL); > > > + phba->slow_ring_trc = kzalloc((sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_slow_ring_trc), > > > + GFP_KERNEL); > > > > kcalloc > > > > Did someone have a Coccinelle script that converted kzalloc() to > kcalloc()? Not sure if I have ever done that. A long time ago, I made one that starts with kmalloc and picks kzalloc or kcalloc. Perhaps Kees did such a thing? I'll see if it would be useful. julia
diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c index 30fac2f6fb06..7c4a71703065 100644 --- a/drivers/scsi/lpfc/lpfc_debugfs.c +++ b/drivers/scsi/lpfc/lpfc_debugfs.c @@ -6272,10 +6272,8 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport) phba->hba_debugfs_root, phba, &lpfc_debugfs_op_slow_ring_trc); if (!phba->slow_ring_trc) { - phba->slow_ring_trc = kmalloc( - (sizeof(struct lpfc_debugfs_trc) * - lpfc_debugfs_max_slow_ring_trc), - GFP_KERNEL); + phba->slow_ring_trc = kzalloc((sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_slow_ring_trc), + GFP_KERNEL); if (!phba->slow_ring_trc) { lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, "0416 Cannot create debugfs " @@ -6283,9 +6281,6 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport) goto debug_failed; } atomic_set(&phba->slow_ring_trc_cnt, 0); - memset(phba->slow_ring_trc, 0, - (sizeof(struct lpfc_debugfs_trc) * - lpfc_debugfs_max_slow_ring_trc)); } snprintf(name, sizeof(name), "nvmeio_trc");
Use kzalloc instead of kmalloc + memset. The semantic patch that makes this change is: (https://coccinelle.gitlabpages.inria.fr/website/) //<smpl> @@ expression res, size, flag; @@ - res = kmalloc(size, flag); + res = kzalloc(size, flag); ... - memset(res, 0, size); //</smpl> Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr> --- drivers/scsi/lpfc/lpfc_debugfs.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)