From patchwork Wed Mar 1 20:04:33 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: 63065 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3845832wrd; Wed, 1 Mar 2023 12:15:22 -0800 (PST) X-Google-Smtp-Source: AK7set9UX5uWJlLBS8dpzlKZFTO5ycwFa8cwugLHPeoFF8F2NE3+jIyr4jyaqAImh37cKdJR5jU7 X-Received: by 2002:a05:6a21:338f:b0:cc:d891:b2ad with SMTP id yy15-20020a056a21338f00b000ccd891b2admr8881063pzb.20.1677701722273; Wed, 01 Mar 2023 12:15:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677701722; cv=none; d=google.com; s=arc-20160816; b=Bw0W6qn+8H0jc9gYpRFZcpGwIBqSXEzPagTCI8t+SYTqpRTpcZU88kwVXALV2FVVNT AOcb2dA5nx1WRniO+wp+Q9tGQ4tMTSsUmql3fAYNjFux8JOFL1ijxTmTzKyLQmvyE0oE KWATu2qJSI3eO2IPv1PE9NqsyOcJGC3OgHo7VIlkOMTOKAa+b5BbbWavWY5GiRbXZyN7 notcptzwGbpiicUJQ48UeTnutVZ/JGTeg33mPyjknZ6wWBXm7aEwfCJ8vnqIIqAo89MB fxyzyTTKLOR7jHfcKXtEzIg+Sn3IccxBPGwiV0zvzpjfxB7BCuj9aJwtsyPsW57YVSaG x4tg== 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=Sv3AnS16C2iEA4BVE6+XH/YalXf3btRU/m8dREqU9ng=; b=BzR9rxyzq83xg9jLYrQZ2aEB+vVe3HH3CbpLjRsI3dUpo2gK1ZuuQrzBf2p/oeiAmd oLQk7rhm/UE6arhIqTeQmUKDVnyJfMzrihL0Xqj7k7KEFX7NxQF7Hw4GT8PX74E36ZyR BekebmDkxm43w0tzgvsf4ZuWIKrTpGcZiod+W4JqdzBk9x1OecsYZQp4balQVb/WoBHu MVASejinJX19AHFKTfwt6EmGyUebhiEx4qpa5k7uYAOSWjrrk4f5iib/BoUPQC7xFFH+ CVAuVmfcv1n+i1Hnc4nxJxLuhBEoTemhj24BJgCO5VP7QVOJoNrICY0opYcSnuUAd4N8 4OTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b="QHsEMb/K"; 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 b9-20020a633409000000b004fc26d41be6si3590413pga.72.2023.03.01.12.15.06; Wed, 01 Mar 2023 12:15:22 -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="QHsEMb/K"; 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 S229871AbjCAUFD (ORCPT + 99 others); Wed, 1 Mar 2023 15:05:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229953AbjCAUEy (ORCPT ); Wed, 1 Mar 2023 15:04:54 -0500 Received: from msg-4.mailo.com (msg-4.mailo.com [213.182.54.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B6214ECE8; Wed, 1 Mar 2023 12:04:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1677701077; bh=SkxO6ocDDrslWnzemAIXgnlRsRGtgWAqK1nWvppSEB8=; h=X-EA-Auth:Date:From:To:Cc:Subject:Message-ID:MIME-Version: Content-Type; b=QHsEMb/KrTcnyTB6UNjavqfGLt1j2d1fL0ym1Suwoa53CBCVnZBY7kmt9j2zCznL2 MdC56njcZuDWLnsStfHtIq+p+T7WUQ/oQZdeKXTtmPAwOuEvBlVzLLN6+TJ9I8/8rP uIgt49qQJagPTxKgdGptMigRKmTN+arINl4m4Oew= Received: by b221-2.in.mailobj.net [192.168.90.22] with ESMTP via ip-20.mailobj.net [213.182.54.20] Wed, 1 Mar 2023 21:04:37 +0100 (CET) X-EA-Auth: DU2ysQMmY52E4ROFbJqtsDKo9YDpEmEu2WCkbqP9Vr5J2zznwaEaDw2Lq5mgK05twi4f9pSDcMAkBxxx3hn6q8WLeFXa0tjo Date: Thu, 2 Mar 2023 01:34:33 +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 , Deepak R Varma Subject: [PATCH RESEND] 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?1759197761502035477?= X-GMAIL-MSGID: =?utf-8?q?1759197761502035477?= 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 --- 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;