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
text data bss dec hex filename
40783 5940 64 46787 b6c3 drivers/scsi/bnx2fc/bnx2fc_hwi.o
After:
himanshu@himanshu-Vostro-3559:~/linux-next$ size drivers/scsi/bnx2fc/bnx2fc_hwi.o
text data bss dec hex filename
40619 5940 64 46623 b61f 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
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 <[email protected]>
Signed-off-by: Himanshu Jha <[email protected]>
---
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_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__));
return status;
}
- memset(sys_info, 0, sizeof(*sys_info));
memset(&mbox_cmd, 0, sizeof(mbox_cmd));
memset(&mbox_sts, 0, sizeof(mbox_sts));
diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
index 2b8a8ce..82e889b 100644
--- a/drivers/scsi/qla4xxx/ql4_os.c
+++ b/drivers/scsi/qla4xxx/ql4_os.c
@@ -2689,16 +2689,15 @@ qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
uint32_t rem = len;
struct nlattr *attr;
- 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) {
ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
__func__);
return -ENOMEM;
}
- memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
memset(&mbox_cmd, 0, sizeof(mbox_cmd));
memset(&mbox_sts, 0, sizeof(mbox_sts));
@@ -4196,15 +4195,14 @@ static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
sizeof(struct shadow_regs) +
MEM_ALIGN_VALUE +
(PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
- ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
- &ha->queues_dma, GFP_KERNEL);
+ ha->queues = dma_zalloc_coherent(&ha->pdev->dev, ha->queues_len,
+ &ha->queues_dma, GFP_KERNEL);
if (ha->queues == NULL) {
ql4_printk(KERN_WARNING, ha,
"Memory Allocation failed - queues.\n");
goto mem_alloc_error_exit;
}
- memset(ha->queues, 0, ha->queues_len);
/*
* As per RISC alignment requirements -- the bus-address must be a
--
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 <[email protected]>
Signed-off-by: Himanshu Jha <[email protected]>
---
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(&ha->pdev->dev,
- sizeof(*stats), &stats_dma, GFP_KERNEL);
+ stats = dma_zalloc_coherent(&ha->pdev->dev, sizeof(*stats),
+ &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(&ha->pdev->dev,
- sizeof(*stats), &stats_dma, GFP_KERNEL);
+ stats = dma_zalloc_coherent(&ha->pdev->dev, sizeof(*stats),
+ &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->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
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 <[email protected]>
Signed-off-by: Himanshu Jha <[email protected]>
---
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 cccc34a..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(&qedi->pdev->dev,
- PAGE_SIZE,
- &qedi->bdq_pbl_list_dma,
- GFP_KERNEL);
+ qedi->bdq_pbl_list = dma_zalloc_coherent(&qedi->pdev->dev, PAGE_SIZE,
+ &qedi->bdq_pbl_list_dma,
+ GFP_KERNEL);
if (!qedi->bdq_pbl_list) {
QEDI_ERR(&qedi->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(&qedi->pdev->dev,
- qedi->global_queues[i]->cq_mem_size,
- &qedi->global_queues[i]->cq_dma,
- GFP_KERNEL);
+ qedi->global_queues[i]->cq =
+ dma_zalloc_coherent(&qedi->pdev->dev,
+ qedi->global_queues[i]->cq_mem_size,
+ &qedi->global_queues[i]->cq_dma,
+ GFP_KERNEL);
if (!qedi->global_queues[i]->cq) {
QEDI_WARN(&qedi->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(&qedi->pdev->dev,
- qedi->global_queues[i]->cq_pbl_size,
- &qedi->global_queues[i]->cq_pbl_dma,
- GFP_KERNEL);
+ qedi->global_queues[i]->cq_pbl =
+ dma_zalloc_coherent(&qedi->pdev->dev,
+ qedi->global_queues[i]->cq_pbl_size,
+ &qedi->global_queues[i]->cq_pbl_dma,
+ GFP_KERNEL);
if (!qedi->global_queues[i]->cq_pbl) {
QEDI_WARN(&qedi->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(&qedi->pdev->dev, ep->sq_mem_size,
- &ep->sq_dma, GFP_KERNEL);
+ ep->sq = dma_zalloc_coherent(&qedi->pdev->dev, ep->sq_mem_size,
+ &ep->sq_dma, GFP_KERNEL);
if (!ep->sq) {
QEDI_WARN(&qedi->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(&qedi->pdev->dev, ep->sq_pbl_size,
- &ep->sq_pbl_dma, GFP_KERNEL);
+ ep->sq_pbl = dma_zalloc_coherent(&qedi->pdev->dev, ep->sq_pbl_size,
+ &ep->sq_pbl_dma, GFP_KERNEL);
if (!ep->sq_pbl) {
QEDI_WARN(&qedi->dbg_ctx,
"Could not allocate send queue PBL.\n");
rval = -ENOMEM;
goto out_free_sq;
}
- memset(ep->sq_pbl, 0, ep->sq_pbl_size);
/* Create PBL */
num_pages = ep->sq_mem_size / QEDI_PAGE_SIZE;
--
2.7.4
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 <[email protected]>
Signed-off-by: Himanshu Jha <[email protected]>
---
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,
- &mvi->tx_dma, GFP_KERNEL);
+ mvi->tx = dma_zalloc_coherent(mvi->dev,
+ sizeof(*mvi->tx) * MVS_CHIP_SLOT_SZ,
+ &mvi->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,
- &mvi->rx_fis_dma, GFP_KERNEL);
+ mvi->rx_fis = dma_zalloc_coherent(mvi->dev, MVS_RX_FISL_SZ,
+ &mvi->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),
- &mvi->rx_dma, GFP_KERNEL);
+ mvi->rx = dma_zalloc_coherent(mvi->dev,
+ sizeof(*mvi->rx) * (MVS_RX_RING_SZ + 1),
+ &mvi->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,
- &mvi->slot_dma, GFP_KERNEL);
+ mvi->slot = dma_zalloc_coherent(mvi->dev,
+ sizeof(*mvi->slot) * slot_nr,
+ &mvi->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
Use vzalloc instead of vmalloc followed by memset 0.
Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
Suggested-by: Luis R. Rodriguez <[email protected]>
Signed-off-by: Himanshu Jha <[email protected]>
---
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
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 <[email protected]>
Signed-off-by: Himanshu Jha <[email protected]>
---
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(&pHba->pDev->dev, 4, &addr, GFP_KERNEL);
+ status = dma_zalloc_coherent(&pHba->pDev->dev, 4, &addr, 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(&pHba->pDev->dev, 4, &addr, GFP_KERNEL);
+ status = dma_zalloc_coherent(&pHba->pDev->dev, 4, &addr, 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, &msg[0]);
writel(I2O_CMD_OUTBOUND_INIT<<24 | HOST_TID<<12 | ADAPTER_TID, &msg[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(&pHba->pDev->dev,
- pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4,
- &pHba->reply_pool_pa, GFP_KERNEL);
+ pHba->reply_pool = dma_zalloc_coherent(&pHba->pDev->dev,
+ pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4,
+ &pHba->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(&pHba->pDev->dev,
- sys_tbl_len, &sys_tbl_pa, GFP_KERNEL);
+ sys_tbl = dma_zalloc_coherent(&pHba->pDev->dev, sys_tbl_len,
+ &sys_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
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 <[email protected]>
Signed-off-by: Himanshu Jha <[email protected]>
---
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(&hba->pcidev->dev,
- PAGE_SIZE,
- &hba->task_ctx_bd_dma,
- GFP_KERNEL);
+ hba->task_ctx_bd_tbl = dma_zalloc_coherent(&hba->pcidev->dev,
+ PAGE_SIZE,
+ &hba->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(&hba->pcidev->dev,
- PAGE_SIZE,
- &hba->task_ctx_dma[i],
- GFP_KERNEL);
+ hba->task_ctx[i] = dma_zalloc_coherent(&hba->pcidev->dev,
+ PAGE_SIZE,
+ &hba->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(&hba->pcidev->dev,
- BNX2FC_HASH_TBL_CHUNK_SIZE,
- &dma_segment_array[i],
- GFP_KERNEL);
+ hba->hash_tbl_segments[i] =
+ dma_zalloc_coherent(&hba->pcidev->dev,
+ BNX2FC_HASH_TBL_CHUNK_SIZE,
+ &dma_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(&hba->pcidev->dev,
- PAGE_SIZE,
- &hba->hash_tbl_pbl_dma,
- GFP_KERNEL);
+ hba->hash_tbl_pbl = dma_zalloc_coherent(&hba->pcidev->dev, PAGE_SIZE,
+ &hba->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_tbl_ptr = dma_alloc_coherent(&hba->pcidev->dev, mem_size,
- &hba->t2_hash_tbl_ptr_dma,
- GFP_KERNEL);
+ hba->t2_hash_tbl_ptr = dma_zalloc_coherent(&hba->pcidev->dev,
+ mem_size,
+ &hba->t2_hash_tbl_ptr_dma,
+ GFP_KERNEL);
if (!hba->t2_hash_tbl_ptr) {
printk(KERN_ERR PFX "unable to allocate t2 hash table ptr\n");
bnx2fc_free_fw_resc(hba);
return -ENOMEM;
}
- memset(hba->t2_hash_tbl_ptr, 0x00, mem_size);
mem_size = BNX2FC_NUM_MAX_SESS *
sizeof(struct fcoe_t2_hash_table_entry);
- hba->t2_hash_tbl = dma_alloc_coherent(&hba->pcidev->dev, mem_size,
- &hba->t2_hash_tbl_dma,
- GFP_KERNEL);
+ hba->t2_hash_tbl = dma_zalloc_coherent(&hba->pcidev->dev, mem_size,
+ &hba->t2_hash_tbl_dma,
+ GFP_KERNEL);
if (!hba->t2_hash_tbl) {
printk(KERN_ERR PFX "unable to allocate t2 hash table\n");
bnx2fc_free_fw_resc(hba);
return -ENOMEM;
}
- memset(hba->t2_hash_tbl, 0x00, mem_size);
for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
addr = (unsigned long) hba->t2_hash_tbl_dma +
((i+1) * sizeof(struct fcoe_t2_hash_table_entry));
@@ -2148,16 +2140,14 @@ int bnx2fc_setup_fw_resc(struct bnx2fc_hba *hba)
return -ENOMEM;
}
- hba->stats_buffer = dma_alloc_coherent(&hba->pcidev->dev,
- PAGE_SIZE,
- &hba->stats_buf_dma,
- GFP_KERNEL);
+ hba->stats_buffer = dma_zalloc_coherent(&hba->pcidev->dev, PAGE_SIZE,
+ &hba->stats_buf_dma,
+ GFP_KERNEL);
if (!hba->stats_buffer) {
printk(KERN_ERR PFX "unable to alloc Stats Buffer\n");
bnx2fc_free_fw_resc(hba);
return -ENOMEM;
}
- memset(hba->stats_buffer, 0x00, PAGE_SIZE);
return 0;
}
diff --git a/drivers/scsi/bnx2fc/bnx2fc_tgt.c b/drivers/scsi/bnx2fc/bnx2fc_tgt.c
index a8ae1a0..e3d1c7c 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_tgt.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_tgt.c
@@ -672,56 +672,52 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
tgt->sq_mem_size = (tgt->sq_mem_size + (CNIC_PAGE_SIZE - 1)) &
CNIC_PAGE_MASK;
- tgt->sq = dma_alloc_coherent(&hba->pcidev->dev, tgt->sq_mem_size,
- &tgt->sq_dma, GFP_KERNEL);
+ tgt->sq = dma_zalloc_coherent(&hba->pcidev->dev, tgt->sq_mem_size,
+ &tgt->sq_dma, GFP_KERNEL);
if (!tgt->sq) {
printk(KERN_ERR PFX "unable to allocate SQ memory %d\n",
tgt->sq_mem_size);
goto mem_alloc_failure;
}
- memset(tgt->sq, 0, tgt->sq_mem_size);
/* Allocate and map CQ */
tgt->cq_mem_size = tgt->max_cqes * BNX2FC_CQ_WQE_SIZE;
tgt->cq_mem_size = (tgt->cq_mem_size + (CNIC_PAGE_SIZE - 1)) &
CNIC_PAGE_MASK;
- tgt->cq = dma_alloc_coherent(&hba->pcidev->dev, tgt->cq_mem_size,
- &tgt->cq_dma, GFP_KERNEL);
+ tgt->cq = dma_zalloc_coherent(&hba->pcidev->dev, tgt->cq_mem_size,
+ &tgt->cq_dma, GFP_KERNEL);
if (!tgt->cq) {
printk(KERN_ERR PFX "unable to allocate CQ memory %d\n",
tgt->cq_mem_size);
goto mem_alloc_failure;
}
- memset(tgt->cq, 0, tgt->cq_mem_size);
/* Allocate and map RQ and RQ PBL */
tgt->rq_mem_size = tgt->max_rqes * BNX2FC_RQ_WQE_SIZE;
tgt->rq_mem_size = (tgt->rq_mem_size + (CNIC_PAGE_SIZE - 1)) &
CNIC_PAGE_MASK;
- tgt->rq = dma_alloc_coherent(&hba->pcidev->dev, tgt->rq_mem_size,
- &tgt->rq_dma, GFP_KERNEL);
+ tgt->rq = dma_zalloc_coherent(&hba->pcidev->dev, tgt->rq_mem_size,
+ &tgt->rq_dma, GFP_KERNEL);
if (!tgt->rq) {
printk(KERN_ERR PFX "unable to allocate RQ memory %d\n",
tgt->rq_mem_size);
goto mem_alloc_failure;
}
- memset(tgt->rq, 0, tgt->rq_mem_size);
tgt->rq_pbl_size = (tgt->rq_mem_size / CNIC_PAGE_SIZE) * sizeof(void *);
tgt->rq_pbl_size = (tgt->rq_pbl_size + (CNIC_PAGE_SIZE - 1)) &
CNIC_PAGE_MASK;
- tgt->rq_pbl = dma_alloc_coherent(&hba->pcidev->dev, tgt->rq_pbl_size,
- &tgt->rq_pbl_dma, GFP_KERNEL);
+ tgt->rq_pbl = dma_zalloc_coherent(&hba->pcidev->dev, tgt->rq_pbl_size,
+ &tgt->rq_pbl_dma, GFP_KERNEL);
if (!tgt->rq_pbl) {
printk(KERN_ERR PFX "unable to allocate RQ PBL %d\n",
tgt->rq_pbl_size);
goto mem_alloc_failure;
}
- memset(tgt->rq_pbl, 0, tgt->rq_pbl_size);
num_pages = tgt->rq_mem_size / CNIC_PAGE_SIZE;
page = tgt->rq_dma;
pbl = (u32 *)tgt->rq_pbl;
@@ -739,44 +735,43 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
tgt->xferq_mem_size = (tgt->xferq_mem_size + (CNIC_PAGE_SIZE - 1)) &
CNIC_PAGE_MASK;
- tgt->xferq = dma_alloc_coherent(&hba->pcidev->dev, tgt->xferq_mem_size,
- &tgt->xferq_dma, GFP_KERNEL);
+ tgt->xferq = dma_zalloc_coherent(&hba->pcidev->dev,
+ tgt->xferq_mem_size, &tgt->xferq_dma,
+ GFP_KERNEL);
if (!tgt->xferq) {
printk(KERN_ERR PFX "unable to allocate XFERQ %d\n",
tgt->xferq_mem_size);
goto mem_alloc_failure;
}
- memset(tgt->xferq, 0, tgt->xferq_mem_size);
/* Allocate and map CONFQ & CONFQ PBL */
tgt->confq_mem_size = tgt->max_sqes * BNX2FC_CONFQ_WQE_SIZE;
tgt->confq_mem_size = (tgt->confq_mem_size + (CNIC_PAGE_SIZE - 1)) &
CNIC_PAGE_MASK;
- tgt->confq = dma_alloc_coherent(&hba->pcidev->dev, tgt->confq_mem_size,
- &tgt->confq_dma, GFP_KERNEL);
+ tgt->confq = dma_zalloc_coherent(&hba->pcidev->dev,
+ tgt->confq_mem_size, &tgt->confq_dma,
+ GFP_KERNEL);
if (!tgt->confq) {
printk(KERN_ERR PFX "unable to allocate CONFQ %d\n",
tgt->confq_mem_size);
goto mem_alloc_failure;
}
- memset(tgt->confq, 0, tgt->confq_mem_size);
tgt->confq_pbl_size =
(tgt->confq_mem_size / CNIC_PAGE_SIZE) * sizeof(void *);
tgt->confq_pbl_size =
(tgt->confq_pbl_size + (CNIC_PAGE_SIZE - 1)) & CNIC_PAGE_MASK;
- tgt->confq_pbl = dma_alloc_coherent(&hba->pcidev->dev,
- tgt->confq_pbl_size,
- &tgt->confq_pbl_dma, GFP_KERNEL);
+ tgt->confq_pbl = dma_zalloc_coherent(&hba->pcidev->dev,
+ tgt->confq_pbl_size,
+ &tgt->confq_pbl_dma, GFP_KERNEL);
if (!tgt->confq_pbl) {
printk(KERN_ERR PFX "unable to allocate CONFQ PBL %d\n",
tgt->confq_pbl_size);
goto mem_alloc_failure;
}
- memset(tgt->confq_pbl, 0, tgt->confq_pbl_size);
num_pages = tgt->confq_mem_size / CNIC_PAGE_SIZE;
page = tgt->confq_dma;
pbl = (u32 *)tgt->confq_pbl;
@@ -792,15 +787,14 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
/* Allocate and map ConnDB */
tgt->conn_db_mem_size = sizeof(struct fcoe_conn_db);
- tgt->conn_db = dma_alloc_coherent(&hba->pcidev->dev,
- tgt->conn_db_mem_size,
- &tgt->conn_db_dma, GFP_KERNEL);
+ tgt->conn_db = dma_zalloc_coherent(&hba->pcidev->dev,
+ tgt->conn_db_mem_size,
+ &tgt->conn_db_dma, GFP_KERNEL);
if (!tgt->conn_db) {
printk(KERN_ERR PFX "unable to allocate conn_db %d\n",
tgt->conn_db_mem_size);
goto mem_alloc_failure;
}
- memset(tgt->conn_db, 0, tgt->conn_db_mem_size);
/* Allocate and map LCQ */
@@ -808,15 +802,14 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
tgt->lcq_mem_size = (tgt->lcq_mem_size + (CNIC_PAGE_SIZE - 1)) &
CNIC_PAGE_MASK;
- tgt->lcq = dma_alloc_coherent(&hba->pcidev->dev, tgt->lcq_mem_size,
- &tgt->lcq_dma, GFP_KERNEL);
+ tgt->lcq = dma_zalloc_coherent(&hba->pcidev->dev, tgt->lcq_mem_size,
+ &tgt->lcq_dma, GFP_KERNEL);
if (!tgt->lcq) {
printk(KERN_ERR PFX "unable to allocate lcq %d\n",
tgt->lcq_mem_size);
goto mem_alloc_failure;
}
- memset(tgt->lcq, 0, tgt->lcq_mem_size);
tgt->conn_db->rq_prod = 0x8000;
--
2.7.4
Use vzalloc instead of vmalloc followed by memset 0.
Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
Suggested-by: Luis R. Rodriguez <[email protected]>
Signed-off-by: Himanshu Jha <[email protected]>
---
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, &kva_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->bfad_lock, flags);
rc = bfa_ioc_debug_fwtrc(&bfad->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->bfad_lock, flags);
rc = bfa_ioc_debug_fwsave(&bfad->bfa.ioc,
fw_debug->debug_buffer,
--
2.7.4
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 <[email protected]>
Signed-off-by: Himanshu Jha <[email protected]>
---
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(&hba->pcidev->dev, ep->qp.sq_mem_size,
- &ep->qp.sq_phys, GFP_KERNEL);
+ ep->qp.sq_virt =
+ dma_zalloc_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
+ &ep->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(&hba->pcidev->dev, ep->qp.cq_mem_size,
- &ep->qp.cq_phys, GFP_KERNEL);
+ ep->qp.cq_virt =
+ dma_zalloc_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
+ &ep->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
On 30/12/17 8:58 PM, "Himanshu Jha" <[email protected]> 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 <[email protected]>
>Signed-off-by: Himanshu Jha <[email protected]>
>---
> 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_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__));
> return status;
> }
>
>- memset(sys_info, 0, sizeof(*sys_info));
> memset(&mbox_cmd, 0, sizeof(mbox_cmd));
> memset(&mbox_sts, 0, sizeof(mbox_sts));
>
>diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
>index 2b8a8ce..82e889b 100644
>--- a/drivers/scsi/qla4xxx/ql4_os.c
>+++ b/drivers/scsi/qla4xxx/ql4_os.c
>@@ -2689,16 +2689,15 @@ qla4xxx_iface_set_param(struct Scsi_Host *shost,
>void *data, uint32_t len)
> uint32_t rem = len;
> struct nlattr *attr;
>
>- 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) {
> ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
> __func__);
> return -ENOMEM;
> }
>
>- memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
> memset(&mbox_cmd, 0, sizeof(mbox_cmd));
> memset(&mbox_sts, 0, sizeof(mbox_sts));
>
>@@ -4196,15 +4195,14 @@ static int qla4xxx_mem_alloc(struct scsi_qla_host
>*ha)
> sizeof(struct shadow_regs) +
> MEM_ALIGN_VALUE +
> (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
>- ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
>- &ha->queues_dma, GFP_KERNEL);
>+ ha->queues = dma_zalloc_coherent(&ha->pdev->dev, ha->queues_len,
>+ &ha->queues_dma, GFP_KERNEL);
> if (ha->queues == NULL) {
> ql4_printk(KERN_WARNING, ha,
> "Memory Allocation failed - queues.\n");
>
> goto mem_alloc_error_exit;
> }
>- memset(ha->queues, 0, ha->queues_len);
>
> /*
> * As per RISC alignment requirements -- the bus-address must be a
>--
Acked-by: Manish Rangankar <[email protected]>
>
On 30/12/17 8:58 PM, "Himanshu Jha" <[email protected]> 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 <[email protected]>
>Signed-off-by: Himanshu Jha <[email protected]>
>---
> 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 cccc34a..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(&qedi->pdev->dev,
>- PAGE_SIZE,
>- &qedi->bdq_pbl_list_dma,
>- GFP_KERNEL);
>+ qedi->bdq_pbl_list = dma_zalloc_coherent(&qedi->pdev->dev, PAGE_SIZE,
>+ &qedi->bdq_pbl_list_dma,
>+ GFP_KERNEL);
> if (!qedi->bdq_pbl_list) {
> QEDI_ERR(&qedi->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(&qedi->pdev->dev,
>- qedi->global_queues[i]->cq_mem_size,
>- &qedi->global_queues[i]->cq_dma,
>- GFP_KERNEL);
>+ qedi->global_queues[i]->cq =
>+ dma_zalloc_coherent(&qedi->pdev->dev,
>+ qedi->global_queues[i]->cq_mem_size,
>+ &qedi->global_queues[i]->cq_dma,
>+ GFP_KERNEL);
>
> if (!qedi->global_queues[i]->cq) {
> QEDI_WARN(&qedi->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(&qedi->pdev->dev,
>- qedi->global_queues[i]->cq_pbl_size,
>- &qedi->global_queues[i]->cq_pbl_dma,
>- GFP_KERNEL);
>+ qedi->global_queues[i]->cq_pbl =
>+ dma_zalloc_coherent(&qedi->pdev->dev,
>+ qedi->global_queues[i]->cq_pbl_size,
>+ &qedi->global_queues[i]->cq_pbl_dma,
>+ GFP_KERNEL);
>
> if (!qedi->global_queues[i]->cq_pbl) {
> QEDI_WARN(&qedi->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(&qedi->pdev->dev, ep->sq_mem_size,
>- &ep->sq_dma, GFP_KERNEL);
>+ ep->sq = dma_zalloc_coherent(&qedi->pdev->dev, ep->sq_mem_size,
>+ &ep->sq_dma, GFP_KERNEL);
> if (!ep->sq) {
> QEDI_WARN(&qedi->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(&qedi->pdev->dev, ep->sq_pbl_size,
>- &ep->sq_pbl_dma, GFP_KERNEL);
>+ ep->sq_pbl = dma_zalloc_coherent(&qedi->pdev->dev, ep->sq_pbl_size,
>+ &ep->sq_pbl_dma, GFP_KERNEL);
> if (!ep->sq_pbl) {
> QEDI_WARN(&qedi->dbg_ctx,
> "Could not allocate send queue PBL.\n");
> rval = -ENOMEM;
> goto out_free_sq;
> }
>- memset(ep->sq_pbl, 0, ep->sq_pbl_size);
>
> /* Create PBL */
> num_pages = ep->sq_mem_size / QEDI_PAGE_SIZE;
>--
>2.7.4
Acked-by: Manish Rangankar <[email protected]>
>
On 30/12/17 8:58 PM, "Himanshu Jha" <[email protected]> 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 <[email protected]>
>Signed-off-by: Himanshu Jha <[email protected]>
>---
> 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(&hba->pcidev->dev, ep->qp.sq_mem_size,
>- &ep->qp.sq_phys, GFP_KERNEL);
>+ ep->qp.sq_virt =
>+ dma_zalloc_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
>+ &ep->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(&hba->pcidev->dev, ep->qp.cq_mem_size,
>- &ep->qp.cq_phys, GFP_KERNEL);
>+ ep->qp.cq_virt =
>+ dma_zalloc_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
>+ &ep->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 <[email protected]>
>
-----Original Message-----
From: Himanshu Jha [mailto:[email protected]]
Sent: 30 December 2017 20:59
To: [email protected]; [email protected]; [email protected]
Cc: Gurumurthy, Anil <[email protected]>; Kalluru, Sudarsana <[email protected]>; Dept-Eng QLogic Storage Upstream <[email protected]>; [email protected]; [email protected]; [email protected]; Dept-Eng QLogic Storage Upstream <[email protected]>; Dept-Eng QLA2xxx Upstream <[email protected]>; [email protected]; [email protected]; Himanshu Jha <[email protected]>
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 <[email protected]>
Signed-off-by: Himanshu Jha <[email protected]>
---
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, &kva_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->bfad_lock, flags);
rc = bfa_ioc_debug_fwtrc(&bfad->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->bfad_lock, flags);
rc = bfa_ioc_debug_fwsave(&bfad->bfa.ioc,
fw_debug->debug_buffer,
--
2.7.4
Acked by: Anil Gurumurthy <[email protected]>
> On Dec 30, 2017, at 7:28 AM, Himanshu Jha <[email protected]> wrote:
>
> 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 <[email protected]>
> Signed-off-by: Himanshu Jha <[email protected]>
> ---
> 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(&ha->pdev->dev,
> - sizeof(*stats), &stats_dma, GFP_KERNEL);
> + stats = dma_zalloc_coherent(&ha->pdev->dev, sizeof(*stats),
> + &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(&ha->pdev->dev,
> - sizeof(*stats), &stats_dma, GFP_KERNEL);
> + stats = dma_zalloc_coherent(&ha->pdev->dev, sizeof(*stats),
> + &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->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
>
Looks good
Acked-by: Himanshu Madhani <[email protected]>
On Sat, 30 Dec 2017, 10:28am, 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 <[email protected]>
> Signed-off-by: Himanshu Jha <[email protected]>
> ---
> 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(&hba->pcidev->dev,
> - PAGE_SIZE,
> - &hba->task_ctx_bd_dma,
> - GFP_KERNEL);
> + hba->task_ctx_bd_tbl = dma_zalloc_coherent(&hba->pcidev->dev,
> + PAGE_SIZE,
> + &hba->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(&hba->pcidev->dev,
> - PAGE_SIZE,
> - &hba->task_ctx_dma[i],
> - GFP_KERNEL);
> + hba->task_ctx[i] = dma_zalloc_coherent(&hba->pcidev->dev,
> + PAGE_SIZE,
> + &hba->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(&hba->pcidev->dev,
> - BNX2FC_HASH_TBL_CHUNK_SIZE,
> - &dma_segment_array[i],
> - GFP_KERNEL);
> + hba->hash_tbl_segments[i] =
> + dma_zalloc_coherent(&hba->pcidev->dev,
> + BNX2FC_HASH_TBL_CHUNK_SIZE,
> + &dma_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(&hba->pcidev->dev,
> - PAGE_SIZE,
> - &hba->hash_tbl_pbl_dma,
> - GFP_KERNEL);
> + hba->hash_tbl_pbl = dma_zalloc_coherent(&hba->pcidev->dev, PAGE_SIZE,
> + &hba->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_tbl_ptr = dma_alloc_coherent(&hba->pcidev->dev, mem_size,
> - &hba->t2_hash_tbl_ptr_dma,
> - GFP_KERNEL);
> + hba->t2_hash_tbl_ptr = dma_zalloc_coherent(&hba->pcidev->dev,
> + mem_size,
> + &hba->t2_hash_tbl_ptr_dma,
> + GFP_KERNEL);
> if (!hba->t2_hash_tbl_ptr) {
> printk(KERN_ERR PFX "unable to allocate t2 hash table ptr\n");
> bnx2fc_free_fw_resc(hba);
> return -ENOMEM;
> }
> - memset(hba->t2_hash_tbl_ptr, 0x00, mem_size);
>
> mem_size = BNX2FC_NUM_MAX_SESS *
> sizeof(struct fcoe_t2_hash_table_entry);
> - hba->t2_hash_tbl = dma_alloc_coherent(&hba->pcidev->dev, mem_size,
> - &hba->t2_hash_tbl_dma,
> - GFP_KERNEL);
> + hba->t2_hash_tbl = dma_zalloc_coherent(&hba->pcidev->dev, mem_size,
> + &hba->t2_hash_tbl_dma,
> + GFP_KERNEL);
> if (!hba->t2_hash_tbl) {
> printk(KERN_ERR PFX "unable to allocate t2 hash table\n");
> bnx2fc_free_fw_resc(hba);
> return -ENOMEM;
> }
> - memset(hba->t2_hash_tbl, 0x00, mem_size);
> for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
> addr = (unsigned long) hba->t2_hash_tbl_dma +
> ((i+1) * sizeof(struct fcoe_t2_hash_table_entry));
> @@ -2148,16 +2140,14 @@ int bnx2fc_setup_fw_resc(struct bnx2fc_hba *hba)
> return -ENOMEM;
> }
>
> - hba->stats_buffer = dma_alloc_coherent(&hba->pcidev->dev,
> - PAGE_SIZE,
> - &hba->stats_buf_dma,
> - GFP_KERNEL);
> + hba->stats_buffer = dma_zalloc_coherent(&hba->pcidev->dev, PAGE_SIZE,
> + &hba->stats_buf_dma,
> + GFP_KERNEL);
> if (!hba->stats_buffer) {
> printk(KERN_ERR PFX "unable to alloc Stats Buffer\n");
> bnx2fc_free_fw_resc(hba);
> return -ENOMEM;
> }
> - memset(hba->stats_buffer, 0x00, PAGE_SIZE);
>
> return 0;
> }
> diff --git a/drivers/scsi/bnx2fc/bnx2fc_tgt.c b/drivers/scsi/bnx2fc/bnx2fc_tgt.c
> index a8ae1a0..e3d1c7c 100644
> --- a/drivers/scsi/bnx2fc/bnx2fc_tgt.c
> +++ b/drivers/scsi/bnx2fc/bnx2fc_tgt.c
> @@ -672,56 +672,52 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
> tgt->sq_mem_size = (tgt->sq_mem_size + (CNIC_PAGE_SIZE - 1)) &
> CNIC_PAGE_MASK;
>
> - tgt->sq = dma_alloc_coherent(&hba->pcidev->dev, tgt->sq_mem_size,
> - &tgt->sq_dma, GFP_KERNEL);
> + tgt->sq = dma_zalloc_coherent(&hba->pcidev->dev, tgt->sq_mem_size,
> + &tgt->sq_dma, GFP_KERNEL);
> if (!tgt->sq) {
> printk(KERN_ERR PFX "unable to allocate SQ memory %d\n",
> tgt->sq_mem_size);
> goto mem_alloc_failure;
> }
> - memset(tgt->sq, 0, tgt->sq_mem_size);
>
> /* Allocate and map CQ */
> tgt->cq_mem_size = tgt->max_cqes * BNX2FC_CQ_WQE_SIZE;
> tgt->cq_mem_size = (tgt->cq_mem_size + (CNIC_PAGE_SIZE - 1)) &
> CNIC_PAGE_MASK;
>
> - tgt->cq = dma_alloc_coherent(&hba->pcidev->dev, tgt->cq_mem_size,
> - &tgt->cq_dma, GFP_KERNEL);
> + tgt->cq = dma_zalloc_coherent(&hba->pcidev->dev, tgt->cq_mem_size,
> + &tgt->cq_dma, GFP_KERNEL);
> if (!tgt->cq) {
> printk(KERN_ERR PFX "unable to allocate CQ memory %d\n",
> tgt->cq_mem_size);
> goto mem_alloc_failure;
> }
> - memset(tgt->cq, 0, tgt->cq_mem_size);
>
> /* Allocate and map RQ and RQ PBL */
> tgt->rq_mem_size = tgt->max_rqes * BNX2FC_RQ_WQE_SIZE;
> tgt->rq_mem_size = (tgt->rq_mem_size + (CNIC_PAGE_SIZE - 1)) &
> CNIC_PAGE_MASK;
>
> - tgt->rq = dma_alloc_coherent(&hba->pcidev->dev, tgt->rq_mem_size,
> - &tgt->rq_dma, GFP_KERNEL);
> + tgt->rq = dma_zalloc_coherent(&hba->pcidev->dev, tgt->rq_mem_size,
> + &tgt->rq_dma, GFP_KERNEL);
> if (!tgt->rq) {
> printk(KERN_ERR PFX "unable to allocate RQ memory %d\n",
> tgt->rq_mem_size);
> goto mem_alloc_failure;
> }
> - memset(tgt->rq, 0, tgt->rq_mem_size);
>
> tgt->rq_pbl_size = (tgt->rq_mem_size / CNIC_PAGE_SIZE) * sizeof(void *);
> tgt->rq_pbl_size = (tgt->rq_pbl_size + (CNIC_PAGE_SIZE - 1)) &
> CNIC_PAGE_MASK;
>
> - tgt->rq_pbl = dma_alloc_coherent(&hba->pcidev->dev, tgt->rq_pbl_size,
> - &tgt->rq_pbl_dma, GFP_KERNEL);
> + tgt->rq_pbl = dma_zalloc_coherent(&hba->pcidev->dev, tgt->rq_pbl_size,
> + &tgt->rq_pbl_dma, GFP_KERNEL);
> if (!tgt->rq_pbl) {
> printk(KERN_ERR PFX "unable to allocate RQ PBL %d\n",
> tgt->rq_pbl_size);
> goto mem_alloc_failure;
> }
>
> - memset(tgt->rq_pbl, 0, tgt->rq_pbl_size);
> num_pages = tgt->rq_mem_size / CNIC_PAGE_SIZE;
> page = tgt->rq_dma;
> pbl = (u32 *)tgt->rq_pbl;
> @@ -739,44 +735,43 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
> tgt->xferq_mem_size = (tgt->xferq_mem_size + (CNIC_PAGE_SIZE - 1)) &
> CNIC_PAGE_MASK;
>
> - tgt->xferq = dma_alloc_coherent(&hba->pcidev->dev, tgt->xferq_mem_size,
> - &tgt->xferq_dma, GFP_KERNEL);
> + tgt->xferq = dma_zalloc_coherent(&hba->pcidev->dev,
> + tgt->xferq_mem_size, &tgt->xferq_dma,
> + GFP_KERNEL);
> if (!tgt->xferq) {
> printk(KERN_ERR PFX "unable to allocate XFERQ %d\n",
> tgt->xferq_mem_size);
> goto mem_alloc_failure;
> }
> - memset(tgt->xferq, 0, tgt->xferq_mem_size);
>
> /* Allocate and map CONFQ & CONFQ PBL */
> tgt->confq_mem_size = tgt->max_sqes * BNX2FC_CONFQ_WQE_SIZE;
> tgt->confq_mem_size = (tgt->confq_mem_size + (CNIC_PAGE_SIZE - 1)) &
> CNIC_PAGE_MASK;
>
> - tgt->confq = dma_alloc_coherent(&hba->pcidev->dev, tgt->confq_mem_size,
> - &tgt->confq_dma, GFP_KERNEL);
> + tgt->confq = dma_zalloc_coherent(&hba->pcidev->dev,
> + tgt->confq_mem_size, &tgt->confq_dma,
> + GFP_KERNEL);
> if (!tgt->confq) {
> printk(KERN_ERR PFX "unable to allocate CONFQ %d\n",
> tgt->confq_mem_size);
> goto mem_alloc_failure;
> }
> - memset(tgt->confq, 0, tgt->confq_mem_size);
>
> tgt->confq_pbl_size =
> (tgt->confq_mem_size / CNIC_PAGE_SIZE) * sizeof(void *);
> tgt->confq_pbl_size =
> (tgt->confq_pbl_size + (CNIC_PAGE_SIZE - 1)) & CNIC_PAGE_MASK;
>
> - tgt->confq_pbl = dma_alloc_coherent(&hba->pcidev->dev,
> - tgt->confq_pbl_size,
> - &tgt->confq_pbl_dma, GFP_KERNEL);
> + tgt->confq_pbl = dma_zalloc_coherent(&hba->pcidev->dev,
> + tgt->confq_pbl_size,
> + &tgt->confq_pbl_dma, GFP_KERNEL);
> if (!tgt->confq_pbl) {
> printk(KERN_ERR PFX "unable to allocate CONFQ PBL %d\n",
> tgt->confq_pbl_size);
> goto mem_alloc_failure;
> }
>
> - memset(tgt->confq_pbl, 0, tgt->confq_pbl_size);
> num_pages = tgt->confq_mem_size / CNIC_PAGE_SIZE;
> page = tgt->confq_dma;
> pbl = (u32 *)tgt->confq_pbl;
> @@ -792,15 +787,14 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
> /* Allocate and map ConnDB */
> tgt->conn_db_mem_size = sizeof(struct fcoe_conn_db);
>
> - tgt->conn_db = dma_alloc_coherent(&hba->pcidev->dev,
> - tgt->conn_db_mem_size,
> - &tgt->conn_db_dma, GFP_KERNEL);
> + tgt->conn_db = dma_zalloc_coherent(&hba->pcidev->dev,
> + tgt->conn_db_mem_size,
> + &tgt->conn_db_dma, GFP_KERNEL);
> if (!tgt->conn_db) {
> printk(KERN_ERR PFX "unable to allocate conn_db %d\n",
> tgt->conn_db_mem_size);
> goto mem_alloc_failure;
> }
> - memset(tgt->conn_db, 0, tgt->conn_db_mem_size);
>
>
> /* Allocate and map LCQ */
> @@ -808,15 +802,14 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
> tgt->lcq_mem_size = (tgt->lcq_mem_size + (CNIC_PAGE_SIZE - 1)) &
> CNIC_PAGE_MASK;
>
> - tgt->lcq = dma_alloc_coherent(&hba->pcidev->dev, tgt->lcq_mem_size,
> - &tgt->lcq_dma, GFP_KERNEL);
> + tgt->lcq = dma_zalloc_coherent(&hba->pcidev->dev, tgt->lcq_mem_size,
> + &tgt->lcq_dma, GFP_KERNEL);
>
> if (!tgt->lcq) {
> printk(KERN_ERR PFX "unable to allocate lcq %d\n",
> tgt->lcq_mem_size);
> goto mem_alloc_failure;
> }
> - memset(tgt->lcq, 0, tgt->lcq_mem_size);
>
> tgt->conn_db->rq_prod = 0x8000;
>
>
Conversion looks sane.
Acked-by: Chad Dupuis <[email protected]>
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
Himanshu,
> Use dma_zalloc_coherent and vzalloc instead of dma_alloc_coherent and
> vmalloc respectively, followed by memset 0.
Applied to 4.16/scsi-queue.
--
Martin K. Petersen Oracle Linux Engineering
Himanshu,
> Use vzalloc instead of vmalloc followed by memset 0.
Applied to 4.16/scsi-queue.
--
Martin K. Petersen Oracle Linux Engineering
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
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!
--
Martin K. Petersen Oracle Linux Engineering
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!
--
Martin K. Petersen Oracle Linux Engineering
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
Himanshu,
> 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
>
> But do I also need to send those mentioned above, which didn't receive
> any response from you ?
I typically only merge cleanup patches if the driver maintainer acks
them. So you should poke the relevant maintainers.
--
Martin K. Petersen Oracle Linux Engineering