mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Deepak R Varma <drv@mailo.com>
To: Satish Kharat <satishkh@cisco.com>,
	Sesidhar Baddela <sebaddel@cisco.com>,
	Karan Tilak Kumar <kartilak@cisco.com>,
	"James E.J. Bottomley" <jejb@linux.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Saurabh Singh Sengar <ssengar@microsoft.com>,
	Praveen Kumar <kumarpraveen@linux.microsoft.com>
Subject: Re: [PATCH] scsi: fnic: Use a variable for repeated mem_size computation
Date: Sun, 22 Jan 2023 23:56:07 +0530	[thread overview]
Message-ID: <Y81/v19WDKVIX7Bs@ubun2204.myguest.virtualbox.org> (raw)
In-Reply-To: <Y77/V6Zk6BCisOMY@ubun2204.myguest.virtualbox.org>

On Wed, Jan 11, 2023 at 11:56:31PM +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 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,
Any feedback/review comments on this patch proposal please?

Thank you,
./drv

>  drivers/scsi/fnic/fnic_trace.c | 19 +++++++------------
>  1 file changed, 7 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/scsi/fnic/fnic_trace.c b/drivers/scsi/fnic/fnic_trace.c
> index e03967463561..7b8ef74fc060 100644
> --- a/drivers/scsi/fnic/fnic_trace.c
> +++ b/drivers/scsi/fnic/fnic_trace.c
> @@ -544,12 +544,10 @@ int fnic_fc_trace_init(void)
>  	unsigned long fc_trace_buf_head;
>  	int err = 0;
>  	int i;
> +	size_t mem_sz = array_size(PAGE_SIZE, fnic_fc_trace_max_pages);
>  
> -	fc_trace_max_entries = (fnic_fc_trace_max_pages * PAGE_SIZE)/
> -				FC_TRC_SIZE_BYTES;
> -	fnic_fc_ctlr_trace_buf_p =
> -		(unsigned long)vmalloc(array_size(PAGE_SIZE,
> -						  fnic_fc_trace_max_pages));
> +	fc_trace_max_entries = mem_sz / FC_TRC_SIZE_BYTES;
> +	fnic_fc_ctlr_trace_buf_p = (unsigned long)vmalloc(mem_sz);
>  	if (!fnic_fc_ctlr_trace_buf_p) {
>  		pr_err("fnic: Failed to allocate memory for "
>  		       "FC Control Trace Buf\n");
> @@ -557,13 +555,11 @@ 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);
> +	memset((void *)fnic_fc_ctlr_trace_buf_p, 0, mem_sz);
>  
>  	/* Allocate memory for page offset */
> -	fc_trace_entries.page_offset =
> -		vmalloc(array_size(fc_trace_max_entries,
> -				   sizeof(unsigned long)));
> +	mem_sz = array_size(fc_trace_max_entries, sizeof(unsigned long));
> +	fc_trace_entries.page_offset = vmalloc(mem_sz);
>  	if (!fc_trace_entries.page_offset) {
>  		pr_err("fnic:Failed to allocate memory for page_offset\n");
>  		if (fnic_fc_ctlr_trace_buf_p) {
> @@ -574,8 +570,7 @@ int fnic_fc_trace_init(void)
>  		err = -ENOMEM;
>  		goto err_fnic_fc_ctlr_trace_buf_init;
>  	}
> -	memset((void *)fc_trace_entries.page_offset, 0,
> -	       (fc_trace_max_entries * sizeof(unsigned long)));
> +	memset((void *)fc_trace_entries.page_offset, 0, mem_sz);
>  
>  	fc_trace_entries.rd_idx = fc_trace_entries.wr_idx = 0;
>  	fc_trace_buf_head = fnic_fc_ctlr_trace_buf_p;
> -- 
> 2.34.1
> 
> 
> 



      reply	other threads:[~2023-01-22 18:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-11 18:26 Deepak R Varma
2023-01-22 18:26 ` Deepak R Varma [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y81/v19WDKVIX7Bs@ubun2204.myguest.virtualbox.org \
    --to=drv@mailo.com \
    --cc=jejb@linux.ibm.com \
    --cc=kartilak@cisco.com \
    --cc=kumarpraveen@linux.microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=satishkh@cisco.com \
    --cc=sebaddel@cisco.com \
    --cc=ssengar@microsoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®