linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: qla2xxx: Use a variable for repeated mem_size computation
@ 2023-01-08 20:38 Deepak R Varma
  2023-01-22 19:18 ` Deepak R Varma
  2023-01-23 18:41 ` Himanshu Madhani
  0 siblings, 2 replies; 3+ messages in thread
From: Deepak R Varma @ 2023-01-08 20:38 UTC (permalink / raw)
  To: Nilesh Javali, GR-QLogic-Storage-Upstream, James E.J. Bottomley,
	Martin K. Petersen, linux-scsi, linux-kernel
  Cc: Saurabh Singh Sengar, Praveen Kumar

Use a variable to upfront compute memory size to be allocated, instead of
repeatedly computing the memory size at different instructions. The reduced
instruction length 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(-)

diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.c b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
index 8fa0056b56dd..8024322c9c5a 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 map_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)));
+	map_sz = array_size(65536, sizeof(struct tcm_qla2xxx_fc_loopid));
+
+	lport->lport_loopid_map = vzalloc(map_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", map_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", map_sz);
 	return 0;
 }
 
-- 
2.34.1




^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi: qla2xxx: Use a variable for repeated mem_size computation
  2023-01-08 20:38 [PATCH] scsi: qla2xxx: Use a variable for repeated mem_size computation Deepak R Varma
@ 2023-01-22 19:18 ` Deepak R Varma
  2023-01-23 18:41 ` Himanshu Madhani
  1 sibling, 0 replies; 3+ messages in thread
From: Deepak R Varma @ 2023-01-22 19:18 UTC (permalink / raw)
  To: Nilesh Javali, GR-QLogic-Storage-Upstream, James E.J. Bottomley,
	Martin K. Petersen, linux-scsi, linux-kernel
  Cc: Saurabh Singh Sengar, Praveen Kumar

On Mon, Jan 09, 2023 at 02:08:24AM +0530, Deepak R Varma wrote:
> Use a variable to upfront compute memory size to be allocated, instead of
> repeatedly computing the memory size at different instructions. The reduced
> instruction length 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>
> ---

Hello,
May I request a review and feedback comments on this patch proposal?

Thank you,
./drv

>  drivers/scsi/qla2xxx/tcm_qla2xxx.c | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.c b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
> index 8fa0056b56dd..8024322c9c5a 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 map_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)));
> +	map_sz = array_size(65536, sizeof(struct tcm_qla2xxx_fc_loopid));
> +
> +	lport->lport_loopid_map = vzalloc(map_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", map_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", map_sz);
>  	return 0;
>  }
>  
> -- 
> 2.34.1
> 
> 
> 



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi: qla2xxx: Use a variable for repeated mem_size computation
  2023-01-08 20:38 [PATCH] scsi: qla2xxx: Use a variable for repeated mem_size computation Deepak R Varma
  2023-01-22 19:18 ` Deepak R Varma
@ 2023-01-23 18:41 ` Himanshu Madhani
  1 sibling, 0 replies; 3+ messages in thread
From: Himanshu Madhani @ 2023-01-23 18:41 UTC (permalink / raw)
  To: Deepak R Varma
  Cc: Nilesh Javali, GR-QLogic-Storage-Upstream, James E.J. Bottomley,
	Martin Petersen, linux-scsi, open list, Saurabh Singh Sengar,
	Praveen Kumar



> On Jan 8, 2023, at 12:38 PM, Deepak R Varma <drv@mailo.com> wrote:
> 
> Use a variable to upfront compute memory size to be allocated, instead of
> repeatedly computing the memory size at different instructions. The reduced
> instruction length 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(-)
> 
> diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.c b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
> index 8fa0056b56dd..8024322c9c5a 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 map_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)));
> + map_sz = array_size(65536, sizeof(struct tcm_qla2xxx_fc_loopid));
> +
> + lport->lport_loopid_map = vzalloc(map_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", map_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", map_sz);
> return 0;
> }
> 
> -- 
> 2.34.1
> 
> 
> 

Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com <mailto:himanshu.madhani@oracle.com>>

-- 
Himanshu Madhani Oracle Linux Engineering


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-23 18:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-08 20:38 [PATCH] scsi: qla2xxx: Use a variable for repeated mem_size computation Deepak R Varma
2023-01-22 19:18 ` Deepak R Varma
2023-01-23 18:41 ` Himanshu Madhani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).