From patchwork Wed Jan 25 16:47:54 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: 48214 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp376560wrn; Wed, 25 Jan 2023 08:55:59 -0800 (PST) X-Google-Smtp-Source: AMrXdXuzCgQxTPIMK41GmGiDJQiALap0s91nPmv4bYnlGpffL9B6ieubBAHudblz87Ze2Pdpmjjg X-Received: by 2002:aa7:cc98:0:b0:486:ecd3:15f8 with SMTP id p24-20020aa7cc98000000b00486ecd315f8mr33069682edt.6.1674665759119; Wed, 25 Jan 2023 08:55:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674665759; cv=none; d=google.com; s=arc-20160816; b=sLsGiQ1fiM9n96b7Lc+ZP/wntyF25py1yNCRs5YTwQLcecxOM/sFUSEp7bAIyP6Nwc A7SVG7vfITIxtF38QN0mO9ulNb0MUuA4LUmM0g59cUM+mBCPC3ABDPPD+L0wYa+EWd8X lNsbi4RJx7qawaO0nHwYzIAtlVedRsrOukn9HS9tcwpnMXmDeey1VoGctNZxHyRiHkPk Fn/PqHE6MQ5xSaicY6gsv2eKbhFV4rITFQkeWkZa53dENDbD8OYo54dDFwm6KVTf4zYa HTFALYIcIFCb3FPTpCy8Tx2b92x/tFCOSr91ofzf8m5dlmwVQp96sneRIr1bB4WjmSdX pa7A== 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=pkhY8NGrq4Rel13u3RkK1mvR2NVGylG3xLtUnBD7Tyg=; b=fr2xF2MIzNen7BzPLv18MeAQ912uke08M5d8gG7+poitS/DSzDCutDg4r8tuYn7FOc nsh446G2pWL9PwJLe5Sbge5NewiQP/G4GM8A6L2r23UXyYuttNJ1alz62idQnk50q6D+ XB1afdAFSxq9aB+GrUwbBSMgv7ueRwd1O2y5YawCzlSvjyZNFrl/vN3A29iR3OiQ6yLj SUub+EbwCvjbZz6kEQ9neqxEWChFj2Pxr8BTVB5l8X/tV5q73vT8P/uuHcIobb+NkMDd KZDawqssHuZNPAiYPHZc5S6DETNWpelc5Dqk4CfGc8UhTT8kadZ+Xhf/c+XKIuLNPHhn gi8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=ncCiL+NL; 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 eg27-20020a056402289b00b004a08afeb68asi5626168edb.55.2023.01.25.08.55.35; Wed, 25 Jan 2023 08:55:59 -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=ncCiL+NL; 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 S235892AbjAYQtH (ORCPT + 99 others); Wed, 25 Jan 2023 11:49:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235827AbjAYQsd (ORCPT ); Wed, 25 Jan 2023 11:48:33 -0500 Received: from msg-4.mailo.com (msg-4.mailo.com [213.182.54.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A72BD5649A; Wed, 25 Jan 2023 08:48:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1674665279; bh=x1M00s3nylMDwIZ7lF9TN/rhz5zBDvXezZz2/ptVsrw=; h=X-EA-Auth:Date:From:To:Cc:Subject:Message-ID:MIME-Version: Content-Type; b=ncCiL+NLt2yXHEsyKL0oUKIDLLmfqXfW5qAExkDI3ocZ3H29EB+sMwIwo7gZ6w8WE T/pQy7s4NyKOETIgkDTMOVbGcyW3bB9Qdav4L9dBpxmcWYeQlT9YETdz6+daaa5IFH VJw3+hwE7nOy/zwNpufLYmbsbd5gStqeJghnIhss= Received: by b-6.in.mailobj.net [192.168.90.16] with ESMTP via ip-206.mailobj.net [213.182.55.206] Wed, 25 Jan 2023 17:47:59 +0100 (CET) X-EA-Auth: bWlBuAmXX6htWB4hJvq9dVY4kmQmdlMsBiRKY6XjvCC5Q1E5JmjYqzVM9mv65YUIBkPtwggm7fCtXXjosCMH+7HhHYyQ8R83 Date: Wed, 25 Jan 2023 22:17:54 +0530 From: Deepak R Varma To: Nilesh Javali , GR-QLogic-Storage-Upstream@marvell.com, "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: qla2xxx: Use a variable instead of repeated computations 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?1756014323069638768?= X-GMAIL-MSGID: =?utf-8?q?1756014323069638768?= Use a variable to upfront compute memory size to be allocated, instead of repeatedly computing it at different instructions. The reduced length of lines 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/qla2xxx/tcm_qla2xxx.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.c b/drivers/scsi/qla2xxx/tcm_qla2xxx.c index 8fa0056b56dd..5213d107879d 100644 --- a/drivers/scsi/qla2xxx/tcm_qla2xxx.c +++ b/drivers/scsi/qla2xxx/tcm_qla2xxx.c @@ -1552,6 +1552,7 @@ static const struct qla_tgt_func_tmpl tcm_qla2xxx_template = { static int tcm_qla2xxx_init_lport(struct tcm_qla2xxx_lport *lport) { int rc; + size_t mem_sz; rc = btree_init32(&lport->lport_fcport_map); if (rc) { @@ -1559,17 +1560,15 @@ static int tcm_qla2xxx_init_lport(struct tcm_qla2xxx_lport *lport) return rc; } - lport->lport_loopid_map = - vzalloc(array_size(65536, - sizeof(struct tcm_qla2xxx_fc_loopid))); + mem_sz = array_size(65536, sizeof(struct tcm_qla2xxx_fc_loopid)); + + lport->lport_loopid_map = vzalloc(mem_sz); if (!lport->lport_loopid_map) { - pr_err("Unable to allocate lport->lport_loopid_map of %zu bytes\n", - sizeof(struct tcm_qla2xxx_fc_loopid) * 65536); + pr_err("Unable to allocate lport->lport_loopid_map of %zu bytes\n", mem_sz); btree_destroy32(&lport->lport_fcport_map); return -ENOMEM; } - pr_debug("qla2xxx: Allocated lport_loopid_map of %zu bytes\n", - sizeof(struct tcm_qla2xxx_fc_loopid) * 65536); + pr_debug("qla2xxx: Allocated lport_loopid_map of %zu bytes\n", mem_sz); return 0; }