RE: [PATCH 8/9] scsi: bfa: Use zeroing allocator rather than allocator/memset

2018-01-01 Thread Gurumurthy, Anil


-Original Message-
From: Himanshu Jha [mailto:himanshujha199...@gmail.com] 
Sent: 30 December 2017 20:59
To: j...@linux.vnet.ibm.com; martin.peter...@oracle.com; aacr...@adaptec.com
Cc: Gurumurthy, Anil ; Kalluru, Sudarsana 
; Dept-Eng QLogic Storage Upstream 
; satis...@cisco.com; sebad...@cisco.com; 
karti...@cisco.com; Dept-Eng QLogic Storage Upstream 
; Dept-Eng QLA2xxx Upstream 
; linux-scsi@vger.kernel.org; 
linux-ker...@vger.kernel.org; Himanshu Jha 
Subject: [PATCH 8/9] scsi: bfa: Use zeroing allocator rather than 
allocator/memset

Use vzalloc instead of vmalloc followed by memset 0.

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

Suggested-by: Luis R. Rodriguez 
Signed-off-by: Himanshu Jha 
---
 drivers/scsi/bfa/bfad.c | 3 +--
 drivers/scsi/bfa/bfad_debugfs.c | 8 ++--
 2 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/bfa/bfad.c b/drivers/scsi/bfa/bfad.c index 
bac18f6..bd7e6a6f 100644
--- a/drivers/scsi/bfa/bfad.c
+++ b/drivers/scsi/bfa/bfad.c
@@ -610,13 +610,12 @@ bfad_hal_mem_alloc(struct bfad_s *bfad)
/* Iterate through the KVA meminfo queue */
list_for_each(km_qe, _info->qe) {
kva_elem = (struct bfa_mem_kva_s *) km_qe;
-   kva_elem->kva = vmalloc(kva_elem->mem_len);
+   kva_elem->kva = vzalloc(kva_elem->mem_len);
if (kva_elem->kva == NULL) {
bfad_hal_mem_release(bfad);
rc = BFA_STATUS_ENOMEM;
goto ext;
}
-   memset(kva_elem->kva, 0, kva_elem->mem_len);
}
 
/* Iterate through the DMA meminfo queue */ diff --git 
a/drivers/scsi/bfa/bfad_debugfs.c b/drivers/scsi/bfa/bfad_debugfs.c index 
05f5239..349cfe7 100644
--- a/drivers/scsi/bfa/bfad_debugfs.c
+++ b/drivers/scsi/bfa/bfad_debugfs.c
@@ -81,7 +81,7 @@ bfad_debugfs_open_fwtrc(struct inode *inode, struct file 
*file)
 
fw_debug->buffer_len = sizeof(struct bfa_trc_mod_s);
 
-   fw_debug->debug_buffer = vmalloc(fw_debug->buffer_len);
+   fw_debug->debug_buffer = vzalloc(fw_debug->buffer_len);
if (!fw_debug->debug_buffer) {
kfree(fw_debug);
printk(KERN_INFO "bfad[%d]: Failed to allocate fwtrc buffer\n", 
@@ -89,8 +89,6 @@ bfad_debugfs_open_fwtrc(struct inode *inode, struct file 
*file)
return -ENOMEM;
}
 
-   memset(fw_debug->debug_buffer, 0, fw_debug->buffer_len);
-
spin_lock_irqsave(>bfad_lock, flags);
rc = bfa_ioc_debug_fwtrc(>bfa.ioc,
fw_debug->debug_buffer,
@@ -125,7 +123,7 @@ bfad_debugfs_open_fwsave(struct inode *inode, struct file 
*file)
 
fw_debug->buffer_len = sizeof(struct bfa_trc_mod_s);
 
-   fw_debug->debug_buffer = vmalloc(fw_debug->buffer_len);
+   fw_debug->debug_buffer = vzalloc(fw_debug->buffer_len);
if (!fw_debug->debug_buffer) {
kfree(fw_debug);
printk(KERN_INFO "bfad[%d]: Failed to allocate fwsave 
buffer\n", @@ -133,8 +131,6 @@ bfad_debugfs_open_fwsave(struct inode *inode, 
struct file *file)
return -ENOMEM;
}
 
-   memset(fw_debug->debug_buffer, 0, fw_debug->buffer_len);
-
spin_lock_irqsave(>bfad_lock, flags);
rc = bfa_ioc_debug_fwsave(>bfa.ioc,
fw_debug->debug_buffer,
--
2.7.4

Acked by: Anil Gurumurthy 



Re: [PATCH 9/9] scsi: bnx2i: Use zeroing allocator rather than allocator/memset

2018-01-01 Thread Rangankar, Manish


On 30/12/17 8:58 PM, "Himanshu Jha"  wrote:

>Use dma_zalloc_coherent instead of dma_alloc_coherent followed by
>memset 0.
>
>Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
>
>Suggested-by: Luis R. Rodriguez 
>Signed-off-by: Himanshu Jha 
>---
> drivers/scsi/bnx2i/bnx2i_hwi.c | 14 ++
> 1 file changed, 6 insertions(+), 8 deletions(-)
>
>diff --git a/drivers/scsi/bnx2i/bnx2i_hwi.c
>b/drivers/scsi/bnx2i/bnx2i_hwi.c
>index 9e3bf53..c6a0bd6 100644
>--- a/drivers/scsi/bnx2i/bnx2i_hwi.c
>+++ b/drivers/scsi/bnx2i/bnx2i_hwi.c
>@@ -1069,16 +1069,15 @@ int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba,
>struct bnx2i_endpoint *ep)
>   }
> 
>   /* Allocate memory area for actual SQ element */
>-  ep->qp.sq_virt =
>-  dma_alloc_coherent(>pcidev->dev, ep->qp.sq_mem_size,
>- >qp.sq_phys, GFP_KERNEL);
>+  ep->qp.sq_virt =
>+  dma_zalloc_coherent(>pcidev->dev, ep->qp.sq_mem_size,
>+  >qp.sq_phys, GFP_KERNEL);
>   if (!ep->qp.sq_virt) {
>   printk(KERN_ALERT "bnx2i: unable to alloc SQ BD memory %d\n",
> ep->qp.sq_mem_size);
>   goto mem_alloc_err;
>   }
> 
>-  memset(ep->qp.sq_virt, 0x00, ep->qp.sq_mem_size);
>   ep->qp.sq_first_qe = ep->qp.sq_virt;
>   ep->qp.sq_prod_qe = ep->qp.sq_first_qe;
>   ep->qp.sq_cons_qe = ep->qp.sq_first_qe;
>@@ -1106,15 +1105,14 @@ int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba,
>struct bnx2i_endpoint *ep)
>   }
> 
>   /* Allocate memory area for actual CQ element */
>-  ep->qp.cq_virt =
>-  dma_alloc_coherent(>pcidev->dev, ep->qp.cq_mem_size,
>- >qp.cq_phys, GFP_KERNEL);
>+  ep->qp.cq_virt =
>+  dma_zalloc_coherent(>pcidev->dev, ep->qp.cq_mem_size,
>+  >qp.cq_phys, GFP_KERNEL);
>   if (!ep->qp.cq_virt) {
>   printk(KERN_ALERT "bnx2i: unable to alloc CQ BD memory %d\n",
> ep->qp.cq_mem_size);
>   goto mem_alloc_err;
>   }
>-  memset(ep->qp.cq_virt, 0x00, ep->qp.cq_mem_size);
> 
>   ep->qp.cq_first_qe = ep->qp.cq_virt;
>   ep->qp.cq_prod_qe = ep->qp.cq_first_qe;
>-- 
>2.7.4

Acked-by: Manish Rangankar 


>



Re: [PATCH 3/9] scsi: qedi: Use zeroing allocator instead of allocator/memset

2018-01-01 Thread Rangankar, Manish


On 30/12/17 8:58 PM, "Himanshu Jha"  wrote:

>Use dma_zalloc_coherent instead of dma_alloc_coherent followed by memset
>0.
>
>Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
>
>Suggested-by: Luis R. Rodriguez 
>Signed-off-by: Himanshu Jha 
>---
> drivers/scsi/qedi/qedi_main.c | 42
>+++---
> 1 file changed, 15 insertions(+), 27 deletions(-)
>
>diff --git a/drivers/scsi/qedi/qedi_main.c b/drivers/scsi/qedi/qedi_main.c
>index 34a..5ef0b36 100644
>--- a/drivers/scsi/qedi/qedi_main.c
>+++ b/drivers/scsi/qedi/qedi_main.c
>@@ -1268,16 +1268,14 @@ static int qedi_alloc_bdq(struct qedi_ctx *qedi)
>   }
> 
>   /* Allocate list of PBL pages */
>-  qedi->bdq_pbl_list = dma_alloc_coherent(>pdev->dev,
>-  PAGE_SIZE,
>-  >bdq_pbl_list_dma,
>-  GFP_KERNEL);
>+  qedi->bdq_pbl_list = dma_zalloc_coherent(>pdev->dev, PAGE_SIZE,
>+   >bdq_pbl_list_dma,
>+   GFP_KERNEL);
>   if (!qedi->bdq_pbl_list) {
>   QEDI_ERR(>dbg_ctx,
>"Could not allocate list of PBL pages.\n");
>   return -ENOMEM;
>   }
>-  memset(qedi->bdq_pbl_list, 0, PAGE_SIZE);
> 
>   /*
>* Now populate PBL list with pages that contain pointers to the
>@@ -1367,11 +1365,10 @@ static int qedi_alloc_global_queues(struct
>qedi_ctx *qedi)
>   (qedi->global_queues[i]->cq_pbl_size +
>   (QEDI_PAGE_SIZE - 1));
> 
>-  qedi->global_queues[i]->cq =
>-  dma_alloc_coherent(>pdev->dev,
>- qedi->global_queues[i]->cq_mem_size,
>- >global_queues[i]->cq_dma,
>- GFP_KERNEL);
>+  qedi->global_queues[i]->cq =
>+  dma_zalloc_coherent(>pdev->dev,
>+  qedi->global_queues[i]->cq_mem_size,
>+  >global_queues[i]->cq_dma,
>+  GFP_KERNEL);
> 
>   if (!qedi->global_queues[i]->cq) {
>   QEDI_WARN(>dbg_ctx,
>@@ -1379,14 +1376,10 @@ static int qedi_alloc_global_queues(struct
>qedi_ctx *qedi)
>   status = -ENOMEM;
>   goto mem_alloc_failure;
>   }
>-  memset(qedi->global_queues[i]->cq, 0,
>- qedi->global_queues[i]->cq_mem_size);
>-
>-  qedi->global_queues[i]->cq_pbl =
>-  dma_alloc_coherent(>pdev->dev,
>- qedi->global_queues[i]->cq_pbl_size,
>- >global_queues[i]->cq_pbl_dma,
>- GFP_KERNEL);
>+  qedi->global_queues[i]->cq_pbl =
>+  dma_zalloc_coherent(>pdev->dev,
>+  qedi->global_queues[i]->cq_pbl_size,
>+  >global_queues[i]->cq_pbl_dma,
>+  GFP_KERNEL);
> 
>   if (!qedi->global_queues[i]->cq_pbl) {
>   QEDI_WARN(>dbg_ctx,
>@@ -1394,8 +1387,6 @@ static int qedi_alloc_global_queues(struct qedi_ctx
>*qedi)
>   status = -ENOMEM;
>   goto mem_alloc_failure;
>   }
>-  memset(qedi->global_queues[i]->cq_pbl, 0,
>- qedi->global_queues[i]->cq_pbl_size);
> 
>   /* Create PBL */
>   num_pages = qedi->global_queues[i]->cq_mem_size /
>@@ -1456,25 +1447,22 @@ int qedi_alloc_sq(struct qedi_ctx *qedi, struct
>qedi_endpoint *ep)
>   ep->sq_pbl_size = (ep->sq_mem_size / QEDI_PAGE_SIZE) * sizeof(void *);
>   ep->sq_pbl_size = ep->sq_pbl_size + QEDI_PAGE_SIZE;
> 
>-  ep->sq = dma_alloc_coherent(>pdev->dev, ep->sq_mem_size,
>-  >sq_dma, GFP_KERNEL);
>+  ep->sq = dma_zalloc_coherent(>pdev->dev, ep->sq_mem_size,
>+   >sq_dma, GFP_KERNEL);
>   if (!ep->sq) {
>   QEDI_WARN(>dbg_ctx,
> "Could not allocate send queue.\n");
>   rval = -ENOMEM;
>   goto out;
>   }
>-  memset(ep->sq, 0, ep->sq_mem_size);
>-
>-  ep->sq_pbl = dma_alloc_coherent(>pdev->dev, ep->sq_pbl_size,
>-  >sq_pbl_dma, GFP_KERNEL);
>+  ep->sq_pbl = dma_zalloc_coherent(>pdev->dev, ep->sq_pbl_size,
>+   >sq_pbl_dma, GFP_KERNEL);
>   if (!ep->sq_pbl) {
>   QEDI_WARN(>dbg_ctx,
> "Could not allocate send queue PBL.\n");
>   rval 

Re: [PATCH 1/9] scsi: qla4xxx: Use zeroing allocator rather than allocator/memset

2018-01-01 Thread Rangankar, Manish


On 30/12/17 8:58 PM, "Himanshu Jha"  wrote:

>Use dma_zalloc_coherent instead of dma_alloc_coherent followed by memset
>0.
>
>Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
>
>Suggested-by: Luis R. Rodriguez 
>Signed-off-by: Himanshu Jha 
>---
> drivers/scsi/qla4xxx/ql4_init.c |  5 ++---
> drivers/scsi/qla4xxx/ql4_mbx.c  | 21 +
> drivers/scsi/qla4xxx/ql4_nx.c   |  5 ++---
> drivers/scsi/qla4xxx/ql4_os.c   | 12 +---
> 4 files changed, 18 insertions(+), 25 deletions(-)
>
>diff --git a/drivers/scsi/qla4xxx/ql4_init.c
>b/drivers/scsi/qla4xxx/ql4_init.c
>index 5d6d158..52b1a0b 100644
>--- a/drivers/scsi/qla4xxx/ql4_init.c
>+++ b/drivers/scsi/qla4xxx/ql4_init.c
>@@ -153,15 +153,14 @@ int qla4xxx_get_sys_info(struct scsi_qla_host *ha)
>   dma_addr_t sys_info_dma;
>   int status = QLA_ERROR;
> 
>-  sys_info = dma_alloc_coherent(>pdev->dev, sizeof(*sys_info),
>-_info_dma, GFP_KERNEL);
>+  sys_info = dma_zalloc_coherent(>pdev->dev, sizeof(*sys_info),
>+ _info_dma, GFP_KERNEL);
>   if (sys_info == NULL) {
>   DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
> ha->host_no, __func__));
> 
>   goto exit_get_sys_info_no_free;
>   }
>-  memset(sys_info, 0, sizeof(*sys_info));
> 
>   /* Get flash sys info */
>   if (qla4xxx_get_flash(ha, sys_info_dma, FLASH_OFFSET_SYS_INFO,
>diff --git a/drivers/scsi/qla4xxx/ql4_mbx.c
>b/drivers/scsi/qla4xxx/ql4_mbx.c
>index 1da04f3..bda2e64 100644
>--- a/drivers/scsi/qla4xxx/ql4_mbx.c
>+++ b/drivers/scsi/qla4xxx/ql4_mbx.c
>@@ -625,15 +625,14 @@ int qla4xxx_initialize_fw_cb(struct scsi_qla_host *
>ha)
>   uint32_t mbox_sts[MBOX_REG_COUNT];
>   int status = QLA_ERROR;
> 
>-  init_fw_cb = dma_alloc_coherent(>pdev->dev,
>-  sizeof(struct addr_ctrl_blk),
>-  _fw_cb_dma, GFP_KERNEL);
>+  init_fw_cb = dma_zalloc_coherent(>pdev->dev,
>+   sizeof(struct addr_ctrl_blk),
>+   _fw_cb_dma, GFP_KERNEL);
>   if (init_fw_cb == NULL) {
>   DEBUG2(printk("scsi%ld: %s: Unable to alloc init_cb\n",
> ha->host_no, __func__));
>   goto exit_init_fw_cb_no_free;
>   }
>-  memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
> 
>   /* Get Initialize Firmware Control Block. */
>   memset(_cmd, 0, sizeof(mbox_cmd));
>@@ -710,9 +709,9 @@ int qla4xxx_get_dhcp_ip_address(struct scsi_qla_host
>* ha)
>   uint32_t mbox_cmd[MBOX_REG_COUNT];
>   uint32_t mbox_sts[MBOX_REG_COUNT];
> 
>-  init_fw_cb = dma_alloc_coherent(>pdev->dev,
>-  sizeof(struct addr_ctrl_blk),
>-  _fw_cb_dma, GFP_KERNEL);
>+  init_fw_cb = dma_zalloc_coherent(>pdev->dev,
>+   sizeof(struct addr_ctrl_blk),
>+   _fw_cb_dma, GFP_KERNEL);
>   if (init_fw_cb == NULL) {
>   printk("scsi%ld: %s: Unable to alloc init_cb\n", ha->host_no,
>  __func__);
>@@ -720,7 +719,6 @@ int qla4xxx_get_dhcp_ip_address(struct scsi_qla_host
>* ha)
>   }
> 
>   /* Get Initialize Firmware Control Block. */
>-  memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
>   if (qla4xxx_get_ifcb(ha, _cmd[0], _sts[0], init_fw_cb_dma) !=
>   QLA_SUCCESS) {
>   DEBUG2(printk("scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
>@@ -1342,16 +1340,15 @@ int qla4xxx_about_firmware(struct scsi_qla_host
>*ha)
>   uint32_t mbox_sts[MBOX_REG_COUNT];
>   int status = QLA_ERROR;
> 
>-  about_fw = dma_alloc_coherent(>pdev->dev,
>-sizeof(struct about_fw_info),
>-_fw_dma, GFP_KERNEL);
>+  about_fw = dma_zalloc_coherent(>pdev->dev,
>+ sizeof(struct about_fw_info),
>+ _fw_dma, GFP_KERNEL);
>   if (!about_fw) {
>   DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Unable to alloc memory "
> "for about_fw\n", __func__));
>   return status;
>   }
> 
>-  memset(about_fw, 0, sizeof(struct about_fw_info));
>   memset(_cmd, 0, sizeof(mbox_cmd));
>   memset(_sts, 0, sizeof(mbox_sts));
> 
>diff --git a/drivers/scsi/qla4xxx/ql4_nx.c b/drivers/scsi/qla4xxx/ql4_nx.c
>index e91abb3..968bd85 100644
>--- a/drivers/scsi/qla4xxx/ql4_nx.c
>+++ b/drivers/scsi/qla4xxx/ql4_nx.c
>@@ -4050,15 +4050,14 @@ int qla4_8xxx_get_sys_info(struct scsi_qla_host
>*ha)
>   dma_addr_t sys_info_dma;
>   int status = QLA_ERROR;
> 
>-  sys_info =