From patchwork Wed Jan 11 18:26:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak R Varma X-Patchwork-Id: 13097089 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66686C46467 for ; Wed, 11 Jan 2023 18:27:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235788AbjAKS1F (ORCPT ); Wed, 11 Jan 2023 13:27:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235083AbjAKS0s (ORCPT ); Wed, 11 Jan 2023 13:26:48 -0500 Received: from msg-2.mailo.com (msg-2.mailo.com [213.182.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFBFB7648; Wed, 11 Jan 2023 10:26:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1673461595; bh=ZEFNU6Bq5v0szLbAfyz11SsYCq9Rp5RsT/ZKh16Bw3A=; h=X-EA-Auth:Date:From:To:Cc:Subject:Message-ID:MIME-Version: Content-Type; b=byQttjl9jXajgHv39vyHxBZpiccy5AouO1rLiXl4u3l2eM7F1AKRxOf7h4YOtiUnx Dn/wViTsp6ruUmunqHz0CKnQbmeWj+DS0UTpMMHDT4Cca4gY5DnyiU9EbrQy+SakrI 8xPKecseqx5bX9+7fnFNp9GnAof1zdMi6el362Po= Received: by b-3.in.mailobj.net [192.168.90.13] with ESMTP via ip-206.mailobj.net [213.182.55.206] Wed, 11 Jan 2023 19:26:35 +0100 (CET) X-EA-Auth: W8eyzXTeMQGkBkwmIgvJiFt+ALPC5ui0yJ2x+jD3Xlx2w09rbbzJeDzZlFUwrhU4q4h6sG/N0GcbofPjX9yrxAaMWCKK+4HI Date: Wed, 11 Jan 2023 23:56:31 +0530 From: Deepak R Varma To: Satish Kharat , Sesidhar Baddela , Karan Tilak Kumar , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Saurabh Singh Sengar , Praveen Kumar Subject: [PATCH] scsi: fnic: Use a variable for repeated mem_size computation Message-ID: MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org 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 --- 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;