Re: [PATCH v2 3/3] mtd: rawnand: r852: bounce non-linear-map buffers

From: Miquel Raynal

Date: Wed Nov 25 2026 - 03:55:22 EST


On 23/11/2026 at 15:04:40 +08, Ping Li <leeonion.muyu@xxxxxxxxx> wrote:

> r852_do_dma() only bounces buffers that are not R852_DMA_LEN
> aligned. An aligned vmalloc'd buffer passes this check and gets
> fed to dma_map_single(), which is only valid for linear-map
> addresses. Such buffers are not hypothetical: mtdblock's write
> cache is vmalloc'ed, and UBIFS passes vmalloc'ed LPT buffers.
>
> Extend the bounce condition with a virt_addr_valid() check so
> that non-linear-map buffers go through the existing internal
> bounce buffer instead.
>
> Fixes: 67e054e919248 ("mtd: nand: Add driver for Ricoh xD/SmartMedia reader")
> Signed-off-by: Ping Li <leeonion.muyu@xxxxxxxxx>
> ---
> drivers/mtd/nand/raw/r852.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mtd/nand/raw/r852.c b/drivers/mtd/nand/raw/r852.c
> index 92c47d351c27..4dbfc053fb21 100644
> --- a/drivers/mtd/nand/raw/r852.c
> +++ b/drivers/mtd/nand/raw/r852.c
> @@ -188,8 +188,8 @@ static void r852_do_dma(struct r852_device *dev, uint8_t *buf, int do_read)
> from device, for writes first fill the buffer from memory*/
> dev->dma_state = do_read ? DMA_INTERNAL : DMA_MEMORY;
>
> - /* if incoming buffer is not page aligned, we should do bounce */
> - if ((unsigned long)buf & (R852_DMA_LEN-1))
> + /* if incoming buffer is not usable for DMA, we should do bounce */
> + if (!virt_addr_valid(buf) || (unsigned long)buf & (R852_DMA_LEN
> - 1))

Why do we need a local bounce if the core can do it with NAND_USES_DMA?

Also please add Cc: stable to these three patches.

Thanks,
Miquèl