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: 42135 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3478346wrt; Wed, 11 Jan 2023 10:40:12 -0800 (PST) X-Google-Smtp-Source: AMrXdXven8v4NWCM0a9RuxrfdM/IZApcy8e+pliRlOLY0AkEIjikQnx/w3ZQcVBvzJJK9xPWrJbF X-Received: by 2002:a17:906:4f14:b0:7c1:98e:ed20 with SMTP id t20-20020a1709064f1400b007c1098eed20mr59124194eju.35.1673462412100; Wed, 11 Jan 2023 10:40:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673462412; cv=none; d=google.com; s=arc-20160816; b=VWI2OyHdQRvNeOkkaAlKreMp7arRBS/ZYrG7TVv+OMwdDG1raw4aB8bHiFxBqVQbij f4Lratl271lO9J1gAF+A2SNQ9TfFtJB4rCzezWv4km1fA2ZO8WRTfZ6huTVpcpLPjEzJ MWFIm9SVDXST3g0PPaKcuoCpgDXrIytCZvgpvJMegf6xm9nHbiygLYNYR0NB8s9mHGcB zSOj00D8ER1CxOKSBIeJ08Z/JoqeFrKbB2Det0GSVl0Tu8lGT77OaMDv0af9g5ifrj2H ebHqrf8N/wh+kY2D5advid4Qnv6WO63dhLOKJMVy4kL6Pyo/dJpHKawPcjdPyKxHhp27 1R+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=g5FNDz2Y38tQIvQQbwVZkjOUHNuXMk6IgXwScjEyb/I=; b=duINl+GF7AdgV7ML/jqaz1L731dRNdTrujMPIHBgy3h9igAISPuDxmW1ahg5R59vB1 JETdkrCXNJG6IO5RdLeBmyuRFvFICRbNyaz5uBhjZ50nXtMhuJ+MQjrHfkAyHRmGzYbb 0Rqf7y0DSpUBJAOH3A42NuVvGSmU6yF4Ph0tCDLYgy9B7yFPlslHRfPrSyKCt7Cd5R4O L4r9eeXyiaFUoFX7UM5ofi+yU3AYqPcNgMOyW/90E95OQr2w0lFG0v1kk/yyYm0tv4M/ R7S4pAx2/hMdx2qw39fkuOiCj8Y5zxMmT/W+P4LrZJFrr5vrgGKqgC6oKd+4/0xLcWU2 T4mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=byQttjl9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hd41-20020a17090796a900b007c0fb283f11si17468281ejc.130.2023.01.11.10.39.47; Wed, 11 Jan 2023 10:40:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=byQttjl9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235157AbjAKS1J (ORCPT + 99 others); Wed, 11 Jan 2023 13:27:09 -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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754752522035410992?= X-GMAIL-MSGID: =?utf-8?q?1754752522035410992?= 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;