All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RESEND] scsi: fnic: Use a variable for repeated mem_size computation
@ 2023-03-01 20:04 Deepak R Varma
  0 siblings, 0 replies; only message in thread
From: Deepak R Varma @ 2023-03-01 20:04 UTC (permalink / raw)
  To: Satish Kharat, Sesidhar Baddela, Karan Tilak Kumar,
	James E.J. Bottomley, Martin K. Petersen, linux-scsi,
	linux-kernel
  Cc: Saurabh Singh Sengar, Praveen Kumar, Deepak R Varma

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>
---
Note:
   Proposed change compile tested only.
   Resending patch for review and feedback. No functional changes.


 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




^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-01 20:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-01 20:04 [PATCH RESEND] scsi: fnic: Use a variable for repeated mem_size computation Deepak R Varma

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.