From: Frank Li <Frank.li@nxp.com>
To: David Carlier <devnexen@gmail.com>
Cc: Binbin Zhou <zhoubinbin@loongson.cn>,
Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>,
Yingkun Meng <mengyingkun@loongson.cn>,
dmaengine@vger.kernel.org
Subject: Re: [PATCH] dmaengine: loongson: loongson2-apb: fix broken bus width validation in ls2x_dmac_detect_burst()
Date: Mon, 30 Mar 2026 12:28:28 -0400 [thread overview]
Message-ID: <acqkrL7CYbr0WmHf@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <20260318164803.14351-1-devnexen@gmail.com>
On Wed, Mar 18, 2026 at 04:48:03PM +0000, David Carlier wrote:
> The bus width validation check in ls2x_dmac_detect_burst() compares raw
> enum dma_slave_buswidth values (e.g. 4, 8) directly against
> LDMA_SLAVE_BUSWIDTHS, which is a BIT()-encoded bitmask
> (BIT(4) | BIT(8) = 0x110). Since 4 & 0x110 == 0 and 8 & 0x110 == 0,
> the condition is always false for valid bus widths, making the
> validation dead code.
>
> Additionally, the logic was inverted: it rejected configurations where
> both widths matched valid values, rather than rejecting when neither
> width is supported.
>
> Fix by wrapping the enum values with BIT() before masking (matching the
> pattern used in sun6i-dma.c) and inverting the logic to reject when
> neither width is supported by the hardware.
>
> Fixes: 71e7d3cb6e55 ("dmaengine: ls2x-apb: New driver for the Loongson LS2X APB DMA controller")
> Signed-off-by: David Carlier <devnexen@gmail.com>
> ---
> drivers/dma/loongson/loongson2-apb-dma.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/dma/loongson/loongson2-apb-dma.c b/drivers/dma/loongson/loongson2-apb-dma.c
> index aceb069e71fc..102c01f993ef 100644
> --- a/drivers/dma/loongson/loongson2-apb-dma.c
> +++ b/drivers/dma/loongson/loongson2-apb-dma.c
> @@ -220,8 +220,8 @@ static size_t ls2x_dmac_detect_burst(struct ls2x_dma_chan *lchan)
> u32 maxburst, buswidth;
>
> /* Reject definitely invalid configurations */
> - if ((lchan->sconfig.src_addr_width & LDMA_SLAVE_BUSWIDTHS) &&
> - (lchan->sconfig.dst_addr_width & LDMA_SLAVE_BUSWIDTHS))
> + if (!(BIT(lchan->sconfig.src_addr_width) & LDMA_SLAVE_BUSWIDTHS) &&
> + !(BIT(lchan->sconfig.dst_addr_width) & LDMA_SLAVE_BUSWIDTHS))
src_addr_width is enum dma_slave_buswidth, which allow
DMA_SLAVE_BUSWIDTH_128_BYTES = 128,
BIT(128) will overflow.
Frank
> return 0;
>
> if (lchan->sconfig.direction == DMA_MEM_TO_DEV) {
> --
> 2.53.0
>
next prev parent reply other threads:[~2026-03-30 16:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-18 16:48 [PATCH] dmaengine: loongson: loongson2-apb: fix broken bus width validation in ls2x_dmac_detect_burst() David Carlier
2026-03-23 2:38 ` Binbin Zhou
2026-03-30 16:28 ` Frank Li [this message]
2026-03-30 16:57 ` David CARLIER
2026-03-31 14:23 ` Frank Li
2026-03-31 15:01 ` [PATCH v2] " David Carlier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=acqkrL7CYbr0WmHf@lizhi-Precision-Tower-5810 \
--to=frank.li@nxp.com \
--cc=Frank.Li@kernel.org \
--cc=devnexen@gmail.com \
--cc=dmaengine@vger.kernel.org \
--cc=mengyingkun@loongson.cn \
--cc=vkoul@kernel.org \
--cc=zhoubinbin@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox