From patchwork Wed Jan 11 18:47:27 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: 42142 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3482659wrt; Wed, 11 Jan 2023 10:51:06 -0800 (PST) X-Google-Smtp-Source: AMrXdXs2tLi3jMZOu1bDyK2MtE2B6LRTxa0ruWxbnqYGCT0CHEpBYTjOVwntL6z8sD7A3bGJU81x X-Received: by 2002:a17:906:6881:b0:84d:4d6c:a462 with SMTP id n1-20020a170906688100b0084d4d6ca462mr8950149ejr.25.1673463066061; Wed, 11 Jan 2023 10:51:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673463066; cv=none; d=google.com; s=arc-20160816; b=qPv+fvs/15WRgqdzxT2ldqf4+VKApPTxBE6IgGxo8UE/XGBA/6KFgA1d+9oVhD5y3j FgZV9ltkg4dvE8XUH0jwTeUDKgMihRyq9KvPMvf7mNYjEmZ9TnmsZqUe8uHp5bOSY9Jk LOrOWJjj8LuDZLElM4RZdCPYhddgqRdd5L919JhoVKaGtlFdF1tQqr3PS5lJ94KR1Dcv GRURLNpHwER6/jDeOHLMunyEUrqd//75hJ4wgbEfWY5qjfUuYpOS7pGz2zVuS7M3jhdd HNUco3CK0UXEPyEo49RKlWf7dYTGj6t3FcBDetdjqkjx3n2e6Qtwyqk0szfcKNMpRpFj ynnA== 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=eDK+4xrqLOFq13xw3Gi+BO1TW0sTt8dEAL3Xx++xUKo=; b=lpmqjcZiaZZ7RYqPuCTLWMreEJ73WO33MphFWePCD7iI3Uf5jI0hqQgfn9Piv+4n7S bDndNkx4d884ZdGUFPpoBgKGx6w0hWAinm4gFQrdDJ2R6pYpbZ3qfV6aayagHjsZEWwW c2CTcX0k4szxRTnVb8HukrBSVbR0bmSCSnz9U4veIoEI1myRyv1XwRNVYYgMOkumXCRH tXmUAAuX8aj7gsRF1gHgYFGggHKB5SrcIl+CmAdIv4n+ep9hl0EjUrGiNo4Gvk8VeQSh LARgpHcjvuJf7qLB1/e1eF6BUl+yALfMk+5T2xSKC4GImPY4ifkotU0uc1WjcEL+IWFK AHLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=bmEem5US; 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 z15-20020a17090655cf00b007e49443849asi12260632ejp.218.2023.01.11.10.50.41; Wed, 11 Jan 2023 10:51:06 -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=bmEem5US; 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 S235851AbjAKSrv (ORCPT + 99 others); Wed, 11 Jan 2023 13:47:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234867AbjAKSrr (ORCPT ); Wed, 11 Jan 2023 13:47:47 -0500 Received: from msg-4.mailo.com (msg-4.mailo.com [213.182.54.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8F8E3C727; Wed, 11 Jan 2023 10:47:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1673462856; bh=jopGRroUzLR4tIlqsfXJiaUefPtk1/CDxZDkEHglVwI=; h=X-EA-Auth:Date:From:To:Cc:Subject:Message-ID:MIME-Version: Content-Type; b=bmEem5USpbJZI5DkvWTiaHiU3SWR8vvmliR2hbKL+uXKkbSl6uhMI/otwTW1cRPdB DxWgJk6+bntH4t4s7UWJuwTtFQAqlNzTK2vj/JCKoSXLzFtONf94n5vrzvQJtD6GuI haXjY8+F0x51uHKovMUcgFQGF6nLfixnEuVOxFrk= Received: by b-2.in.mailobj.net [192.168.90.12] with ESMTP via ip-206.mailobj.net [213.182.55.206] Wed, 11 Jan 2023 19:47:31 +0100 (CET) X-EA-Auth: sME8AV4L7mHKGVO2EY/d0CLsKyWhtWFXdco2VEzHxLa+vDKwbgQivgHsMLs+dDkIdDhqk4I+68aGalNmD9TArn+bLadrCNj7 Date: Thu, 12 Jan 2023 00:17:27 +0530 From: Deepak R Varma To: Kashyap Desai , Sumit Saxena , Shivasharan S , "James E.J. Bottomley" , "Martin K. Petersen" , megaraidlinux.pdl@broadcom.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Saurabh Singh Sengar , Praveen Kumar Subject: [PATCH] scsi: megaraid_sas: 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?1754753207746186116?= X-GMAIL-MSGID: =?utf-8?q?1754753207746186116?= 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/megaraid/megaraid_sas_fusion.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c index fe70f8f11435..efb25af80664 100644 --- a/drivers/scsi/megaraid/megaraid_sas_fusion.c +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c @@ -5287,6 +5287,7 @@ int megasas_alloc_fusion_context(struct megasas_instance *instance) { struct fusion_context *fusion; + size_t sz; instance->ctrl_context = kzalloc(sizeof(struct fusion_context), GFP_KERNEL); @@ -5298,15 +5299,13 @@ megasas_alloc_fusion_context(struct megasas_instance *instance) fusion = instance->ctrl_context; - fusion->log_to_span_pages = get_order(MAX_LOGICAL_DRIVES_EXT * - sizeof(LD_SPAN_INFO)); + sz = array_size(MAX_LOGICAL_DRIVES_EXT, sizeof(LD_SPAN_INFO)); + fusion->log_to_span_pages = get_order(sz); fusion->log_to_span = (PLD_SPAN_INFO)__get_free_pages(GFP_KERNEL | __GFP_ZERO, fusion->log_to_span_pages); if (!fusion->log_to_span) { - fusion->log_to_span = - vzalloc(array_size(MAX_LOGICAL_DRIVES_EXT, - sizeof(LD_SPAN_INFO))); + fusion->log_to_span = vzalloc(sz); if (!fusion->log_to_span) { dev_err(&instance->pdev->dev, "Failed from %s %d\n", __func__, __LINE__); @@ -5314,15 +5313,13 @@ megasas_alloc_fusion_context(struct megasas_instance *instance) } } - fusion->load_balance_info_pages = get_order(MAX_LOGICAL_DRIVES_EXT * - sizeof(struct LD_LOAD_BALANCE_INFO)); + sz = array_size(MAX_LOGICAL_DRIVES_EXT, sizeof(struct LD_LOAD_BALANCE_INFO)); + fusion->load_balance_info_pages = get_order(sz); fusion->load_balance_info = (struct LD_LOAD_BALANCE_INFO *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, fusion->load_balance_info_pages); if (!fusion->load_balance_info) { - fusion->load_balance_info = - vzalloc(array_size(MAX_LOGICAL_DRIVES_EXT, - sizeof(struct LD_LOAD_BALANCE_INFO))); + fusion->load_balance_info = vzalloc(sz); if (!fusion->load_balance_info) dev_err(&instance->pdev->dev, "Failed to allocate load_balance_info, " "continuing without Load Balance support\n");