From patchwork Wed Mar 1 20:11:14 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: 63066 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3846383wrd; Wed, 1 Mar 2023 12:16:23 -0800 (PST) X-Google-Smtp-Source: AK7set+rfDjUYoecqHCJ4/GQxsIdvMiyJZiGt9enL6MajhBOWvqMN2DZZFHXii33sAfhSylAJaRr X-Received: by 2002:aa7:cd91:0:b0:4af:6aa6:12d3 with SMTP id x17-20020aa7cd91000000b004af6aa612d3mr7183622edv.40.1677701783365; Wed, 01 Mar 2023 12:16:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677701783; cv=none; d=google.com; s=arc-20160816; b=saoyuuomRpcIjSrcf95jvnXoKhwRbspoeXvXJ4KzX2AzxikDglD9BopKjPFCqo5T40 SGTdzkmyeSKwyVtX/oFF16P2jo1bmrdBDqHFkyTjG99c5Fsib1pgWjQPjhxI/oo2Rwpk aH8/kSIXIge9jgvup/HDr2Zrsxn6U71rkTV5RBpKI2TtPwZ8Eqe26AO++RUZJ0V/qOwS eM7GEPLZYo69gLAzkddTHpVeqJbl2C+cKTh2FyhFMMGY+QB1c7Ju11HqO2pOGlnWAvaC Mt74z/fbXYJFO3VMaUdD1Of2fzZnBTNUlzmmNfTfErKedPXmfx/mKoiV0QFTaS1dNm/H 3d2w== 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=2VyFUMVvh/NF1XZCsYfxAXYyeeWALo04ct01f+m1B1A=; b=TPx/348PQ0GtWrwVcamNhsB3UBFG9c1xbL49ddVt2O+cMD9392oFbHlpZ5uj6rN282 PDF1cXNk/a9I8US2a1RHGPPRa+C37IKj5qXOi9xjYVUeR7QtJsB1HrajKWwGQKLFqzPw V1IwNZptklwQjPkevf3eXy3wDbkoeAHtygIe4nqil31bqWzIahqCN4j9s+W8LpIIJtTZ uTYnD3QPgQCY/alSDLPkVH24w3YzAbhPM9K/BoXwBGlhvBwDnjluGey+lieWoTPTNUJP OjJBVl/qe4Z0OUOAghJK8bQcon/J6GkF9i5RqoplcfG0RoBHMENOdt4AKsfO1mWvSz6q R0Sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=DkEBJek0; 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 dn21-20020a17090794d500b008e418335b5dsi19458180ejc.793.2023.03.01.12.15.59; Wed, 01 Mar 2023 12:16:23 -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=DkEBJek0; 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 S229796AbjCAULl (ORCPT + 99 others); Wed, 1 Mar 2023 15:11:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229766AbjCAULk (ORCPT ); Wed, 1 Mar 2023 15:11:40 -0500 Received: from msg-2.mailo.com (msg-2.mailo.com [213.182.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F7B64ECC3; Wed, 1 Mar 2023 12:11:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1677701480; bh=sd7TUoLeCUd92ZXggFD4kGKXSAM8Ac3AHPaGaF1Smwo=; h=X-EA-Auth:Date:From:To:Cc:Subject:Message-ID:MIME-Version: Content-Type; b=DkEBJek0lPEuKOP2Gq9vdUbAQ0oyKyItDphgH9R9bdCNs+z7FxlOMSzNMev44/hqU VWxO6hlJjjWy5yrF+2s4BfkZyA2IFBKCbxqrIgLBRCBP1lqS1v05gs3ArUKL6XLjYw lh/p6oCuLInQcto8mNswaSD9i6ts94NDVuEOGbls= Received: by b221-1.in.mailobj.net [192.168.90.21] with ESMTP via ip-20.mailobj.net [213.182.54.20] Wed, 1 Mar 2023 21:11:20 +0100 (CET) X-EA-Auth: u6rUujtstJ90tXkD2OLmeUq9fTvMJ8+h2tHz5MJlmbx9rMm91pGggkvzVOGmHJSkEVTlcn5nOjiGVOMhLeHGFOQlreIt0KAs Date: Thu, 2 Mar 2023 01:41:14 +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 , Deepak R Varma Subject: [PATCH RESEND] 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?1759197825140043141?= X-GMAIL-MSGID: =?utf-8?q?1759197825140043141?= 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 is compile tested only. Resending the patch for review and feedback. Initially submitted on Jan 12 2023. 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 6597e118c805..39c0595682c1 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");