diff mbox series

scsi: qla2xxx: Use a variable instead of repeated computations

Message ID Y9FdOu4Y3KS5eVUf@ubun2204.myguest.virtualbox.org
State New
Headers show
Series scsi: qla2xxx: Use a variable instead of repeated computations | expand

Commit Message

Deepak R Varma Jan. 25, 2023, 4:47 p.m. UTC
Use a variable to upfront compute memory size to be allocated, instead
of repeatedly computing it at different instructions.  The reduced
length of lines also allows to tidy up the code.
Issue identified using the array_size_dup Coccinelle semantic patch.

Signed-off-by: Deepak R Varma <drv@mailo.com>
---
 drivers/scsi/qla2xxx/tcm_qla2xxx.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

Comments

Deepak R Varma Jan. 25, 2023, 5:22 p.m. UTC | #1
On Wed, Jan 25, 2023 at 10:17:54PM +0530, Deepak R Varma wrote:
> Use a variable to upfront compute memory size to be allocated, instead
> of repeatedly computing it at different instructions.  The reduced
> length of lines also allows to tidy up the code.
> Issue identified using the array_size_dup Coccinelle semantic patch.
> 
> Signed-off-by: Deepak R Varma <drv@mailo.com>
> ---

Please ignore this duplicate patch. I got this from a wrong/old branch. My
apologies for the inconvenience.

./drv
diff mbox series

Patch

diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.c b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
index 8fa0056b56dd..5213d107879d 100644
--- a/drivers/scsi/qla2xxx/tcm_qla2xxx.c
+++ b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
@@ -1552,6 +1552,7 @@  static const struct qla_tgt_func_tmpl tcm_qla2xxx_template = {
 static int tcm_qla2xxx_init_lport(struct tcm_qla2xxx_lport *lport)
 {
 	int rc;
+	size_t mem_sz;
 
 	rc = btree_init32(&lport->lport_fcport_map);
 	if (rc) {
@@ -1559,17 +1560,15 @@  static int tcm_qla2xxx_init_lport(struct tcm_qla2xxx_lport *lport)
 		return rc;
 	}
 
-	lport->lport_loopid_map =
-		vzalloc(array_size(65536,
-				   sizeof(struct tcm_qla2xxx_fc_loopid)));
+	mem_sz = array_size(65536, sizeof(struct tcm_qla2xxx_fc_loopid));
+
+	lport->lport_loopid_map = vzalloc(mem_sz);
 	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);
+		pr_err("Unable to allocate lport->lport_loopid_map of %zu bytes\n", mem_sz);
 		btree_destroy32(&lport->lport_fcport_map);
 		return -ENOMEM;
 	}
-	pr_debug("qla2xxx: Allocated lport_loopid_map of %zu bytes\n",
-	       sizeof(struct tcm_qla2xxx_fc_loopid) * 65536);
+	pr_debug("qla2xxx: Allocated lport_loopid_map of %zu bytes\n", mem_sz);
 	return 0;
 }