[RESEND PATCH 2/2] scsi: qedi: Use zeroing allocator instead of allocator/memset

2018-01-09 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 <mcg...@kernel.org>
Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 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_p

[RESEND PATCH 1/2] scsi: bnx2fc: Use zeroing allocator rather than allocator/memset

2018-01-09 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 <mcg...@kernel.org>
Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/scsi/bnx2fc/bnx2fc_hwi.c | 60 +---
 drivers/scsi/bnx2fc/bnx2fc_tgt.c | 51 +++---
 2 files changed, 47 insertions(+), 64 deletions(-)

diff --git a/drivers/scsi/bnx2fc/bnx2fc_hwi.c b/drivers/scsi/bnx2fc/bnx2fc_hwi.c
index 26de61d..e8ae4d6 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_hwi.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_hwi.c
@@ -1857,16 +1857,15 @@ int bnx2fc_setup_task_ctx(struct bnx2fc_hba *hba)
 * entries. Hence the limit with one page is 8192 task context
 * entries.
 */
-   hba->task_ctx_bd_tbl = dma_alloc_coherent(>pcidev->dev,
- PAGE_SIZE,
- >task_ctx_bd_dma,
- GFP_KERNEL);
+   hba->task_ctx_bd_tbl = dma_zalloc_coherent(>pcidev->dev,
+  PAGE_SIZE,
+  >task_ctx_bd_dma,
+  GFP_KERNEL);
if (!hba->task_ctx_bd_tbl) {
printk(KERN_ERR PFX "unable to allocate task context BDT\n");
rc = -1;
goto out;
}
-   memset(hba->task_ctx_bd_tbl, 0, PAGE_SIZE);
 
/*
 * Allocate task_ctx which is an array of pointers pointing to
@@ -1895,16 +1894,15 @@ int bnx2fc_setup_task_ctx(struct bnx2fc_hba *hba)
task_ctx_bdt = (struct regpair *)hba->task_ctx_bd_tbl;
for (i = 0; i < task_ctx_arr_sz; i++) {
 
-   hba->task_ctx[i] = dma_alloc_coherent(>pcidev->dev,
- PAGE_SIZE,
- >task_ctx_dma[i],
- GFP_KERNEL);
+   hba->task_ctx[i] = dma_zalloc_coherent(>pcidev->dev,
+  PAGE_SIZE,
+  >task_ctx_dma[i],
+  GFP_KERNEL);
if (!hba->task_ctx[i]) {
printk(KERN_ERR PFX "unable to alloc task context\n");
rc = -1;
goto out3;
}
-   memset(hba->task_ctx[i], 0, PAGE_SIZE);
addr = (u64)hba->task_ctx_dma[i];
task_ctx_bdt->hi = cpu_to_le32((u64)addr >> 32);
task_ctx_bdt->lo = cpu_to_le32((u32)addr);
@@ -2033,28 +2031,23 @@ static int bnx2fc_allocate_hash_table(struct bnx2fc_hba 
*hba)
}
 
for (i = 0; i < segment_count; ++i) {
-   hba->hash_tbl_segments[i] =
-   dma_alloc_coherent(>pcidev->dev,
-  BNX2FC_HASH_TBL_CHUNK_SIZE,
-  _segment_array[i],
-  GFP_KERNEL);
+   hba->hash_tbl_segments[i] = 
dma_zalloc_coherent(>pcidev->dev,
+   
BNX2FC_HASH_TBL_CHUNK_SIZE,
+   
_segment_array[i],
+   GFP_KERNEL);
if (!hba->hash_tbl_segments[i]) {
printk(KERN_ERR PFX "hash segment alloc failed\n");
goto cleanup_dma;
}
-   memset(hba->hash_tbl_segments[i], 0,
-  BNX2FC_HASH_TBL_CHUNK_SIZE);
}
 
-   hba->hash_tbl_pbl = dma_alloc_coherent(>pcidev->dev,
-  PAGE_SIZE,
-  >hash_tbl_pbl_dma,
-  GFP_KERNEL);
+   hba->hash_tbl_pbl = dma_zalloc_coherent(>pcidev->dev, PAGE_SIZE,
+   >hash_tbl_pbl_dma,
+   GFP_KERNEL);
if (!hba->hash_tbl_pbl) {
printk(KERN_ERR PFX "hash table pbl alloc failed\n");
goto cleanup_dma;
}
-   memset(hba->hash_tbl_pbl, 0, PAGE_SIZE);
 
pbl = hba->hash_tbl_pbl;
for (i = 0; i < segment_count; ++i) {
@@ -2111,27 +2104,26 @@ int bnx2fc_setup_fw_resc(struct bnx2fc_hba *hba)
return -ENOMEM;
 
mem_s

Re: [PATCH] scsi: megaraid: Use zeroing memory allocator than allocator/memset

2018-01-04 Thread Himanshu Jha
Hi Shivashran,

On Thu, Jan 04, 2018 at 04:52:54PM +0530, Shivasharan Srikanteshwara wrote:
> > -Original Message-
> > From: Himanshu Jha [mailto:himanshujha199...@gmail.com]
> > Sent: Saturday, December 30, 2017 9:18 PM
> > To: martin.peter...@oracle.com; j...@linux.vnet.ibm.com
> > Cc: kashyap.de...@broadcom.com; sumit.sax...@broadcom.com;
> > shivasharan.srikanteshw...@broadcom.com;
> > megaraidlinux@broadcom.com; linux-scsi@vger.kernel.org; linux-
> > ker...@vger.kernel.org; mcg...@kernel.org; Himanshu Jha
> > <himanshujha199...@gmail.com>
> > Subject: [PATCH] scsi: megaraid: Use zeroing memory allocator than
> > allocator/memset
> >
> > Use pci_zalloc_consistent for allocating zeroed memory and remove
> > unnecessary memset function.
> >
> > Done using Coccinelle.
> > Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
> > 0-day tested with no failures.
> >
> > Suggested-by: Luis R. Rodriguez <mcg...@kernel.org>
> > Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
> > ---
> >  drivers/scsi/megaraid/megaraid_sas_base.c   | 19 ++-
> >  drivers/scsi/megaraid/megaraid_sas_fusion.c |  5 ++---
> >  2 files changed, 8 insertions(+), 16 deletions(-)
> >
> 
> Hi Himanshu,
> I can see one more allocation done in megasas_get_seq_num() that could
> make use of these changes.

Yes, I missed that case! Thanks for pointing that out.

> Also, there is a driver update patchset that I am planning to post today.
> Adding this patch first might require additional rebasing of this
> patchset.
> Would you be ok if I send a separate patch for this along with the change
> mentioned above once my patch series gets committed?
> That would save me some rebasing effort. :-)

Yeah, sure! I have no objections for it. But this patch was not in the
patchseries that I sent a while ago https://lkml.org/lkml/2017/12/30/77

Thanks
Himanshu Jha


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

2018-01-03 Thread Himanshu Jha
Hello Martin,

On Thu, Jan 04, 2018 at 01:17:52AM -0500, Martin K. Petersen wrote:
> 
> Himanshu,
> 
> > Use dma_zalloc_coherent instead of dma_alloc_coherent followed by
> > memset 0.
> 
> Does not apply to 4.16/scsi-queue. Please resubmit. Thanks!

No problem, I will resend the patch.

scsi: qla4xxx: Use zeroing allocator rather than allocator/memset --Applied
scsi: qla2xxx: Use zeroing allocator rather than allocator/memset --Applied
scsi: qedi: Use zeroing allocator instead of allocator/memset --Resend
scsi: mvsas: Use zeroing allocator rather than allocator/memset
scsi: fnic: Use zeroing allocator rather than allocator/memset
scsi: dpt_i2o: Use zeroing allocator rather than allocator/memset
scsi: bnx2fc: Use zeroing allocator rather than allocator/memset --Resend
scsi: bfa: Use zeroing allocator rather than allocator/memset --Applied
scsi: bnx2i: Use zeroing allocator rather than allocator/memset --Applied

But do I also need to send those mentioned above, which didn't receive
any response from you ?

Also, I later sent a patch for fnic after this series which can be
applied after or before this series whichever is suitable to you.

Thanks
Himanshu Jha


[PATCH] scsi: fnic: Use eth_broadcast_addr instead of memset

2017-12-30 Thread Himanshu Jha
Use eth_broadcasr_addr Networking API instead of memset to assign the
broadcast address to the given address array.

0-day tested with no failures.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/scsi/fnic/fnic_scsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/fnic/fnic_scsi.c b/drivers/scsi/fnic/fnic_scsi.c
index 242e2ee..e51dc72 100644
--- a/drivers/scsi/fnic/fnic_scsi.c
+++ b/drivers/scsi/fnic/fnic_scsi.c
@@ -276,7 +276,7 @@ int fnic_flogi_reg_handler(struct fnic *fnic, u32 fc_id)
}
 
if (fnic->ctlr.map_dest) {
-   memset(gw_mac, 0xff, ETH_ALEN);
+   eth_broadcast_addr(gw_mac);
format = FCPIO_FLOGI_REG_DEF_DEST;
} else {
memcpy(gw_mac, fnic->ctlr.dest_addr, ETH_ALEN);
-- 
2.7.4



[PATCH] scsi: megaraid: Use zeroing memory allocator than allocator/memset

2017-12-30 Thread Himanshu Jha
Use pci_zalloc_consistent for allocating zeroed
memory and remove unnecessary memset function.

Done using Coccinelle.
Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
0-day tested with no failures.

Suggested-by: Luis R. Rodriguez <mcg...@kernel.org>
Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/scsi/megaraid/megaraid_sas_base.c   | 19 ++-
 drivers/scsi/megaraid/megaraid_sas_fusion.c |  5 ++---
 2 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c 
b/drivers/scsi/megaraid/megaraid_sas_base.c
index 2c8cfa2..62959d0 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -,10 +,9 @@ static int megasas_get_ld_vf_affiliation_111(struct 
megasas_instance *instance,
memset(instance->vf_affiliation_111, 0,
   sizeof(struct MR_LD_VF_AFFILIATION_111));
else {
-   new_affiliation_111 =
-   pci_alloc_consistent(instance->pdev,
-sizeof(struct 
MR_LD_VF_AFFILIATION_111),
-_affiliation_111_h);
+   new_affiliation_111 =
+   pci_zalloc_consistent(instance->pdev,
+   sizeof(struct MR_LD_VF_AFFILIATION_111),
+   _affiliation_111_h);
if (!new_affiliation_111) {
dev_printk(KERN_DEBUG, >pdev->dev, "SR-IOV: 
Couldn't allocate "
   "memory for new affiliation for scsi%d\n",
@@ -2233,8 +2232,6 @@ static int megasas_get_ld_vf_affiliation_111(struct 
megasas_instance *instance,
megasas_return_cmd(instance, cmd);
return -ENOMEM;
}
-   memset(new_affiliation_111, 0,
-  sizeof(struct MR_LD_VF_AFFILIATION_111));
}
 
memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
@@ -2331,11 +2328,9 @@ static int megasas_get_ld_vf_affiliation_12(struct 
megasas_instance *instance,
memset(instance->vf_affiliation, 0, (MAX_LOGICAL_DRIVES + 1) *
   sizeof(struct MR_LD_VF_AFFILIATION));
else {
-   new_affiliation =
-   pci_alloc_consistent(instance->pdev,
-(MAX_LOGICAL_DRIVES + 1) *
-sizeof(struct 
MR_LD_VF_AFFILIATION),
-_affiliation_h);
+   new_affiliation =
+   pci_zalloc_consistent(instance->pdev,
+   (MAX_LOGICAL_DRIVES + 1) *
+   sizeof(struct 
MR_LD_VF_AFFILIATION),
+   _affiliation_h);
if (!new_affiliation) {
dev_printk(KERN_DEBUG, >pdev->dev, "SR-IOV: 
Couldn't allocate "
   "memory for new affiliation for scsi%d\n",
@@ -2343,8 +2338,6 @@ static int megasas_get_ld_vf_affiliation_12(struct 
megasas_instance *instance,
megasas_return_cmd(instance, cmd);
return -ENOMEM;
}
-   memset(new_affiliation, 0, (MAX_LOGICAL_DRIVES + 1) *
-  sizeof(struct MR_LD_VF_AFFILIATION));
}
 
memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c 
b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 65dc4fe..5f61b93 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -690,15 +690,14 @@ megasas_alloc_rdpq_fusion(struct megasas_instance 
*instance)
array_size = sizeof(struct MPI2_IOC_INIT_RDPQ_ARRAY_ENTRY) *
 MAX_MSIX_QUEUES_FUSION;
 
-   fusion->rdpq_virt = pci_alloc_consistent(instance->pdev, array_size,
->rdpq_phys);
+   fusion->rdpq_virt = pci_zalloc_consistent(instance->pdev, array_size,
+ >rdpq_phys);
if (!fusion->rdpq_virt) {
dev_err(>pdev->dev,
"Failed from %s %d\n",  __func__, __LINE__);
return -ENOMEM;
}
 
-   memset(fusion->rdpq_virt, 0, array_size);
msix_count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
 
fusion->reply_frames_desc_pool = dma_pool_create("mr_rdpq",
-- 
2.7.4



[PATCH 2/9] scsi: qla2xxx: Use zeroing allocator rather than allocator/memset

2017-12-30 Thread Himanshu Jha
Use dma_zalloc_coherent and vzalloc instead of dma_alloc_coherent and
vmalloc respectively, followed by memset 0.

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

Suggested-by: Luis R. Rodriguez <mcg...@kernel.org>
Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/scsi/qla2xxx/qla_attr.c| 5 ++---
 drivers/scsi/qla2xxx/qla_bsg.c | 9 +++--
 drivers/scsi/qla2xxx/tcm_qla2xxx.c | 5 +
 3 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index 9ce28c4..f46b015 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -1843,14 +1843,13 @@ qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
if (qla2x00_reset_active(vha))
goto done;
 
-   stats = dma_alloc_coherent(>pdev->dev,
-   sizeof(*stats), _dma, GFP_KERNEL);
+   stats = dma_zalloc_coherent(>pdev->dev, sizeof(*stats),
+   _dma, GFP_KERNEL);
if (!stats) {
ql_log(ql_log_warn, vha, 0x707d,
"Failed to allocate memory for stats.\n");
goto done;
}
-   memset(stats, 0, sizeof(*stats));
 
rval = QLA_FUNCTION_FAILED;
if (IS_FWI2_CAPABLE(ha)) {
diff --git a/drivers/scsi/qla2xxx/qla_bsg.c b/drivers/scsi/qla2xxx/qla_bsg.c
index e3ac707..e2d5d3c 100644
--- a/drivers/scsi/qla2xxx/qla_bsg.c
+++ b/drivers/scsi/qla2xxx/qla_bsg.c
@@ -1435,7 +1435,7 @@ qla2x00_optrom_setup(struct bsg_job *bsg_job, 
scsi_qla_host_t *vha,
ha->optrom_state = QLA_SREADING;
}
 
-   ha->optrom_buffer = vmalloc(ha->optrom_region_size);
+   ha->optrom_buffer = vzalloc(ha->optrom_region_size);
if (!ha->optrom_buffer) {
ql_log(ql_log_warn, vha, 0x7059,
"Read: Unable to allocate memory for optrom retrieval "
@@ -1445,7 +1445,6 @@ qla2x00_optrom_setup(struct bsg_job *bsg_job, 
scsi_qla_host_t *vha,
return -ENOMEM;
}
 
-   memset(ha->optrom_buffer, 0, ha->optrom_region_size);
return 0;
 }
 
@@ -2314,16 +2313,14 @@ qla2x00_get_priv_stats(struct bsg_job *bsg_job)
if (!IS_FWI2_CAPABLE(ha))
return -EPERM;
 
-   stats = dma_alloc_coherent(>pdev->dev,
-   sizeof(*stats), _dma, GFP_KERNEL);
+   stats = dma_zalloc_coherent(>pdev->dev, sizeof(*stats),
+   _dma, GFP_KERNEL);
if (!stats) {
ql_log(ql_log_warn, vha, 0x70e2,
"Failed to allocate memory for stats.\n");
return -ENOMEM;
}
 
-   memset(stats, 0, sizeof(*stats));
-
rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma, options);
 
if (rval == QLA_SUCCESS) {
diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.c 
b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
index 3f82ea1..aadfeaa 100644
--- a/drivers/scsi/qla2xxx/tcm_qla2xxx.c
+++ b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
@@ -1635,16 +1635,13 @@ static int tcm_qla2xxx_init_lport(struct 
tcm_qla2xxx_lport *lport)
return rc;
}
 
-   lport->lport_loopid_map = vmalloc(sizeof(struct tcm_qla2xxx_fc_loopid) *
-   65536);
+   lport->lport_loopid_map = vzalloc(sizeof(struct tcm_qla2xxx_fc_loopid) 
* 65536);
if (!lport->lport_loopid_map) {
pr_err("Unable to allocate lport->lport_loopid_map of %zu 
bytes\n",
sizeof(struct tcm_qla2xxx_fc_loopid) * 65536);
btree_destroy32(>lport_fcport_map);
return -ENOMEM;
}
-   memset(lport->lport_loopid_map, 0, sizeof(struct tcm_qla2xxx_fc_loopid)
-  * 65536);
pr_debug("qla2xxx: Allocated lport_loopid_map of %zu bytes\n",
   sizeof(struct tcm_qla2xxx_fc_loopid) * 65536);
return 0;
-- 
2.7.4



[PATCH 3/9] scsi: qedi: Use zeroing allocator instead of 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 <mcg...@kernel.org>
Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 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,
+ 

[PATCH 9/9] scsi: bnx2i: 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 <mcg...@kernel.org>
Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 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



[PATCH 5/9] scsi: fnic: Use zeroing allocator rather than allocator/memset

2017-12-30 Thread Himanshu Jha
Use vzalloc instead of vmalloc followed by memset 0.

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

Suggested-by: Luis R. Rodriguez <mcg...@kernel.org>
Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/scsi/fnic/fnic_debugfs.c | 10 ++
 drivers/scsi/fnic/fnic_trace.c   |  9 ++---
 2 files changed, 4 insertions(+), 15 deletions(-)

diff --git a/drivers/scsi/fnic/fnic_debugfs.c b/drivers/scsi/fnic/fnic_debugfs.c
index 9858484..ec249bd 100644
--- a/drivers/scsi/fnic/fnic_debugfs.c
+++ b/drivers/scsi/fnic/fnic_debugfs.c
@@ -233,24 +233,18 @@ static int fnic_trace_debugfs_open(struct inode *inode,
return -ENOMEM;
 
if (*rdata_ptr == fc_trc_flag->fnic_trace) {
-   fnic_dbg_prt->buffer = vmalloc(3 *
-   (trace_max_pages * PAGE_SIZE));
+   fnic_dbg_prt->buffer = vzalloc(3 *
+   (trace_max_pages * PAGE_SIZE));
if (!fnic_dbg_prt->buffer) {
kfree(fnic_dbg_prt);
return -ENOMEM;
}
-   memset((void *)fnic_dbg_prt->buffer, 0,
-   3 * (trace_max_pages * PAGE_SIZE));
fnic_dbg_prt->buffer_len = fnic_get_trace_data(fnic_dbg_prt);
} else {
-   fnic_dbg_prt->buffer =
-   vmalloc(3 * (fnic_fc_trace_max_pages * PAGE_SIZE));
+   fnic_dbg_prt->buffer =
+   vzalloc(3 * (fnic_fc_trace_max_pages * PAGE_SIZE));
if (!fnic_dbg_prt->buffer) {
kfree(fnic_dbg_prt);
return -ENOMEM;
}
-   memset((void *)fnic_dbg_prt->buffer, 0,
-   3 * (fnic_fc_trace_max_pages * PAGE_SIZE));
fnic_dbg_prt->buffer_len =
fnic_fc_trace_get_data(fnic_dbg_prt, *rdata_ptr);
}
diff --git a/drivers/scsi/fnic/fnic_trace.c b/drivers/scsi/fnic/fnic_trace.c
index 4826f59..e63285e 100644
--- a/drivers/scsi/fnic/fnic_trace.c
+++ b/drivers/scsi/fnic/fnic_trace.c
@@ -468,14 +468,13 @@ int fnic_trace_buf_init(void)
fnic_max_trace_entries = (trace_max_pages * PAGE_SIZE)/
  FNIC_ENTRY_SIZE_BYTES;
 
-   fnic_trace_buf_p = (unsigned long)vmalloc((trace_max_pages * 
PAGE_SIZE));
+   fnic_trace_buf_p = (unsigned long)vzalloc((trace_max_pages
+   * PAGE_SIZE));
if (!fnic_trace_buf_p) {
printk(KERN_ERR PFX "Failed to allocate memory "
  "for fnic_trace_buf_p\n");
err = -ENOMEM;
goto err_fnic_trace_buf_init;
}
-   memset((void *)fnic_trace_buf_p, 0, (trace_max_pages * PAGE_SIZE));
 
fnic_trace_entries.page_offset = vmalloc(fnic_max_trace_entries *
  sizeof(unsigned long));
@@ -555,8 +554,7 @@ int fnic_fc_trace_init(void)
 
fc_trace_max_entries = (fnic_fc_trace_max_pages * PAGE_SIZE)/
FC_TRC_SIZE_BYTES;
-   fnic_fc_ctlr_trace_buf_p = (unsigned long)vmalloc(
-   fnic_fc_trace_max_pages * PAGE_SIZE);
+   fnic_fc_ctlr_trace_buf_p = (unsigned long)vzalloc(
+   fnic_fc_trace_max_pages * PAGE_SIZE);
if (!fnic_fc_ctlr_trace_buf_p) {
pr_err("fnic: Failed to allocate memory for "
   "FC Control Trace Buf\n");
@@ -564,9 +562,6 @@ int fnic_fc_trace_init(void)
goto err_fnic_fc_ctlr_trace_buf_init;
}
 
-   memset((void *)fnic_fc_ctlr_trace_buf_p, 0,
-   fnic_fc_trace_max_pages * PAGE_SIZE);
-
/* Allocate memory for page offset */
fc_trace_entries.page_offset = vmalloc(fc_trace_max_entries *
sizeof(unsigned long));
-- 
2.7.4



[PATCH 7/9] scsi: bnx2fc: 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 <mcg...@kernel.org>
Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/scsi/bnx2fc/bnx2fc_hwi.c | 60 +---
 drivers/scsi/bnx2fc/bnx2fc_tgt.c | 51 +++---
 2 files changed, 47 insertions(+), 64 deletions(-)

diff --git a/drivers/scsi/bnx2fc/bnx2fc_hwi.c b/drivers/scsi/bnx2fc/bnx2fc_hwi.c
index 26de61d..e8ae4d6 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_hwi.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_hwi.c
@@ -1857,16 +1857,15 @@ int bnx2fc_setup_task_ctx(struct bnx2fc_hba *hba)
 * entries. Hence the limit with one page is 8192 task context
 * entries.
 */
-   hba->task_ctx_bd_tbl = dma_alloc_coherent(>pcidev->dev,
- PAGE_SIZE,
- >task_ctx_bd_dma,
- GFP_KERNEL);
+   hba->task_ctx_bd_tbl = dma_zalloc_coherent(>pcidev->dev,
+  PAGE_SIZE,
+  >task_ctx_bd_dma,
+  GFP_KERNEL);
if (!hba->task_ctx_bd_tbl) {
printk(KERN_ERR PFX "unable to allocate task context BDT\n");
rc = -1;
goto out;
}
-   memset(hba->task_ctx_bd_tbl, 0, PAGE_SIZE);
 
/*
 * Allocate task_ctx which is an array of pointers pointing to
@@ -1895,16 +1894,15 @@ int bnx2fc_setup_task_ctx(struct bnx2fc_hba *hba)
task_ctx_bdt = (struct regpair *)hba->task_ctx_bd_tbl;
for (i = 0; i < task_ctx_arr_sz; i++) {
 
-   hba->task_ctx[i] = dma_alloc_coherent(>pcidev->dev,
- PAGE_SIZE,
- >task_ctx_dma[i],
- GFP_KERNEL);
+   hba->task_ctx[i] = dma_zalloc_coherent(>pcidev->dev,
+  PAGE_SIZE,
+  >task_ctx_dma[i],
+  GFP_KERNEL);
if (!hba->task_ctx[i]) {
printk(KERN_ERR PFX "unable to alloc task context\n");
rc = -1;
goto out3;
}
-   memset(hba->task_ctx[i], 0, PAGE_SIZE);
addr = (u64)hba->task_ctx_dma[i];
task_ctx_bdt->hi = cpu_to_le32((u64)addr >> 32);
task_ctx_bdt->lo = cpu_to_le32((u32)addr);
@@ -2033,28 +2031,23 @@ static int bnx2fc_allocate_hash_table(struct bnx2fc_hba 
*hba)
}
 
for (i = 0; i < segment_count; ++i) {
-   hba->hash_tbl_segments[i] =
-   dma_alloc_coherent(>pcidev->dev,
-  BNX2FC_HASH_TBL_CHUNK_SIZE,
-  _segment_array[i],
-  GFP_KERNEL);
+   hba->hash_tbl_segments[i] =
+dma_zalloc_coherent(>pcidev->dev,
+   BNX2FC_HASH_TBL_CHUNK_SIZE,
+   _segment_array[i],
+   GFP_KERNEL);
if (!hba->hash_tbl_segments[i]) {
printk(KERN_ERR PFX "hash segment alloc failed\n");
goto cleanup_dma;
}
-   memset(hba->hash_tbl_segments[i], 0,
-  BNX2FC_HASH_TBL_CHUNK_SIZE);
}
 
-   hba->hash_tbl_pbl = dma_alloc_coherent(>pcidev->dev,
-  PAGE_SIZE,
-  >hash_tbl_pbl_dma,
-  GFP_KERNEL);
+   hba->hash_tbl_pbl = dma_zalloc_coherent(>pcidev->dev, PAGE_SIZE,
+   >hash_tbl_pbl_dma,
+   GFP_KERNEL);
if (!hba->hash_tbl_pbl) {
printk(KERN_ERR PFX "hash table pbl alloc failed\n");
goto cleanup_dma;
}
-   memset(hba->hash_tbl_pbl, 0, PAGE_SIZE);
 
pbl = hba->hash_tbl_pbl;
for (i = 0; i < segment_count; ++i) {
@@ -2111,27 +2104,26 @@ int bnx2fc_setup_fw_resc(struct bnx2fc_hba *hba)
return -ENOMEM;
 
mem_size = BNX2FC_NUM_MAX_SESS * sizeof(struct regpair);
-   hba->t2_hash_

[PATCH 4/9] scsi: mvsas: 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 <mcg...@kernel.org>
Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/scsi/mvsas/mv_init.c | 27 +++
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/drivers/scsi/mvsas/mv_init.c b/drivers/scsi/mvsas/mv_init.c
index 8c91637..6748394 100644
--- a/drivers/scsi/mvsas/mv_init.c
+++ b/drivers/scsi/mvsas/mv_init.c
@@ -253,33 +253,28 @@ static int mvs_alloc(struct mvs_info *mvi, struct 
Scsi_Host *shost)
/*
 * alloc and init our DMA areas
 */
-   mvi->tx = dma_alloc_coherent(mvi->dev,
-sizeof(*mvi->tx) * MVS_CHIP_SLOT_SZ,
->tx_dma, GFP_KERNEL);
+   mvi->tx = dma_zalloc_coherent(mvi->dev,
+ sizeof(*mvi->tx) * MVS_CHIP_SLOT_SZ,
+ >tx_dma, GFP_KERNEL);
if (!mvi->tx)
goto err_out;
-   memset(mvi->tx, 0, sizeof(*mvi->tx) * MVS_CHIP_SLOT_SZ);
-   mvi->rx_fis = dma_alloc_coherent(mvi->dev, MVS_RX_FISL_SZ,
->rx_fis_dma, GFP_KERNEL);
+   mvi->rx_fis = dma_zalloc_coherent(mvi->dev, MVS_RX_FISL_SZ,
+ >rx_fis_dma, GFP_KERNEL);
if (!mvi->rx_fis)
goto err_out;
-   memset(mvi->rx_fis, 0, MVS_RX_FISL_SZ);
-
-   mvi->rx = dma_alloc_coherent(mvi->dev,
-sizeof(*mvi->rx) * (MVS_RX_RING_SZ + 1),
->rx_dma, GFP_KERNEL);
+   mvi->rx = dma_zalloc_coherent(mvi->dev,
+ sizeof(*mvi->rx) * (MVS_RX_RING_SZ + 1),
+ >rx_dma, GFP_KERNEL);
if (!mvi->rx)
goto err_out;
-   memset(mvi->rx, 0, sizeof(*mvi->rx) * (MVS_RX_RING_SZ + 1));
mvi->rx[0] = cpu_to_le32(0xfff);
mvi->rx_cons = 0xfff;
 
-   mvi->slot = dma_alloc_coherent(mvi->dev,
-  sizeof(*mvi->slot) * slot_nr,
-  >slot_dma, GFP_KERNEL);
+   mvi->slot = dma_zalloc_coherent(mvi->dev,
+   sizeof(*mvi->slot) * slot_nr,
+   >slot_dma, GFP_KERNEL);
if (!mvi->slot)
goto err_out;
-   memset(mvi->slot, 0, sizeof(*mvi->slot) * slot_nr);
 
mvi->bulk_buffer = dma_alloc_coherent(mvi->dev,
   TRASH_BUCKET_SIZE,
-- 
2.7.4



[PATCH 6/9] scsi: dpt_i2o: 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 <mcg...@kernel.org>
Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/scsi/dpt_i2o.c | 19 ---
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
index fd172b0..67cd777 100644
--- a/drivers/scsi/dpt_i2o.c
+++ b/drivers/scsi/dpt_i2o.c
@@ -1371,13 +1371,12 @@ static s32 adpt_i2o_reset_hba(adpt_hba* pHba)
schedule_timeout_uninterruptible(1);
} while (m == EMPTY_QUEUE);
 
-   status = dma_alloc_coherent(>pDev->dev, 4, , GFP_KERNEL);
+   status = dma_zalloc_coherent(>pDev->dev, 4, , GFP_KERNEL);
if(status == NULL) {
adpt_send_nop(pHba, m);
printk(KERN_ERR"IOP reset failed - no free memory.\n");
return -ENOMEM;
}
-   memset(status,0,4);
 
msg[0]=EIGHT_WORD_MSG_SIZE|SGL_OFFSET_0;
msg[1]=I2O_CMD_ADAPTER_RESET<<24|HOST_TID<<12|ADAPTER_TID;
@@ -2827,14 +2826,13 @@ static s32 adpt_i2o_init_outbound_q(adpt_hba* pHba)
 
msg=(u32 __iomem *)(pHba->msg_addr_virt+m);
 
-   status = dma_alloc_coherent(>pDev->dev, 4, , GFP_KERNEL);
+   status = dma_zalloc_coherent(>pDev->dev, 4, , GFP_KERNEL);
if (!status) {
adpt_send_nop(pHba, m);
printk(KERN_WARNING"%s: IOP reset failed - no free memory.\n",
pHba->name);
return -ENOMEM;
}
-   memset(status, 0, 4);
 
writel(EIGHT_WORD_MSG_SIZE| SGL_OFFSET_6, [0]);
writel(I2O_CMD_OUTBOUND_INIT<<24 | HOST_TID<<12 | ADAPTER_TID, [1]);
@@ -2881,14 +2879,14 @@ static s32 adpt_i2o_init_outbound_q(adpt_hba* pHba)
pHba->reply_pool, pHba->reply_pool_pa);
}
 
-   pHba->reply_pool = dma_alloc_coherent(>pDev->dev,
-   pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4,
-   >reply_pool_pa, GFP_KERNEL);
+   pHba->reply_pool = dma_zalloc_coherent(>pDev->dev,
+   pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4,
+   >reply_pool_pa, GFP_KERNEL);
if (!pHba->reply_pool) {
printk(KERN_ERR "%s: Could not allocate reply pool\n", 
pHba->name);
return -ENOMEM;
}
-   memset(pHba->reply_pool, 0 , pHba->reply_fifo_size * REPLY_FRAME_SIZE * 
4);
 
for(i = 0; i < pHba->reply_fifo_size; i++) {
writel(pHba->reply_pool_pa + (i * REPLY_FRAME_SIZE * 4),
@@ -3117,13 +3115,12 @@ static int adpt_i2o_build_sys_table(void)
sys_tbl_len = sizeof(struct i2o_sys_tbl) +  // Header + IOPs
(hba_count) * sizeof(struct i2o_sys_tbl_entry);
 
-   sys_tbl = dma_alloc_coherent(>pDev->dev,
-   sys_tbl_len, _tbl_pa, GFP_KERNEL);
+   sys_tbl = dma_zalloc_coherent(>pDev->dev, sys_tbl_len,
+ _tbl_pa, GFP_KERNEL);
if (!sys_tbl) {
printk(KERN_WARNING "SysTab Set failed. Out of memory.\n"); 
return -ENOMEM;
}
-   memset(sys_tbl, 0, sys_tbl_len);
 
sys_tbl->num_entries = hba_count;
sys_tbl->version = I2OVERSION;
-- 
2.7.4



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

2017-12-30 Thread Himanshu Jha
Use vzalloc instead of vmalloc followed by memset 0.

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

Suggested-by: Luis R. Rodriguez <mcg...@kernel.org>
Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 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



[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 <mcg...@kernel.org>
Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 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 = dma_alloc_coherent(&g

[PATCH 0/9] scsi: Use zeroing allocators than allocator/memset

2017-12-30 Thread Himanshu Jha
There are many instances where a region of memory is allocated using
allocator functions and immediately the region of memory is zeroed using
memset function.

We already have zeroing memory allocator function for that purpose and
replacing the currently used allocator functions with zeroing allocators
will make code cleaner, easier to read, and also reduce the code size.

For eg:

Before:
himanshu@himanshu-Vostro-3559:~/linux-next$ size 
drivers/scsi/bnx2fc/bnx2fc_hwi.o
   textdata bss dec hex filename
  407835940  64   46787b6c3 drivers/scsi/bnx2fc/bnx2fc_hwi.o

After: 
himanshu@himanshu-Vostro-3559:~/linux-next$ size 
drivers/scsi/bnx2fc/bnx2fc_hwi.o
   textdata bss dec hex filename
  406195940  64   46623b61f drivers/scsi/bnx2fc/bnx2fc_hwi.o

Also, all these patches have been tested using 0-day test service with
zero build failures.

Done using Coccinelle.
Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
Link: https://lkml.org/lkml/2017/12/26/205

Himanshu Jha (9):
  scsi: qla4xxx: Use zeroing allocator rather than allocator/memset
  scsi: qla2xxx: Use zeroing allocator rather than allocator/memset
  scsi: qedi: Use zeroing allocator instead of allocator/memset
  scsi: mvsas: Use zeroing allocator rather than allocator/memset
  scsi: fnic: Use zeroing allocator rather than allocator/memset
  scsi: dpt_i2o: Use zeroing allocator rather than allocator/memset
  scsi: bnx2fc: Use zeroing allocator rather than allocator/memset
  scsi: bfa: Use zeroing allocator rather than allocator/memset
  scsi: bnx2i: Use zeroing allocator rather than allocator/memset

 drivers/scsi/bfa/bfad.c|  3 +-
 drivers/scsi/bfa/bfad_debugfs.c|  8 ++---
 drivers/scsi/bnx2fc/bnx2fc_hwi.c   | 60 --
 drivers/scsi/bnx2fc/bnx2fc_tgt.c   | 51 ++--
 drivers/scsi/bnx2i/bnx2i_hwi.c | 14 -
 drivers/scsi/dpt_i2o.c | 19 +---
 drivers/scsi/fnic/fnic_debugfs.c   | 10 ++-
 drivers/scsi/fnic/fnic_trace.c |  9 ++
 drivers/scsi/mvsas/mv_init.c   | 27 +++--
 drivers/scsi/qedi/qedi_main.c  | 42 ++
 drivers/scsi/qla2xxx/qla_attr.c|  5 ++--
 drivers/scsi/qla2xxx/qla_bsg.c |  9 ++
 drivers/scsi/qla2xxx/tcm_qla2xxx.c |  5 +---
 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 
 17 files changed, 118 insertions(+), 187 deletions(-)

-- 
2.7.4



Re: [PATCH] scsi: Use vzalloc instead of vmalloc/memset

2017-11-07 Thread Himanshu Jha
On Tue, Nov 07, 2017 at 08:51:36PM +0100, Luis R. Rodriguez wrote:
> On Sun, Nov 05, 2017 at 03:26:26AM +0530, Himanshu Jha wrote:
> > Use vzalloc instead of vmalloc/memset to allocate memory filled with 0
> > value.
> > 
> > Done using Coccinelle.
> > Semantic patch used :
> > 
> > @@
> > expression x,a;
> > statement S;
> > @@
> > 
> > - x = vmalloc(a);
> > + x = vzalloc(a);
> >   if (x == NULL || ...) S
> > - memset(x, 0, a);
> 
> How many false positives do you get? Have you identified any?
> If not you should consider adding this SmPL rule to:
> 
> scripts/coccinelle/api/
> 
> Some maintainers may ask you for the SmPL rule to be upstream first,
> not all though. So its good practice for you to strive for this.
> Another reason for it to go upstream is then other maintainers
> can / should be running coccicheck against their subsystem to avoid
> stupid regressions.
> 
> You may want to explain for patches like these that they have been
> tested by 0-day without any issues found.
> 
> Also add the tag:
> 
> Generated-by: Coccinelle SmPL
> 
> > Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
> > ---
> >  drivers/scsi/bfa/bfad.c| 3 +--
> >  drivers/scsi/bfa/bfad_debugfs.c| 8 ++--
> >  drivers/scsi/qla2xxx/qla_bsg.c | 3 +--
> >  drivers/scsi/qla2xxx/tcm_qla2xxx.c | 5 +
> >  drivers/scsi/scsi_debug.c  | 6 ++
> >  drivers/scsi/snic/snic_trc.c   | 3 +--
> >  6 files changed, 8 insertions(+), 20 deletions(-)
> 
> Split this up per driver, and resend by using ./scripts/get_maintainer.pl
> foo.patch and ensuring the right folks get the email.  Right now you 
> just spammed tons of people and the changes may be preferred to go
> upstream atomically per driver, always assume this first.
> 
> Other than this, feel free to add to each of the patches you created:
> 

Thanks for the feeedback! I will resend the patch with the necessary
changes.

> Acked-by: Luis R. Rodriguez <mcg...@kernel.org>


Thanks
Himanshu Jha


[PATCH] scsi: Remove null check before kfree

2017-11-06 Thread Himanshu Jha
Kfree on NULL pointer is a no-op and therefore checking is redundant.

Done using Coccinelle.
Semantic patch used :

@@ expression E; @@
- if (E != NULL) { kfree(E); }
+ kfree(E);
@@ expression E; @@
- if (E != NULL) { kfree(E); E = NULL; }
+ kfree(E);
+ E = NULL;


Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/scsi/aic7xxx/aic79xx_core.c | 15 +--
 drivers/scsi/aic7xxx/aic7xxx_core.c | 15 +--
 drivers/scsi/aic94xx/aic94xx_init.c |  9 +++--
 drivers/scsi/lpfc/lpfc_bsg.c|  3 +--
 drivers/scsi/lpfc/lpfc_init.c   |  6 ++
 drivers/scsi/megaraid/megaraid_sas_fusion.c |  3 +--
 drivers/scsi/qedf/qedf_main.c   |  3 +--
 drivers/scsi/qla2xxx/qla_os.c   | 12 
 8 files changed, 22 insertions(+), 44 deletions(-)

diff --git a/drivers/scsi/aic7xxx/aic79xx_core.c 
b/drivers/scsi/aic7xxx/aic79xx_core.c
index b560f39..7ad1df5 100644
--- a/drivers/scsi/aic7xxx/aic79xx_core.c
+++ b/drivers/scsi/aic7xxx/aic79xx_core.c
@@ -3681,8 +3681,7 @@ ahd_free_tstate(struct ahd_softc *ahd, u_int scsi_id, 
char channel, int force)
return;
 
tstate = ahd->enabled_targets[scsi_id];
-   if (tstate != NULL)
-   kfree(tstate);
+   kfree(tstate);
ahd->enabled_targets[scsi_id] = NULL;
 }
 #endif
@@ -6144,8 +6143,7 @@ ahd_set_unit(struct ahd_softc *ahd, int unit)
 void
 ahd_set_name(struct ahd_softc *ahd, char *name)
 {
-   if (ahd->name != NULL)
-   kfree(ahd->name);
+   kfree(ahd->name);
ahd->name = name;
 }
 
@@ -6212,12 +6210,9 @@ ahd_free(struct ahd_softc *ahd)
kfree(ahd->black_hole);
}
 #endif
-   if (ahd->name != NULL)
-   kfree(ahd->name);
-   if (ahd->seep_config != NULL)
-   kfree(ahd->seep_config);
-   if (ahd->saved_stack != NULL)
-   kfree(ahd->saved_stack);
+   kfree(ahd->name);
+   kfree(ahd->seep_config);
+   kfree(ahd->saved_stack);
 #ifndef __FreeBSD__
kfree(ahd);
 #endif
diff --git a/drivers/scsi/aic7xxx/aic7xxx_core.c 
b/drivers/scsi/aic7xxx/aic7xxx_core.c
index 6612ff3..9c46c6d 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_core.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_core.c
@@ -2200,8 +2200,7 @@ ahc_free_tstate(struct ahc_softc *ahc, u_int scsi_id, 
char channel, int force)
if (channel == 'B')
scsi_id += 8;
tstate = ahc->enabled_targets[scsi_id];
-   if (tstate != NULL)
-   kfree(tstate);
+   kfree(tstate);
ahc->enabled_targets[scsi_id] = NULL;
 }
 #endif
@@ -4481,8 +4480,7 @@ ahc_set_unit(struct ahc_softc *ahc, int unit)
 void
 ahc_set_name(struct ahc_softc *ahc, char *name)
 {
-   if (ahc->name != NULL)
-   kfree(ahc->name);
+   kfree(ahc->name);
ahc->name = name;
 }
 
@@ -4549,10 +4547,8 @@ ahc_free(struct ahc_softc *ahc)
kfree(ahc->black_hole);
}
 #endif
-   if (ahc->name != NULL)
-   kfree(ahc->name);
-   if (ahc->seep_config != NULL)
-   kfree(ahc->seep_config);
+   kfree(ahc->name);
+   kfree(ahc->seep_config);
 #ifndef __FreeBSD__
kfree(ahc);
 #endif
@@ -4957,8 +4953,7 @@ ahc_fini_scbdata(struct ahc_softc *ahc)
case 0:
break;
}
-   if (scb_data->scbarray != NULL)
-   kfree(scb_data->scbarray);
+   kfree(scb_data->scbarray);
 }
 
 static void
diff --git a/drivers/scsi/aic94xx/aic94xx_init.c 
b/drivers/scsi/aic94xx/aic94xx_init.c
index 6c83886..778df1a 100644
--- a/drivers/scsi/aic94xx/aic94xx_init.c
+++ b/drivers/scsi/aic94xx/aic94xx_init.c
@@ -584,8 +584,7 @@ static void asd_destroy_ha_caches(struct asd_ha_struct 
*asd_ha)
if (asd_ha->hw_prof.scb_ext)
asd_free_coherent(asd_ha, asd_ha->hw_prof.scb_ext);
 
-   if (asd_ha->hw_prof.ddb_bitmap)
-   kfree(asd_ha->hw_prof.ddb_bitmap);
+   kfree(asd_ha->hw_prof.ddb_bitmap);
asd_ha->hw_prof.ddb_bitmap = NULL;
 
for (i = 0; i < ASD_MAX_PHYS; i++) {
@@ -597,10 +596,8 @@ static void asd_destroy_ha_caches(struct asd_ha_struct 
*asd_ha)
asd_free_escbs(asd_ha);
if (asd_ha->seq.edb_arr)
asd_free_edbs(asd_ha);
-   if (asd_ha->hw_prof.ue.area) {
-   kfree(asd_ha->hw_prof.ue.area);
-   asd_ha->hw_prof.ue.area = NULL;
-   }
+   kfree(asd_ha->hw_prof.ue.area);
+   asd_ha->hw_prof.ue.area = NULL;
if (asd_ha->seq.tc_index_array) {
kfree(asd_ha->seq.tc_index_array);
kfree(asd_ha->seq.tc_index_bitmap);
diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index d898162..3860df0 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/d

[PATCH] scsi: Use vzalloc instead of vmalloc/memset

2017-11-04 Thread Himanshu Jha
Use vzalloc instead of vmalloc/memset to allocate memory filled with 0
value.

Done using Coccinelle.
Semantic patch used :

@@
expression x,a;
statement S;
@@

- x = vmalloc(a);
+ x = vzalloc(a);
  if (x == NULL || ...) S
- memset(x, 0, a);

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/scsi/bfa/bfad.c| 3 +--
 drivers/scsi/bfa/bfad_debugfs.c| 8 ++--
 drivers/scsi/qla2xxx/qla_bsg.c | 3 +--
 drivers/scsi/qla2xxx/tcm_qla2xxx.c | 5 +
 drivers/scsi/scsi_debug.c  | 6 ++
 drivers/scsi/snic/snic_trc.c   | 3 +--
 6 files changed, 8 insertions(+), 20 deletions(-)

diff --git a/drivers/scsi/bfa/bfad.c b/drivers/scsi/bfa/bfad.c
index 5caf5f3..ab91c59 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,
diff --git a/drivers/scsi/qla2xxx/qla_bsg.c b/drivers/scsi/qla2xxx/qla_bsg.c
index e3ac707..fdd9059 100644
--- a/drivers/scsi/qla2xxx/qla_bsg.c
+++ b/drivers/scsi/qla2xxx/qla_bsg.c
@@ -1435,7 +1435,7 @@ qla2x00_optrom_setup(struct bsg_job *bsg_job, 
scsi_qla_host_t *vha,
ha->optrom_state = QLA_SREADING;
}
 
-   ha->optrom_buffer = vmalloc(ha->optrom_region_size);
+   ha->optrom_buffer = vzalloc(ha->optrom_region_size);
if (!ha->optrom_buffer) {
ql_log(ql_log_warn, vha, 0x7059,
"Read: Unable to allocate memory for optrom retrieval "
@@ -1445,7 +1445,6 @@ qla2x00_optrom_setup(struct bsg_job *bsg_job, 
scsi_qla_host_t *vha,
return -ENOMEM;
}
 
-   memset(ha->optrom_buffer, 0, ha->optrom_region_size);
return 0;
 }
 
diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.c 
b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
index 3f82ea1..aadfeaa 100644
--- a/drivers/scsi/qla2xxx/tcm_qla2xxx.c
+++ b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
@@ -1635,16 +1635,13 @@ static int tcm_qla2xxx_init_lport(struct 
tcm_qla2xxx_lport *lport)
return rc;
}
 
-   lport->lport_loopid_map = vmalloc(sizeof(struct tcm_qla2xxx_fc_loopid) *
-   65536);
+   lport->lport_loopid_map = vzalloc(sizeof(struct tcm_qla2xxx_fc_loopid) 
* 65536);
if (!lport->lport_loopid_map) {
pr_err("Unable to allocate lport->lport_loopid_map of %zu 
bytes\n",
sizeof(struct tcm_qla2xxx_fc_loopid) * 65536);
btree_destroy32(>lport_fcport_map);
return -ENOMEM;

Re: [PATCH v2] scsi: be2iscsi: Use kasprintf

2017-11-03 Thread Himanshu Jha
On Fri, Nov 03, 2017 at 11:25:05AM -0400, Martin K. Petersen wrote:

Hi Martin,
> 
> Himanshu,
> 
> > Just a reminder, is my patch in our queue ?
> 
> It is not. It needs a review/ack from the driver maintainers.

What about Kyle Fortin's review ?

> -- 
> Martin K. PetersenOracle Linux Engineering


Thanks
Himanshu


Re: [PATCH v2] scsi: be2iscsi: Use kasprintf

2017-11-03 Thread Himanshu Jha
On Wed, Oct 11, 2017 at 09:06:14PM +0530, Himanshu Jha wrote:

Hi James,



Just a reminder, is my patch in our queue ?

Thanks
Himanshu Jha


> Use kasprintf instead of combination of kmalloc and sprintf.
> Also, remove BEISCSI_MSI_NAME macro used to specify size of string as
> kasprintf handles size computations.
> 
> Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
> ---
> v2:
>-remove the unnecessary macro BEISCSI_MSI_NAME. 
> 
>  drivers/scsi/be2iscsi/be_main.c | 12 +---
>  drivers/scsi/be2iscsi/be_main.h |  2 --
>  2 files changed, 5 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c
> index b4542e7..6a9ee0e 100644
> --- a/drivers/scsi/be2iscsi/be_main.c
> +++ b/drivers/scsi/be2iscsi/be_main.c
> @@ -803,15 +803,14 @@ static int beiscsi_init_irqs(struct beiscsi_hba *phba)
>  
>   if (pcidev->msix_enabled) {
>   for (i = 0; i < phba->num_cpus; i++) {
> - phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME,
> - GFP_KERNEL);
> + phba->msi_name[i] = kasprintf(GFP_KERNEL,
> +   "beiscsi_%02x_%02x",
> +   phba->shost->host_no, i);
>   if (!phba->msi_name[i]) {
>   ret = -ENOMEM;
>   goto free_msix_irqs;
>   }
>  
> - sprintf(phba->msi_name[i], "beiscsi_%02x_%02x",
> - phba->shost->host_no, i);
>   ret = request_irq(pci_irq_vector(pcidev, i),
> be_isr_msix, 0, phba->msi_name[i],
> _context->be_eq[i]);
> @@ -824,13 +823,12 @@ static int beiscsi_init_irqs(struct beiscsi_hba *phba)
>   goto free_msix_irqs;
>   }
>   }
> - phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, GFP_KERNEL);
> + phba->msi_name[i] = kasprintf(GFP_KERNEL, "beiscsi_mcc_%02x",
> +   phba->shost->host_no);
>   if (!phba->msi_name[i]) {
>   ret = -ENOMEM;
>   goto free_msix_irqs;
>   }
> - sprintf(phba->msi_name[i], "beiscsi_mcc_%02x",
> - phba->shost->host_no);
>   ret = request_irq(pci_irq_vector(pcidev, i), be_isr_mcc, 0,
> phba->msi_name[i], _context->be_eq[i]);
>   if (ret) {
> diff --git a/drivers/scsi/be2iscsi/be_main.h b/drivers/scsi/be2iscsi/be_main.h
> index 81ce3ff..8166de5 100644
> --- a/drivers/scsi/be2iscsi/be_main.h
> +++ b/drivers/scsi/be2iscsi/be_main.h
> @@ -155,8 +155,6 @@
>  #define PAGES_REQUIRED(x) \
>   ((x < PAGE_SIZE) ? 1 :  ((x + PAGE_SIZE - 1) / PAGE_SIZE))
>  
> -#define BEISCSI_MSI_NAME 20 /* size of msi_name string */
> -
>  #define MEM_DESCR_OFFSET 8
>  #define BEISCSI_DEFQ_HDR 1
>  #define BEISCSI_DEFQ_DATA 0
> -- 
> 2.7.4
> 


[PATCH v2] scsi: be2iscsi: Use kasprintf

2017-10-11 Thread Himanshu Jha
Use kasprintf instead of combination of kmalloc and sprintf.
Also, remove BEISCSI_MSI_NAME macro used to specify size of string as
kasprintf handles size computations.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
v2:
   -remove the unnecessary macro BEISCSI_MSI_NAME. 

 drivers/scsi/be2iscsi/be_main.c | 12 +---
 drivers/scsi/be2iscsi/be_main.h |  2 --
 2 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c
index b4542e7..6a9ee0e 100644
--- a/drivers/scsi/be2iscsi/be_main.c
+++ b/drivers/scsi/be2iscsi/be_main.c
@@ -803,15 +803,14 @@ static int beiscsi_init_irqs(struct beiscsi_hba *phba)
 
if (pcidev->msix_enabled) {
for (i = 0; i < phba->num_cpus; i++) {
-   phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME,
-   GFP_KERNEL);
+   phba->msi_name[i] = kasprintf(GFP_KERNEL,
+ "beiscsi_%02x_%02x",
+ phba->shost->host_no, i);
if (!phba->msi_name[i]) {
ret = -ENOMEM;
goto free_msix_irqs;
}
 
-   sprintf(phba->msi_name[i], "beiscsi_%02x_%02x",
-   phba->shost->host_no, i);
ret = request_irq(pci_irq_vector(pcidev, i),
  be_isr_msix, 0, phba->msi_name[i],
  _context->be_eq[i]);
@@ -824,13 +823,12 @@ static int beiscsi_init_irqs(struct beiscsi_hba *phba)
goto free_msix_irqs;
}
}
-   phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, GFP_KERNEL);
+   phba->msi_name[i] = kasprintf(GFP_KERNEL, "beiscsi_mcc_%02x",
+ phba->shost->host_no);
if (!phba->msi_name[i]) {
ret = -ENOMEM;
goto free_msix_irqs;
}
-   sprintf(phba->msi_name[i], "beiscsi_mcc_%02x",
-   phba->shost->host_no);
ret = request_irq(pci_irq_vector(pcidev, i), be_isr_mcc, 0,
  phba->msi_name[i], _context->be_eq[i]);
if (ret) {
diff --git a/drivers/scsi/be2iscsi/be_main.h b/drivers/scsi/be2iscsi/be_main.h
index 81ce3ff..8166de5 100644
--- a/drivers/scsi/be2iscsi/be_main.h
+++ b/drivers/scsi/be2iscsi/be_main.h
@@ -155,8 +155,6 @@
 #define PAGES_REQUIRED(x) \
((x < PAGE_SIZE) ? 1 :  ((x + PAGE_SIZE - 1) / PAGE_SIZE))
 
-#define BEISCSI_MSI_NAME 20 /* size of msi_name string */
-
 #define MEM_DESCR_OFFSET 8
 #define BEISCSI_DEFQ_HDR 1
 #define BEISCSI_DEFQ_DATA 0
-- 
2.7.4



Re: [PATCH] scsi: be2iscsi: Use kasprintf

2017-10-11 Thread Himanshu Jha
On Tue, Oct 10, 2017 at 05:54:15PM -0400, Kyle Fortin wrote:
> Hi Himanshu,
> 
> On Oct 6, 2017, at 2:57 PM, Himanshu Jha <himanshujha199...@gmail.com> wrote:
> > 
> > Use kasprintf instead of combination of kmalloc and sprintf.
> > 
> > Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
> > ---
> > drivers/scsi/be2iscsi/be_main.c | 12 +---
> > 1 file changed, 5 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/scsi/be2iscsi/be_main.c 
> > b/drivers/scsi/be2iscsi/be_main.c
> > index b4542e7..6a9ee0e 100644
> > --- a/drivers/scsi/be2iscsi/be_main.c
> > +++ b/drivers/scsi/be2iscsi/be_main.c
> > @@ -803,15 +803,14 @@ static int beiscsi_init_irqs(struct beiscsi_hba *phba)
> > 
> > if (pcidev->msix_enabled) {
> > for (i = 0; i < phba->num_cpus; i++) {
> > -   phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME,
> > -   GFP_KERNEL);
> > +   phba->msi_name[i] = kasprintf(GFP_KERNEL,
> > + "beiscsi_%02x_%02x",
> > + phba->shost->host_no, i);
> > if (!phba->msi_name[i]) {
> > ret = -ENOMEM;
> > goto free_msix_irqs;
> > }
> > 
> > -   sprintf(phba->msi_name[i], "beiscsi_%02x_%02x",
> > -   phba->shost->host_no, i);
> > ret = request_irq(pci_irq_vector(pcidev, i),
> >   be_isr_msix, 0, phba->msi_name[i],
> >   _context->be_eq[i]);
> > @@ -824,13 +823,12 @@ static int beiscsi_init_irqs(struct beiscsi_hba *phba)
> > goto free_msix_irqs;
> > }
> > }
> > -   phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, GFP_KERNEL);
> > +   phba->msi_name[i] = kasprintf(GFP_KERNEL, "beiscsi_mcc_%02x",
> > + phba->shost->host_no);
> > if (!phba->msi_name[i]) {
> > ret = -ENOMEM;
> > goto free_msix_irqs;
> > }
> > -   sprintf(phba->msi_name[i], "beiscsi_mcc_%02x",
> > -   phba->shost->host_no);
> > ret = request_irq(pci_irq_vector(pcidev, i), be_isr_mcc, 0,
> >   phba->msi_name[i], _context->be_eq[i]);
> > if (ret) {
> > -- 
> > 2.7.4
> 
> Since you are getting rid of the only use for BEISCSI_MSI_NAME within 
> drivers/scsi/be2iscsi/be_main.h, that should be removed too.

Yes, that should be removed! Thanks for pointing that out.
I will send a v2 patch with the update.

> --
> Kyle Fortin - Oracle Linux Engineering
> 
> 
> 
> 


[PATCH] scsi: be2iscsi: Use kasprintf

2017-10-06 Thread Himanshu Jha
Use kasprintf instead of combination of kmalloc and sprintf.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/scsi/be2iscsi/be_main.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c
index b4542e7..6a9ee0e 100644
--- a/drivers/scsi/be2iscsi/be_main.c
+++ b/drivers/scsi/be2iscsi/be_main.c
@@ -803,15 +803,14 @@ static int beiscsi_init_irqs(struct beiscsi_hba *phba)
 
if (pcidev->msix_enabled) {
for (i = 0; i < phba->num_cpus; i++) {
-   phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME,
-   GFP_KERNEL);
+   phba->msi_name[i] = kasprintf(GFP_KERNEL,
+ "beiscsi_%02x_%02x",
+ phba->shost->host_no, i);
if (!phba->msi_name[i]) {
ret = -ENOMEM;
goto free_msix_irqs;
}
 
-   sprintf(phba->msi_name[i], "beiscsi_%02x_%02x",
-   phba->shost->host_no, i);
ret = request_irq(pci_irq_vector(pcidev, i),
  be_isr_msix, 0, phba->msi_name[i],
  _context->be_eq[i]);
@@ -824,13 +823,12 @@ static int beiscsi_init_irqs(struct beiscsi_hba *phba)
goto free_msix_irqs;
}
}
-   phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, GFP_KERNEL);
+   phba->msi_name[i] = kasprintf(GFP_KERNEL, "beiscsi_mcc_%02x",
+ phba->shost->host_no);
if (!phba->msi_name[i]) {
ret = -ENOMEM;
goto free_msix_irqs;
}
-   sprintf(phba->msi_name[i], "beiscsi_mcc_%02x",
-   phba->shost->host_no);
ret = request_irq(pci_irq_vector(pcidev, i), be_isr_mcc, 0,
  phba->msi_name[i], _context->be_eq[i]);
if (ret) {
-- 
2.7.4



[PATCH] scsi: esas2r: Use setup_timer and mod_timer

2017-09-28 Thread Himanshu Jha
Use setup_timer and mod_timer API instead of structure assignments.

This is done using Coccinelle and semantic patch used
for this as follows:

@@
expression x,y,z,a,b;
@@

-init_timer ();
+setup_timer (, y, z);
+mod_timer (, b);
-x.function = y;
-x.data = z;
-x.expires = b;
-add_timer();

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/scsi/esas2r/esas2r_main.c | 10 ++
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/esas2r/esas2r_main.c 
b/drivers/scsi/esas2r/esas2r_main.c
index 81f226b..1866ba0 100644
--- a/drivers/scsi/esas2r/esas2r_main.c
+++ b/drivers/scsi/esas2r/esas2r_main.c
@@ -1635,14 +1635,8 @@ static void esas2r_timer_callback(unsigned long context);
 
 void esas2r_kickoff_timer(struct esas2r_adapter *a)
 {
-   init_timer(>timer);
-
-   a->timer.function = esas2r_timer_callback;
-   a->timer.data = (unsigned long)a;
-   a->timer.expires = jiffies +
-  msecs_to_jiffies(100);
-
-   add_timer(>timer);
+   setup_timer(>timer, esas2r_timer_callback, (unsigned long)a);
+   mod_timer(>timer, jiffies + msecs_to_jiffies(100));
 }
 
 static void esas2r_timer_callback(unsigned long context)
-- 
2.7.4



[PATCH] scsi: qla2xxx: remove unnecessary call to memset

2017-09-11 Thread Himanshu Jha
call to memset to assign 0 value immediately after allocating
memory with kzalloc is unnecesaary as kzalloc allocates the memory
filled with 0 value.

Semantic patch used to resolve this issue:

@@
expression e,e2; constant c;
statement S;
@@

  e = kzalloc(e2, c);
  if(e == NULL) S
- memset(e, 0, e2);

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/scsi/qla2xxx/qla_init.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index b5b48dd..54c1d63 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -7917,7 +7917,6 @@ struct qla_qpair *qla2xxx_create_qpair(struct 
scsi_qla_host *vha, int qos,
"Failed to allocate memory for queue pair.\n");
return NULL;
}
-   memset(qpair, 0, sizeof(struct qla_qpair));
 
qpair->hw = vha->hw;
qpair->vha = vha;
-- 
2.7.4



Re: [PATCH] scsi: remove memset before memcpy

2017-08-29 Thread Himanshu Jha
On Tue, Aug 29, 2017 at 12:29:35PM -0700, Joe Perches wrote:
> On Wed, 2017-08-30 at 00:19 +0530, Himanshu Jha wrote:
> > drivers/scsi/megaraid/megaraid_sas_fusion.c
> 
> I don't know if you did this with coccinelle.

Yes, I did this with coccinelle.

> 
> If so, it would be good to show the tool and script
> in the commit message.

Alright, next time.
> 
> If not, the input script is pretty simple.
> 
> $ cat memset_before_memcpy.cocci
> @@
> expression e1;
> expression e2;
> expression e3;
> @@
> 
> - memset(e1, 0, e3);
>   memcpy(e1, e2, e3);
> $
> 
> Adding a test to make sure e1 or e3 isn't
> modified before any other code uses them
> by doing
> 
> $ cat memset_before_memcpy_2.cocci
> @@
> expression e1;
> expression e2;
> expressi
> on e3;
> @@
> 
> - memset(e1, 0, e3);
>   ... when != \( e1 \| e3 \)
>   memcpy(e1, e2, e3);
> $
> 
> finds more cases but there may be a
> false positive if e1 is a passed
> function argument and if the operation
> isn't effectively atomic like below:
>

I usually check all my diff before sending to see if any false positives
occured or not.

It's been 4 days since I learnt coccinelle and before I used to look
into every files for occurences or search the identifiers on
FreeElectrons.

>From now I will mention whatever tool I used on my patch!

Thanks

> 
> --- a/net/bridge/br_multicast.c
> +++ b/net/bridge/br_multicast.c
> @@ -2556,7 +2556,6 @@ void br_multicast_get_stats(const struct
>   struct br_mcast_stats tdst;
>   int i;
>  
> - memset(dest, 0, sizeof(*dest));
>   if (p)
>   stats = p->mcast_stats;
>   else
> 
> 
> 
> where the memcpy is the last line of the function.
> 


[PATCH] scsi: remove memset before memcpy

2017-08-29 Thread Himanshu Jha
calling memcpy immediately after memset with the same region of memory
makes memset redundant.

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/scsi/bfa/bfa_ioc.c  | 1 -
 drivers/scsi/megaraid/megaraid_sas_fusion.c | 2 --
 drivers/scsi/qla4xxx/ql4_os.c   | 1 -
 3 files changed, 4 deletions(-)

diff --git a/drivers/scsi/bfa/bfa_ioc.c b/drivers/scsi/bfa/bfa_ioc.c
index 256f4af..c37a4be 100644
--- a/drivers/scsi/bfa/bfa_ioc.c
+++ b/drivers/scsi/bfa/bfa_ioc.c
@@ -2763,7 +2763,6 @@ bfa_ioc_get_type(struct bfa_ioc_s *ioc)
 void
 bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num)
 {
-   memset((void *)serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN);
memcpy((void *)serial_num,
(void *)ioc->attr->brcd_serialnum,
BFA_ADAPTER_SERIAL_NUM_LEN);
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c 
b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 11bd2e6..20bbb9b 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -1505,8 +1505,6 @@ map_cmd_status(struct fusion_context *fusion,
 
scmd->result = (DID_OK << 16) | ext_status;
if (ext_status == SAM_STAT_CHECK_CONDITION) {
-   memset(scmd->sense_buffer, 0,
-  SCSI_SENSE_BUFFERSIZE);
memcpy(scmd->sense_buffer, sense,
   SCSI_SENSE_BUFFERSIZE);
scmd->result |= DRIVER_SENSE << 24;
diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
index 64c6fa5..c87658c 100644
--- a/drivers/scsi/qla4xxx/ql4_os.c
+++ b/drivers/scsi/qla4xxx/ql4_os.c
@@ -619,7 +619,6 @@ static void qla4xxx_create_chap_list(struct scsi_qla_host 
*ha)
goto exit_chap_list;
}
 
-   memset(ha->chap_list, 0, chap_size);
memcpy(ha->chap_list, chap_flash_data, chap_size);
 
 exit_chap_list:
-- 
2.7.4



[PATCH] scsi: qla2xxx: Use PTR_ERR_OR_ZERO

2017-08-29 Thread Himanshu Jha
Use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR

Signed-off-by: Himanshu Jha <himanshujha199...@gmail.com>
---
 drivers/scsi/qla2xxx/tcm_qla2xxx.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.c 
b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
index 3f82ea1..bf33350 100644
--- a/drivers/scsi/qla2xxx/tcm_qla2xxx.c
+++ b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
@@ -1522,10 +1522,7 @@ static int tcm_qla2xxx_check_initiator_node_acl(
   sizeof(struct qla_tgt_cmd),
   TARGET_PROT_ALL, port_name,
   qlat_sess, tcm_qla2xxx_session_cb);
-   if (IS_ERR(se_sess))
-   return PTR_ERR(se_sess);
-
-   return 0;
+   return PTR_ERR_OR_ZERO(se_sess);
 }
 
 static void tcm_qla2xxx_update_sess(struct fc_port *sess, port_id_t s_id,
-- 
2.7.4