2020-08-20 18:53:47

by Alex Dewar

[permalink] [raw]
Subject: [PATCH] scsi: qla2xxx: Remove unnecessary call to memset

In qla25xx_set_els_cmds_supported(), a call is made to
dma_alloc_coherent() followed by zeroing the memory with memset. This is
unnecessary as dma_alloc_coherent() already zeros memory. Remove.

Issue identified with Coccinelle.

Signed-off-by: Alex Dewar <[email protected]>
---
drivers/scsi/qla2xxx/qla_mbx.c | 2 --
1 file changed, 2 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
index 226f1428d3e5..e00f604bbf7a 100644
--- a/drivers/scsi/qla2xxx/qla_mbx.c
+++ b/drivers/scsi/qla2xxx/qla_mbx.c
@@ -4925,8 +4925,6 @@ qla25xx_set_els_cmds_supported(scsi_qla_host_t *vha)
return QLA_MEMORY_ALLOC_FAILED;
}

- memset(els_cmd_map, 0, ELS_CMD_MAP_SIZE);
-
/* List of Purex ELS */
cmd_opcode[0] = ELS_FPIN;
cmd_opcode[1] = ELS_RDP;
--
2.28.0


2020-08-21 00:03:59

by Alex Dewar

[permalink] [raw]
Subject: [PATCH v2] scsi: Don't call memset after dma_alloc_coherent()

dma_alloc_coherent() already zeroes memory, so the extra call to
memset() is unnecessary.

Issue identified with Coccinelle.

Signed-off-by: Alex Dewar <[email protected]>
---
v2: I've noticed a few other places in the scsi subsystem with this
pattern, so lets fix them all with one patch.
---
drivers/scsi/mpt3sas/mpt3sas_base.c | 1 -
drivers/scsi/mvsas/mv_init.c | 4 ----
drivers/scsi/pmcraid.c | 1 -
drivers/scsi/qla2xxx/qla_mbx.c | 2 --
4 files changed, 8 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
index b66d3f9b717f..36b6c0d67353 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -5259,7 +5259,6 @@ _base_allocate_memory_pools(struct MPT3SAS_ADAPTER *ioc)
_base_release_memory_pools(ioc);
goto retry_allocation;
}
- memset(ioc->request, 0, sz);

if (retry_sz)
ioc_err(ioc, "request pool: dma_alloc_coherent succeed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), total(%d kb)\n",
diff --git a/drivers/scsi/mvsas/mv_init.c b/drivers/scsi/mvsas/mv_init.c
index 978f5283c883..6aa2697c4a15 100644
--- a/drivers/scsi/mvsas/mv_init.c
+++ b/drivers/scsi/mvsas/mv_init.c
@@ -246,19 +246,16 @@ static int mvs_alloc(struct mvs_info *mvi, struct Scsi_Host *shost)
&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);
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);
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;

@@ -267,7 +264,6 @@ static int mvs_alloc(struct mvs_info *mvi, struct Scsi_Host *shost)
&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,
diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index aa9ae2ae8579..d99568fdf4af 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -4716,7 +4716,6 @@ static int pmcraid_allocate_host_rrqs(struct pmcraid_instance *pinstance)
return -ENOMEM;
}

- memset(pinstance->hrrq_start[i], 0, buffer_size);
pinstance->hrrq_curr[i] = pinstance->hrrq_start[i];
pinstance->hrrq_end[i] =
pinstance->hrrq_start[i] + PMCRAID_MAX_CMD - 1;
diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
index 226f1428d3e5..e00f604bbf7a 100644
--- a/drivers/scsi/qla2xxx/qla_mbx.c
+++ b/drivers/scsi/qla2xxx/qla_mbx.c
@@ -4925,8 +4925,6 @@ qla25xx_set_els_cmds_supported(scsi_qla_host_t *vha)
return QLA_MEMORY_ALLOC_FAILED;
}

- memset(els_cmd_map, 0, ELS_CMD_MAP_SIZE);
-
/* List of Purex ELS */
cmd_opcode[0] = ELS_FPIN;
cmd_opcode[1] = ELS_RDP;
--
2.28.0

2020-08-24 21:46:05

by Alex Dewar

[permalink] [raw]
Subject: Re: [PATCH] scsi: qla2xxx: Remove unnecessary call to memset

On 2020-08-20 19:51, Alex Dewar wrote:
> In qla25xx_set_els_cmds_supported(), a call is made to
> dma_alloc_coherent() followed by zeroing the memory with memset. This is
> unnecessary as dma_alloc_coherent() already zeros memory. Remove.
>
> Issue identified with Coccinelle.
>
> Signed-off-by: Alex Dewar <[email protected]>
Gentle ping?
> ---
> drivers/scsi/qla2xxx/qla_mbx.c | 2 --
> 1 file changed, 2 deletions(-)
>
> diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
> index 226f1428d3e5..e00f604bbf7a 100644
> --- a/drivers/scsi/qla2xxx/qla_mbx.c
> +++ b/drivers/scsi/qla2xxx/qla_mbx.c
> @@ -4925,8 +4925,6 @@ qla25xx_set_els_cmds_supported(scsi_qla_host_t *vha)
> return QLA_MEMORY_ALLOC_FAILED;
> }
>
> - memset(els_cmd_map, 0, ELS_CMD_MAP_SIZE);
> -
> /* List of Purex ELS */
> cmd_opcode[0] = ELS_FPIN;
> cmd_opcode[1] = ELS_RDP;

2020-08-24 21:56:01

by Alex Dewar

[permalink] [raw]
Subject: Re: [PATCH v2] scsi: Don't call memset after dma_alloc_coherent()

On 2020-08-21 00:49, Alex Dewar wrote:
> dma_alloc_coherent() already zeroes memory, so the extra call to
> memset() is unnecessary.
>
> Issue identified with Coccinelle.
>
> Signed-off-by: Alex Dewar <[email protected]>
Gentle ping? I've just realised that this is the one we want, not the v1
I just replied to.
> ---
> v2: I've noticed a few other places in the scsi subsystem with this
> pattern, so lets fix them all with one patch.
> ---
> drivers/scsi/mpt3sas/mpt3sas_base.c | 1 -
> drivers/scsi/mvsas/mv_init.c | 4 ----
> drivers/scsi/pmcraid.c | 1 -
> drivers/scsi/qla2xxx/qla_mbx.c | 2 --
> 4 files changed, 8 deletions(-)
>
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
> index b66d3f9b717f..36b6c0d67353 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_base.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
> @@ -5259,7 +5259,6 @@ _base_allocate_memory_pools(struct MPT3SAS_ADAPTER *ioc)
> _base_release_memory_pools(ioc);
> goto retry_allocation;
> }
> - memset(ioc->request, 0, sz);
>
> if (retry_sz)
> ioc_err(ioc, "request pool: dma_alloc_coherent succeed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), total(%d kb)\n",
> diff --git a/drivers/scsi/mvsas/mv_init.c b/drivers/scsi/mvsas/mv_init.c
> index 978f5283c883..6aa2697c4a15 100644
> --- a/drivers/scsi/mvsas/mv_init.c
> +++ b/drivers/scsi/mvsas/mv_init.c
> @@ -246,19 +246,16 @@ static int mvs_alloc(struct mvs_info *mvi, struct Scsi_Host *shost)
> &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);
> 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);
> 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;
>
> @@ -267,7 +264,6 @@ static int mvs_alloc(struct mvs_info *mvi, struct Scsi_Host *shost)
> &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,
> diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
> index aa9ae2ae8579..d99568fdf4af 100644
> --- a/drivers/scsi/pmcraid.c
> +++ b/drivers/scsi/pmcraid.c
> @@ -4716,7 +4716,6 @@ static int pmcraid_allocate_host_rrqs(struct pmcraid_instance *pinstance)
> return -ENOMEM;
> }
>
> - memset(pinstance->hrrq_start[i], 0, buffer_size);
> pinstance->hrrq_curr[i] = pinstance->hrrq_start[i];
> pinstance->hrrq_end[i] =
> pinstance->hrrq_start[i] + PMCRAID_MAX_CMD - 1;
> diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
> index 226f1428d3e5..e00f604bbf7a 100644
> --- a/drivers/scsi/qla2xxx/qla_mbx.c
> +++ b/drivers/scsi/qla2xxx/qla_mbx.c
> @@ -4925,8 +4925,6 @@ qla25xx_set_els_cmds_supported(scsi_qla_host_t *vha)
> return QLA_MEMORY_ALLOC_FAILED;
> }
>
> - memset(els_cmd_map, 0, ELS_CMD_MAP_SIZE);
> -
> /* List of Purex ELS */
> cmd_opcode[0] = ELS_FPIN;
> cmd_opcode[1] = ELS_RDP;

2020-08-26 16:39:09

by Arun Easi

[permalink] [raw]
Subject: Re: [PATCH] scsi: qla2xxx: Remove unnecessary call to memset

On Mon, 24 Aug 2020, 2:42pm, Alex Dewar wrote:

>
> On 2020-08-20 19:51, Alex Dewar wrote:
> > In qla25xx_set_els_cmds_supported(), a call is made to
> > dma_alloc_coherent() followed by zeroing the memory with memset. This is
> > unnecessary as dma_alloc_coherent() already zeros memory. Remove.
> >
> > Issue identified with Coccinelle.
> >
> > Signed-off-by: Alex Dewar <[email protected]>
> Gentle ping?
> > ---
> > drivers/scsi/qla2xxx/qla_mbx.c | 2 --
> > 1 file changed, 2 deletions(-)
> >
> > diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
> > index 226f1428d3e5..e00f604bbf7a 100644
> > --- a/drivers/scsi/qla2xxx/qla_mbx.c
> > +++ b/drivers/scsi/qla2xxx/qla_mbx.c
> > @@ -4925,8 +4925,6 @@ qla25xx_set_els_cmds_supported(scsi_qla_host_t *vha)
> > return QLA_MEMORY_ALLOC_FAILED;
> > }
> > - memset(els_cmd_map, 0, ELS_CMD_MAP_SIZE);
> > -
> > /* List of Purex ELS */
> > cmd_opcode[0] = ELS_FPIN;
> > cmd_opcode[1] = ELS_RDP;
>
>

Looks good.

Regards,
-Arun

2020-09-02 01:25:18

by Martin K. Petersen

[permalink] [raw]
Subject: Re: [PATCH v2] scsi: Don't call memset after dma_alloc_coherent()


Alex,

> dma_alloc_coherent() already zeroes memory, so the extra call to
> memset() is unnecessary.

One patch per driver, please.

Thanks!

--
Martin K. Petersen Oracle Linux Engineering

2020-09-02 15:53:07

by Alex Dewar

[permalink] [raw]
Subject: Re: [PATCH v2] scsi: Don't call memset after dma_alloc_coherent()

On Tue, Sep 01, 2020 at 09:22:44PM -0400, Martin K. Petersen wrote:
>
> Alex,
>
> > dma_alloc_coherent() already zeroes memory, so the extra call to
> > memset() is unnecessary.
>
> One patch per driver, please.

There's a single patch for QLA2XXX already submitted: https://lore.kernel.org/lkml/[email protected]/

I'll send separate patches for the other cases.

>
> Thanks!
>
> --
> Martin K. Petersen Oracle Linux Engineering

2020-09-02 16:05:43

by Alex Dewar

[permalink] [raw]
Subject: Re: [PATCH v2] scsi: Don't call memset after dma_alloc_coherent()

On Tue, Sep 01, 2020 at 09:22:44PM -0400, Martin K. Petersen wrote:
>
> Alex,
>
> > dma_alloc_coherent() already zeroes memory, so the extra call to
> > memset() is unnecessary.
>
> One patch per driver, please.

Nvm, someone's already beaten me to the punch!
>
> Thanks!
>
> --
> Martin K. Petersen Oracle Linux Engineering

2020-09-03 01:30:18

by Martin K. Petersen

[permalink] [raw]
Subject: Re: [PATCH v2] scsi: Don't call memset after dma_alloc_coherent()


Alex,

> Nvm, someone's already beaten me to the punch!

Yep, that one was already fixed up. Thanks!

--
Martin K. Petersen Oracle Linux Engineering