From patchwork Sun Jan 8 20:38:24 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: 40562 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1843953wrt; Sun, 8 Jan 2023 12:40:00 -0800 (PST) X-Google-Smtp-Source: AMrXdXuI/PAIzvVn2Wqj+veWpKRQCxFpqUyOss/kgGSq7puM/oMzvuxig665jwB7ozr1+r1SottE X-Received: by 2002:aa7:97a1:0:b0:582:a686:34f with SMTP id d1-20020aa797a1000000b00582a686034fmr23702297pfq.30.1673210400364; Sun, 08 Jan 2023 12:40:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673210400; cv=none; d=google.com; s=arc-20160816; b=r5Y9MPUAXUjlkp2cpvOZO4jTiw97bEH/LgYlhtoNXCM3eugQZoV2TExAARExE0i+MP E8+9ivc8ccHZsyzR5v7ITyGJoJ9/lRD7r8zdeJ8MiaGcZd2hlBJUFtWBaBeKPF28hlyD 6mCqEUxMQoyxLhNah71JptuBv82k9Lq3PNKeY9BYNRZRxCDF0mqw7aL9uNpZVtXWOEhr qvokkVmu6pqBUiCCTwDAoiu73SX5yCAzU9aicd1dz9NfcbSZ3U5jAhr547gUTYwc9U0m wGLUiZFLFZFgEfCh5YfdgWlKg/EW8awxlxO4cdfX8Ih5B8mMFpLICdaVIJ3uu99G55+b BmtQ== 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=/2VwZuUx78yUjbZzK8EEUn34588PlQhU5pO35j+28tY=; b=iTtAQlfSVhKSfhZatHxYlcoQwnxm04ciS60ARa1z+a4mZMVyAqSBxlt6nkgfvLB2yN uerviiHsJhmk8gkm030iHJ2PEMmlBGcp7dSm/2lewhD2LyiuYv33l5/NjnJGtMp1meTq C2JujnZF5QJVgZ65WS2VBYKIE74d/2zLdYdZfC156TpSt1aOKUeAViRJxX+ulmJns/js QhuOgMSbLhRTOkgjvnajbO9uD703ImDM2ISBwK0QLm/u/uhEuSBk0e9MSksPd9vMqc4R A/d0Q9f0CBAWkA9NZ6Dtt4Hqnv1th2y7/yS/Xbi5PomPpz78ay8hW0tNlwNflyatNB2F VUxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=WO8xqzGC; 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 p14-20020aa79e8e000000b0057a7f9dbc3fsi7743645pfq.117.2023.01.08.12.39.48; Sun, 08 Jan 2023 12:40:00 -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=WO8xqzGC; 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 S235027AbjAHUin (ORCPT + 99 others); Sun, 8 Jan 2023 15:38:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233278AbjAHUii (ORCPT ); Sun, 8 Jan 2023 15:38:38 -0500 Received: from msg-2.mailo.com (msg-2.mailo.com [213.182.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24C53B7CB; Sun, 8 Jan 2023 12:38:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1673210308; bh=W+GnkAId60B8+kx0qvRInY7BmXQ5CWhNPxJNlVxnWps=; h=X-EA-Auth:Date:From:To:Cc:Subject:Message-ID:MIME-Version: Content-Type; b=WO8xqzGC5rsnJJdsnSP6uUJG+ofmj5qDZXnzRzc/SLs2pt1Ov/ZN4l4DCVvtoWO21 8T5KPzjrQ6P21iP69LyeqB5CAdt/YR/1SmJGKM1bWYO4R8OetQKjq2kEGB9QE/qsBX PdbVrWh3kG28Hb4gTLGjLByPc2osXE6lUEk6gLaM= Received: by b-6.in.mailobj.net [192.168.90.16] with ESMTP via ip-206.mailobj.net [213.182.55.206] Sun, 8 Jan 2023 21:38:28 +0100 (CET) X-EA-Auth: RDzrUikqaR2vh1gQOWWDaBwjRimXsJMMIR4iHIYZyDQbTtUHXyag5PB6pfZf1T3uhwuhbmm6qlgjgxxm5+SLT+gno3cQLH6p Date: Mon, 9 Jan 2023 02:08:24 +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 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?1754488268778841328?= X-GMAIL-MSGID: =?utf-8?q?1754488268778841328?= Use a variable to upfront compute memory size to be allocated, instead of repeatedly computing the memory size 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 Reviewed-by: Himanshu Madhani > --- 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..8024322c9c5a 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 map_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))); + map_sz = array_size(65536, sizeof(struct tcm_qla2xxx_fc_loopid)); + + lport->lport_loopid_map = vzalloc(map_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", map_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", map_sz); return 0; }