From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 250A7256C80; Mon, 7 Apr 2025 18:17:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744049827; cv=none; b=lnQ/L5T/g4DDetK3QWCbXEH0DUofjG9m/K5sbI2pzFU9G+BCTCTqp2UAckKwsV7zSPdjiRrBHc1ssVE4uDHicui1AxtevWfn9OVu4jH+XD0Tr+N9OQNTvI8ky4/HyybB4qrXUq+bzzIsqRN2hQqzP+NOSrybfO5XAlfHILUZF7A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744049827; c=relaxed/simple; bh=gE7AwRQ0fIAvGw2TDXblJP8qxB66IupehRc3JRJFs9k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tvE15ZCNlYkD5/jwU2+4YDgAVGd4PPKAiBli4si4YRIG9A473J7xc8ti56bdIia1jcUlrO/cwlJG6fHNPTC/D4R1x1Juzj5N56YVH4A6jQwLqklVcTD0w1sHP3S1WOACAgfUQQISINeTWU5NbPR/WPM1Y75xKcH/z/tpAAS25Ao= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MZbRlQwV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MZbRlQwV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2296DC4CEE7; Mon, 7 Apr 2025 18:17:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744049826; bh=gE7AwRQ0fIAvGw2TDXblJP8qxB66IupehRc3JRJFs9k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MZbRlQwVXTLgYC8a0LO7g8yRLkddajbD4ZveWrAPV7UzMSh+AN2kRHnuAmavRXTRn KrJfb9f/KYZR6as9bbWw5CBYle7JljcdvrwSaTAaDCcnLYrLmNg/vRdL19aQq0KS9d cAuUg6P2p9AGgJzLEOgHdL3pKxkYXhZO+h3mKkWBll5M3Vp/QHycRauOEkYlkL+Aap z19iPM2bo9Dv6wEJE204Ps0tU8nMpwVbVgJd39FGRqXX3s1HFemvTG9+mx512KX3Fe xZH4cNO8rOkReulMBVw8/V9z9CwL6pZervqvJa5a3LjeOdlMxaKyBCQIWIhNf76uXD +783BVWpU7eDA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Arnd Bergmann , kernel test robot , Dave Jiang , Damien Le Moal , Jon Mason , Sasha Levin , allenbh@gmail.com, bhelgaas@google.com, fancer.lancer@gmail.com, zhangjiao2@cmss.chinamobile.com, pstanner@redhat.com, ntb@lists.linux.dev Subject: [PATCH AUTOSEL 6.13 2/8] ntb: reduce stack usage in idt_scan_mws Date: Mon, 7 Apr 2025 14:16:52 -0400 Message-Id: <20250407181658.3184231-2-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250407181658.3184231-1-sashal@kernel.org> References: <20250407181658.3184231-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: ntb@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.13.10 Content-Transfer-Encoding: 8bit From: Arnd Bergmann [ Upstream commit aff12700b8dd7422bfe2277696e192af4df9de8f ] idt_scan_mws() puts a large fixed-size array on the stack and copies it into a smaller dynamically allocated array at the end. On 32-bit targets, the fixed size can easily exceed the warning limit for possible stack overflow: drivers/ntb/hw/idt/ntb_hw_idt.c:1041:27: error: stack frame size (1032) exceeds limit (1024) in 'idt_scan_mws' [-Werror,-Wframe-larger-than] Change it to instead just always use dynamic allocation for the array from the start. It's too big for the stack, but not actually all that much for a permanent allocation. Reported-by: kernel test robot Closes: https://lore.kernel.org/all/202205111109.PiKTruEj-lkp@intel.com/ Signed-off-by: Arnd Bergmann Reviewed-by: Dave Jiang Reviewed-by: Damien Le Moal Signed-off-by: Jon Mason Signed-off-by: Sasha Levin --- drivers/ntb/hw/idt/ntb_hw_idt.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/drivers/ntb/hw/idt/ntb_hw_idt.c b/drivers/ntb/hw/idt/ntb_hw_idt.c index 544d8a4d2af59..f27df8d7f3b97 100644 --- a/drivers/ntb/hw/idt/ntb_hw_idt.c +++ b/drivers/ntb/hw/idt/ntb_hw_idt.c @@ -1041,7 +1041,7 @@ static inline char *idt_get_mw_name(enum idt_mw_type mw_type) static struct idt_mw_cfg *idt_scan_mws(struct idt_ntb_dev *ndev, int port, unsigned char *mw_cnt) { - struct idt_mw_cfg mws[IDT_MAX_NR_MWS], *ret_mws; + struct idt_mw_cfg *mws; const struct idt_ntb_bar *bars; enum idt_mw_type mw_type; unsigned char widx, bidx, en_cnt; @@ -1049,6 +1049,11 @@ static struct idt_mw_cfg *idt_scan_mws(struct idt_ntb_dev *ndev, int port, int aprt_size; u32 data; + mws = devm_kcalloc(&ndev->ntb.pdev->dev, IDT_MAX_NR_MWS, + sizeof(*mws), GFP_KERNEL); + if (!mws) + return ERR_PTR(-ENOMEM); + /* Retrieve the array of the BARs registers */ bars = portdata_tbl[port].bars; @@ -1103,16 +1108,7 @@ static struct idt_mw_cfg *idt_scan_mws(struct idt_ntb_dev *ndev, int port, } } - /* Allocate memory for memory window descriptors */ - ret_mws = devm_kcalloc(&ndev->ntb.pdev->dev, *mw_cnt, sizeof(*ret_mws), - GFP_KERNEL); - if (!ret_mws) - return ERR_PTR(-ENOMEM); - - /* Copy the info of detected memory windows */ - memcpy(ret_mws, mws, (*mw_cnt)*sizeof(*ret_mws)); - - return ret_mws; + return mws; } /* -- 2.39.5