Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795049191; b=dUzoQv3C3Yyue8fApFJ/svFb3Q1TBhJ4NHHQTgGgt3qjKXE9diXFKx0l8UQY/O9zthOq K5c/YQpHPGwjJ5j78Aeec6HaBVDKVAtgL469i9jE8KQNzOhb7B7XTKmtyNq4kR9o6rwS4 sdgY7u8fNY40omBmmf/OpUclw+madtclKsA6OBhUwEUn56HftOy7SCdHrPulSteaxRmxR 3QO3hG7XcAjK+WpmQrugIW3hEC+ubakyilrqRXse12yVVTtDoXOPNiR7aPwte0wQBqqzS dNZLiiTdgCuin5k/twxtdnMNjtTRHkZO4MQGTgdbh7l8Nh8oCidhGlyFFYLcBF1/VOw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795049191; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=P5k/A4DHvFf6shWFNmeSuDtTSH+6a3vM5eW+xkzwFDM=; b=DiRraj5At112yTk+hkDHQNV2rqJCzmkMlDzp4yxpQlWyXPtT+CoMx646OmYYP6DjueFj tCoGm8KJPC2nmQY97s/nFRrL8JEyTx3IAFLYCIVQlqG6krLiQJ8e8IEbmyIi8J/sZtTFs JHrFwYXdfavf04Nw6kijPcXsOcMSpw3ybJZlrQ2b6LWKCavBKwmmB9rjO15axMnxDnuPh Ev7mEtGBLUmCdBQGt/yV/SMtckKmVc+ZDxUpxni6Y5mO121A2Pc9TM0lskOYFOefUj1LI OWbi6dWKxM/RLY3oSs/keUT+XvmK+0X04m0EBS2sAVB70D2QJO85VM+TWMuTNII7cmA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=iLZZXQ2h; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C403606A325; Thu, 19 Nov 2026 00:46:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=iLZZXQ2h Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2F621F000C9; Thu, 19 Nov 2026 00:46:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795049191; bh=P5k/A4DHvFf6shWFNmeSuDtTSH+6a3vM5eW+xkzwFDM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=iLZZXQ2hKwKlEFDK9WYiLwaJ5xKQxdKtIo4uTaLwEGtA5L3cKxi5CH6BgO5ucf68V 9+SRxDSJcc4XIBhtxEagOPX328KBUGP5pUnTNkfW0kbM/bSRnyuk8gnZPR0mjH9ndN 7aIdYEeWBI/Po/ntncPUxhLqaGTACSHR7xq7e1Fk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Rosen Penev , Linus Walleij , Vinod Koul , Sasha Levin Subject: [PATCH 6.1 2262/2857] dmaengine: ste_dma40: turn d40_base phy_chans into a flexible array Date: Wed, 18 Nov 2026 15:54:56 +0100 Message-ID: <20261118150322.891485330@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150201.293410965@linuxfoundation.org> References: <20261118150201.293410965@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Rosen Penev [ Upstream commit cc4fea19daeb0460fe3569e0a2d523f427b2bac1 ] Convert the separately-offset phy_chans pointer to a C99 flexible array member at the end of struct d40_base, and switch the allocation to struct_size(). The log_chans and memcpy_chans slots continue to live in the same allocation immediately after phy_chans, indexed via base->log_chans. This removes the hand-rolled pointer fixup that recomputed phy_chans from base + ALIGN(sizeof(struct d40_base), 4). The ALIGN(sizeof(struct d40_base), 4) requirement is met implicitly by the C compiler when using a flexible array member. With struct d40_chan phy_chans[] as the last member, the C standard guarantees sizeof(struct d40_base) includes trailing padding to satisfy the alignment of the flexible array element type (struct d40_chan). Since struct d40_chan contains members like spinlock_t, pointers, and struct dma_chan — all with alignment ≥ 4 — the compiler ensures sizeof(struct d40_base) is already a multiple of _Alignof(struct d40_chan) >= 4. The struct_size() macro then computes sizeof(struct d40_base) + sizeof(struct d40_chan) * num_phy_chans, so phy_chans[0] lands at a properly aligned offset without needing the manual ALIGN. Assisted-by: Claude:Opus-4.7 Signed-off-by: Rosen Penev Reviewed-by: Linus Walleij Link: https://patch.msgid.link/20260531020843.594892-1-rosenp@gmail.com Signed-off-by: Vinod Koul Stable-dep-of: f2baf04a695d ("dmaengine: ste_dma40: Fix memcpy channel parsing") Signed-off-by: Sasha Levin --- drivers/dma/ste_dma40.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/dma/ste_dma40.c b/drivers/dma/ste_dma40.c index 63e93d99f533a..eff7a8dfe3012 100644 --- a/drivers/dma/ste_dma40.c +++ b/drivers/dma/ste_dma40.c @@ -604,7 +604,6 @@ struct d40_base { struct dma_device dma_both; struct dma_device dma_slave; struct dma_device dma_memcpy; - struct d40_chan *phy_chans; struct d40_chan *log_chans; struct d40_chan **lookup_log_chans; struct d40_chan **lookup_phy_chans; @@ -623,6 +622,7 @@ struct d40_base { u32 *regs_interrupt; u16 gcc_pwr_off_mask; struct d40_gen_dmac gen_dmac; + struct d40_chan phy_chans[]; }; static struct device *chan2dev(struct d40_chan *d40c) @@ -3183,6 +3183,7 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev) struct clk *clk; void __iomem *virtbase; struct d40_base *base; + size_t alloc_size; int num_log_chans; int num_phy_chans; int num_memcpy_chans; @@ -3242,22 +3243,24 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev) else num_phy_chans = 4 * (readl(virtbase + D40_DREG_ICFG) & 0x7) + 4; + num_phy_chans = min(num_phy_chans, STEDMA40_MAX_PHYS); + /* The number of channels used for memcpy */ if (plat_data->num_of_memcpy_chans) num_memcpy_chans = plat_data->num_of_memcpy_chans; else num_memcpy_chans = ARRAY_SIZE(dma40_memcpy_channels); + num_memcpy_chans = min(num_memcpy_chans, D40_MEMCPY_MAX_CHANS); num_log_chans = num_phy_chans * D40_MAX_LOG_CHAN_PER_PHY; dev_info(dev, "hardware rev: %d with %d physical and %d logical channels\n", rev, num_phy_chans, num_log_chans); - base = devm_kzalloc(dev, - ALIGN(sizeof(struct d40_base), 4) + - (num_phy_chans + num_log_chans + num_memcpy_chans) * - sizeof(struct d40_chan), GFP_KERNEL); + alloc_size = struct_size(base, phy_chans, num_phy_chans); + alloc_size += sizeof(*base->log_chans) * (num_log_chans + num_memcpy_chans); + base = devm_kzalloc(dev, alloc_size, GFP_KERNEL); if (!base) return NULL; @@ -3270,7 +3273,6 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev) base->virtbase = virtbase; base->plat_data = plat_data; base->dev = dev; - base->phy_chans = ((void *)base) + ALIGN(sizeof(struct d40_base), 4); base->log_chans = &base->phy_chans[num_phy_chans]; if (base->plat_data->num_of_phy_chans == 14) { -- 2.53.0