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: 13097096 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61D81C46467 for ; Wed, 11 Jan 2023 18:47:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235818AbjAKSrs (ORCPT ); Wed, 11 Jan 2023 13:47:48 -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 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org 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");