Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4525704rdh; Wed, 29 Nov 2023 04:06:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IG+oHb0K69aBIXZFhA+7h5AnytbSuQQecoR2efNfumRe3As1K13E8t5TRWnxMxrMvY7nQae X-Received: by 2002:a17:902:e752:b0:1cf:b786:f110 with SMTP id p18-20020a170902e75200b001cfb786f110mr17624901plf.32.1701259605282; Wed, 29 Nov 2023 04:06:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701259605; cv=none; d=google.com; s=arc-20160816; b=KYAgPtFJGBACvG9eTLpWw/nXBb/QNI1pu8c9UJO3J+Ab2vk7ER7j0ReAojJylr86Ei JIsVnYdULnT1Trjhlc4uei9LQNUu+sio4jJQQnMFejIIhq0v+SEZtp+wdFBKSND35hCe Rig3VwQjwA1+NpVc30OoznN7JvJiH+UQb0xjJsHUgNSI/VR0Cqq55lOJTxWeDSxjSE+F QXWIHhrgMEBOeQ1XpPWfIaeviG6q+pdJUxZz/Fnc2NIJq4um8Gy4Cjzd/LE5H8zkhpsU SqUJSh4zxIn90P8/d6i0qx2dLqeGwDlFkLViMtS7PVKvx20zX/vtnfExTtvfmLosSwVO 9LrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=nyktXDsdUX7zsA/+JTUzVrKKNic5AMafQUxo6ZXmpeM=; fh=mfLLm9CWc3cpxydFV/pJB7e//EKzx3x9UrjrvSTQU8g=; b=vz5dgA9pz6wuk2GUEv3jmM2hIGzT1cYp/4+ZiWwxwZLBem1ecR6kN4+bdf0pkozCHz 2LAT/+w3rUAChj+MnpWk8q21UsPt2vZeQL6DAMoPyXXVdo8UbzI9/gROSorKSCRydTqP XSGT4Fp6KWrm1H87r4yfOsoG63cshztTlz7Ntx6pK6NdVmNxkG8Om6+KrRKTd+4CWQey yt/S4aVbfnseDeKKWkDMALyZbm8pjFpEM/0arqoeWr40iQKV9GI/6Jex4U0ltmp0QTzj hTR+D/1VRA5sf+r2O5UZAOO1++CPsmLyoCl9q+PrbPop36QRclhbIvooslPO7LSyBJs4 eH7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=G2fEAlaX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id d6-20020a170902cec600b001d0050e2452si2725756plg.45.2023.11.29.04.06.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 04:06:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=G2fEAlaX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 82FBD807AFCE; Wed, 29 Nov 2023 04:06:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232531AbjK2MG2 (ORCPT + 99 others); Wed, 29 Nov 2023 07:06:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230283AbjK2MG0 (ORCPT ); Wed, 29 Nov 2023 07:06:26 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01E92D48 for ; Wed, 29 Nov 2023 04:06:32 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBC20C433C7; Wed, 29 Nov 2023 12:06:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701259592; bh=nq4//SqYMEHrYH9WAGI7RRiUbWslfN4uSXxCXgslX3I=; h=From:To:Cc:Subject:Date:From; b=G2fEAlaXY9tFxabavDUIrq3gW35B2D4E12tQ8ohrVLz5r1hW/SMZIAUGcmW8TD1RI /2v5JjXFS/tq65TaNXp2VQEJ8rYsrj6ZJzprlHSXMKLfNLfJWEAcTDDzH5iTG4bO0T 3YW0+jUc4Ti0oz5/HOdBhwoxmbWOVKX32muHb1kzfi3bBjB8gy9+NCUx+fRLuMFRbl VPoY1k0t705F8RggchuakSm+td9XflYIk/SRrKpWk0Ko9eHb0MRdU2cI5ZppGPTH8t ugSZh5DXirVOD8ZZmxla1YqIuvNku48z3+6mqVzsKFKo1xkTTAn6qD+0uFe62W+t6/ CmB6CHLTLsKPw== From: Arnd Bergmann To: Sathya Prakash Veerichetty , Kashyap Desai , Sumit Saxena , Sreekanth Reddy Cc: Arnd Bergmann , "James E.J. Bottomley" , "Martin K. Petersen" , Ranjan Kumar , Tomas Henzl , Harshit Mogalapalli , mpi3mr-linuxdrv.pdl@broadcom.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] scsi: mpi3mr: reduce stack usage in mpi3mr_refresh_sas_ports() Date: Wed, 29 Nov 2023 13:06:12 +0100 Message-Id: <20231129120626.4118089-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 29 Nov 2023 04:06:42 -0800 (PST) From: Arnd Bergmann Toubling the number of PHYs also doubled the stack usage of this function, exceeding the 32-bit limit of 1024 bytes: drivers/scsi/mpi3mr/mpi3mr_transport.c: In function 'mpi3mr_refresh_sas_ports': drivers/scsi/mpi3mr/mpi3mr_transport.c:1818:1: error: the frame size of 1636 bytes is larger than 1024 bytes [-Werror=frame-larger-than=] Since the sas_io_unit_pg0 structure is already allocated dynamically, use the same method here. The size of the allocation can be smaller based on the actual number of phys now, so use this as an upper bound. Fixes: cb5b60894602 ("scsi: mpi3mr: Increase maximum number of PHYs to 64 from 32") Signed-off-by: Arnd Bergmann --- drivers/scsi/mpi3mr/mpi3mr_transport.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/mpi3mr/mpi3mr_transport.c b/drivers/scsi/mpi3mr/mpi3mr_transport.c index c0c8ab586957..ab04596dbdf5 100644 --- a/drivers/scsi/mpi3mr/mpi3mr_transport.c +++ b/drivers/scsi/mpi3mr/mpi3mr_transport.c @@ -1671,7 +1671,7 @@ mpi3mr_update_mr_sas_port(struct mpi3mr_ioc *mrioc, struct host_port *h_port, void mpi3mr_refresh_sas_ports(struct mpi3mr_ioc *mrioc) { - struct host_port h_port[64]; + struct host_port *h_port = NULL; int i, j, found, host_port_count = 0, port_idx; u16 sz, attached_handle, ioc_status; struct mpi3_sas_io_unit_page0 *sas_io_unit_pg0 = NULL; @@ -1685,6 +1685,11 @@ mpi3mr_refresh_sas_ports(struct mpi3mr_ioc *mrioc) sas_io_unit_pg0 = kzalloc(sz, GFP_KERNEL); if (!sas_io_unit_pg0) return; + h_port = kcalloc(mrioc->sas_hba.num_phys, sizeof(struct host_port), + GFP_KERNEL); + if (!h_port) + goto out; + if (mpi3mr_cfg_get_sas_io_unit_pg0(mrioc, sas_io_unit_pg0, sz)) { ioc_err(mrioc, "failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); @@ -1814,6 +1819,7 @@ mpi3mr_refresh_sas_ports(struct mpi3mr_ioc *mrioc) } } out: + kfree(h_port); kfree(sas_io_unit_pg0); } -- 2.39.2