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 0853B27CCD4; Mon, 7 Apr 2025 18:18:18 +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=1744049899; cv=none; b=EwCP4fqx4dWuY9/KakLT49aWdApPWZgcxa94beugmEYNN0F5dChhvqhe1AXqGVA9afInPpuAG7/+rcrsJxomAa+nR6puYqkj4KNundZAQ9C/pbcfsDnjG0W5lkPSo66LCUCuJQqZP6rVL/bBgnAxIoysl9wCGDfh3QJ1pEp29Pw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744049899; c=relaxed/simple; bh=FlV4Jkh0MjOxubU4XDHeoQi4Zqm7mUHsS/yjuDre5JU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gaA+mK/aAjn2OKkRKI3vCBx1gvRkI6q1fbzMhmoyLft5ZWLd3vIqnCPjimy7B39YuONOfPLQxruF0Djneqx5C69d8qgbI91UNwE6SzImxDfzctDxUYKaoW6XGes7r7mvzv47zlHrBABVElt3DoOa8hvdskSjQqHDa8lOp/ioOnU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hFVQKWsw; 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="hFVQKWsw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4CB21C4CEDD; Mon, 7 Apr 2025 18:18:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744049898; bh=FlV4Jkh0MjOxubU4XDHeoQi4Zqm7mUHsS/yjuDre5JU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hFVQKWswPfjdQ95gGXEUeheZ8c4bmiYmVrBS2/NnT4K2J0D6Z4GjFXve8FF1I7l5M Vqnl3fZt4Q77QPKdWVVFjjac9WV3Zvrm7r107d1Omm2l4wgD0GuUG/cu4+eZsVBbI3 SbenL8D2U5BFaYcZx1iaoMVfyIxWHwrrgEcViyhgETtY3X00Z8asYqY/EZe5QxQ7fl Tj453BUlfYsu/wC3mimdzNQLUOowSPFGLO/3ljF0u8P8iDVKkKsV3KZjYdWMexrVBq bvA73JT6uX1jZ0+tjOYxinmf9Ia5DIW+T69HuYHrRJ5glBLO5m2EHLj0UKTYR4SdXj awo7568Le1eag== 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 5.10 2/2] ntb: reduce stack usage in idt_scan_mws Date: Mon, 7 Apr 2025 14:18:10 -0400 Message-Id: <20250407181810.3184654-2-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250407181810.3184654-1-sashal@kernel.org> References: <20250407181810.3184654-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 5.10.235 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 99711dd0b6e8e..d39fc55f8b0cc 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