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

2018-01-03 Thread Martin K. Petersen

Himanshu,

> Use dma_zalloc_coherent instead of dma_alloc_coherent followed by memset
> 0.

Applied to 4.16/scsi-queue.

-- 
Martin K. Petersen  Oracle Linux Engineering


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(&ha->pdev->dev, sizeof(*sys_info),
>-&sys_info_dma, GFP_KERNEL);
>+  sys_info = dma_zalloc_coherent(&ha->pdev->dev, sizeof(*sys_info),
>+ &sys_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(&ha->pdev->dev,
>-  sizeof(struct addr_ctrl_blk),
>-  &init_fw_cb_dma, GFP_KERNEL);
>+  init_fw_cb = dma_zalloc_coherent(&ha->pdev->dev,
>+   sizeof(struct addr_ctrl_blk),
>+   &init_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(&mbox_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(&ha->pdev->dev,
>-  sizeof(struct addr_ctrl_blk),
>-  &init_fw_cb_dma, GFP_KERNEL);
>+  init_fw_cb = dma_zalloc_coherent(&ha->pdev->dev,
>+   sizeof(struct addr_ctrl_blk),
>+   &init_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, &mbox_cmd[0], &mbox_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(&ha->pdev->dev,
>-sizeof(struct about_fw_info),
>-&about_fw_dma, GFP_KERNEL);
>+  about_fw = dma_zalloc_coherent(&ha->pdev->dev,
>+ sizeof(struct about_fw_info),
>+ &about_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(&mbox_cmd, 0, sizeof(mbox_cmd));
>   memset(&mbox_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 = dma_al

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

2017-12-30 Thread Himanshu Jha
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(&ha->pdev->dev, sizeof(*sys_info),
- &sys_info_dma, GFP_KERNEL);
+   sys_info = dma_zalloc_coherent(&ha->pdev->dev, sizeof(*sys_info),
+  &sys_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(&ha->pdev->dev,
-   sizeof(struct addr_ctrl_blk),
-   &init_fw_cb_dma, GFP_KERNEL);
+   init_fw_cb = dma_zalloc_coherent(&ha->pdev->dev,
+sizeof(struct addr_ctrl_blk),
+&init_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(&mbox_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(&ha->pdev->dev,
-   sizeof(struct addr_ctrl_blk),
-   &init_fw_cb_dma, GFP_KERNEL);
+   init_fw_cb = dma_zalloc_coherent(&ha->pdev->dev,
+sizeof(struct addr_ctrl_blk),
+&init_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, &mbox_cmd[0], &mbox_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(&ha->pdev->dev,
- sizeof(struct about_fw_info),
- &about_fw_dma, GFP_KERNEL);
+   about_fw = dma_zalloc_coherent(&ha->pdev->dev,
+  sizeof(struct about_fw_info),
+  &about_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(&mbox_cmd, 0, sizeof(mbox_cmd));
memset(&mbox_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 = dma_alloc_coherent(&ha->pdev->dev, sizeof(*sys_info),
- &sys_info_d