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=1795055818; b=k9bmYnjO0dxPhUI93AQANsQ/7widQE32x4xA79RqiL4rfbF3EkXBMc6QOeLtJsG4XTdT AZ6OWdMNyggqFrZHw48o+r8JQEp/y9JlbewQIa4kC1nRhuvvNc3+5PoPv0nUeov7328Ff hYW2U/xmv3Y+FwJmvxYZWX+9BYlfn+DjUY+FpiwD0aI0AQwdl1gDtVM2XwWTjWDDwqvcJ IIt+Tr6L5lMFyy9KynzOcSgcregEyh8aBEjTzLqzO6M+TStYkQvmKIxA2yWOd0HIesYsZ 1Jg85oYBCY1or4o5hDqjYnhKf204QfNfReL89o1D36AG09BBbSKQ1Rz35MQwRasK1qQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795055818; 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=J9y1j4gj9dYBP4KWVGl8T0Fg2XzQPdglYonv3DswiGg=; b=4ZOpyJKHraoXEpP+DFNuMTCaLdxfqS+mO7Ld2ZscKzIvXyeWI1IqNzh8ncEOfBZ4hglk XruCwvBl5aWUs6uFq7I73kZdnQo7VVRU69wqXBgdQ3K5RSvkYajGDorMyX29lRrkzH5Nc dMSF81nadn79wbLmCv8PQTnevKPrFR3lFooK+2V9SuXE+MNCZS5T5dq5phOPI38nTdonL E9N5mrqr+1JUcRfamgTy/2KF46TLIqHs6FG8QY2pRN7tpkO7zeGsQ3DO4xyzodoJYKyDm RORmuZpBq/hWw7SqiKty0xCSTvi+lieZEX6BOC1YnrkxdW4ap/w7gx2JuJpoaijsGPg== 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=P5g8yleK; 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 2D7AB606A32F; Thu, 19 Nov 2026 02:36:58 +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=P5g8yleK Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FA931F000C4; Thu, 19 Nov 2026 02:36:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795055818; bh=J9y1j4gj9dYBP4KWVGl8T0Fg2XzQPdglYonv3DswiGg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=P5g8yleKu/uurYMehCWcojIJAKc5TbfkDkPfKP2Cl/y5bNYwV+T96r3sKaeZx7P1G wHZ/b1JhxqO9glqZyUUhzVPsKFPHL7xHmVmuBGvSu/mT4m+YKB6tWUEwTipgJ4OfDm Guom8O1WNk3sjIMrhgiygUlAvBQqBTrs08Teb9do= 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 5.15 1765/2214] dmaengine: ste_dma40: turn d40_base phy_chans into a flexible array Date: Wed, 18 Nov 2026 15:57:21 +0100 Message-ID: <20261118150122.137563928@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150009.797899913@linuxfoundation.org> References: <20261118150009.797899913@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 5.15-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 4670d5bf9aef2..f752a33a45367 100644 --- a/drivers/dma/ste_dma40.c +++ b/drivers/dma/ste_dma40.c @@ -576,7 +576,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; @@ -595,6 +594,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) @@ -3156,6 +3156,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; @@ -3215,22 +3216,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; @@ -3243,7 +3246,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