Skip to contentSkip to conversation

scsi: qla2xxx: Remove unnecessary call to memset

PATCH In review Alex Dewar 3 participants 9 messages Aug 20, 2020 – Sep 3, 2020

Subsystems (4)
lore
Share & tools
lore

Alex Dewar

author
#0 lore raw

PATCH 1/1 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.

---
 drivers/scsi/qla2xxx/qla_mbx.c | 2 --
 1 file changed, 2 deletions(-)
drivers/scsi/qla2xxx/qla_mbx.c +0 -2
index 226f1428d3e5..e00f604bbf7a 100644
@@ -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;
Signature · 1 line
2.28.0
author
#1 lore raw

PATCH v2 1/1 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.

---
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(-)
drivers/scsi/mpt3sas/mpt3sas_base.c +0 -1
index b66d3f9b717f..36b6c0d67353 100644
@@ -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",
drivers/scsi/mvsas/mv_init.c +0 -4
index 978f5283c883..6aa2697c4a15 100644
@@ -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,
drivers/scsi/pmcraid.c +0 -1
index aa9ae2ae8579..d99568fdf4af 100644
@@ -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;
drivers/scsi/qla2xxx/qla_mbx.c +0 -2
index 226f1428d3e5..e00f604bbf7a 100644
@@ -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;
Signature · 1 line
2.28.0
author
#2 lore raw

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

Quoted 6 lines · Alex Dewar

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

Issue identified with Coccinelle.

Gentle ping? I've just realised that this is the one we want, not the v1 I just replied to.

Quoted 79 lines

---
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(-)
drivers/scsi/mpt3sas/mpt3sas_base.c +0 -1
index b66d3f9b717f..36b6c0d67353 100644
@@ -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",
drivers/scsi/mvsas/mv_init.c +0 -4
index 978f5283c883..6aa2697c4a15 100644
@@ -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,
drivers/scsi/pmcraid.c +0 -1
index aa9ae2ae8579..d99568fdf4af 100644
@@ -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;
drivers/scsi/qla2xxx/qla_mbx.c +0 -2
index 226f1428d3e5..e00f604bbf7a 100644
@@ -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;
#3 lore raw

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

In reply to Alex Dewar

Alex,

Quoted 2 lines

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

One patch per driver, please.

Thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
author
#4 lore raw

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

Quoted 7 lines · Martin K. Petersen

Alex,

Quoted 2 lines

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.

Quoted 5 lines

Thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
author
#5 lore raw

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

In reply to Martin K. Petersen
Quoted 7 lines · Martin K. Petersen

Alex,

Quoted 2 lines

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!

Quoted 5 lines

Thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#6 lore raw

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

Alex,

Quoted 1 line

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

Yep, that one was already fixed up. Thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
author
#7 lore raw
In reply to Alex Dewar
Quoted 7 lines · Alex Dewar

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.

Gentle ping?

Quoted 17 lines
---
  drivers/scsi/qla2xxx/qla_mbx.c | 2 --
  1 file changed, 2 deletions(-)
drivers/scsi/qla2xxx/qla_mbx.c +0 -2
index 226f1428d3e5..e00f604bbf7a 100644
@@ -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;
#8 lore raw
Quoted 14 lines · Alex Dewar
Quoted 7 lines · Alex Dewar

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.

Gentle ping?

Quoted 4 lines
---
  drivers/scsi/qla2xxx/qla_mbx.c | 2 --
  1 file changed, 2 deletions(-)
Quoted 14 lines

drivers/scsi/qla2xxx/qla_mbx.c qla25xx_set_els_cmds_supported(scsi_qla_host_t *vha) · line 4930

Quoted 12 lines
drivers/scsi/qla2xxx/qla_mbx.c +0 -1
index 226f1428d3e5..e00f604bbf7a 100644
@@ -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