* [PATCH] dmaengine: loongson: loongson2-apb: fix broken bus width validation in ls2x_dmac_detect_burst()
@ 2026-03-18 16:48 David Carlier
2026-03-23 2:38 ` Binbin Zhou
0 siblings, 1 reply; 2+ messages in thread
From: David Carlier @ 2026-03-18 16:48 UTC (permalink / raw)
To: Binbin Zhou, Vinod Koul, Frank Li, Yingkun Meng; +Cc: dmaengine, David Carlier
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))
return 0;
if (lchan->sconfig.direction == DMA_MEM_TO_DEV) {
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] dmaengine: loongson: loongson2-apb: fix broken bus width validation in ls2x_dmac_detect_burst()
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
0 siblings, 0 replies; 2+ messages in thread
From: Binbin Zhou @ 2026-03-23 2:38 UTC (permalink / raw)
To: David Carlier, Vinod Koul, Frank Li; +Cc: dmaengine
Hi David:
On 2026/3/19 00:48, 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>
That was indeed my oversight. Thanks a lot!
Reviewed-by: Binbin Zhou <zhoubinbin@loongson.cn>
> ---
> 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))
> return 0;
>
> if (lchan->sconfig.direction == DMA_MEM_TO_DEV) {
Thanks.
Binbin
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-23 2:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox