Skip to content

Commit 98480a1

Browse files
Arseniy Krasnovmiquelraynal
authored andcommitted
mtd: rawnand: meson: fix unaligned DMA buffers handling
Meson NAND controller requires 8 bytes alignment for DMA addresses, otherwise it "aligns" passed address by itself thus accessing invalid location in the provided buffer. This patch makes unaligned buffers to be reallocated to become valid. Fixes: 8fae856 ("mtd: rawnand: meson: add support for Amlogic NAND flash controller") Cc: <Stable@vger.kernel.org> Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/linux-mtd/20230615080815.3291006-1-AVKrasnov@sberdevices.ru
1 parent a6a8a1e commit 98480a1

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

drivers/mtd/nand/raw/meson_nand.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
#define GENCMDIADDRH(aih, addr) ((aih) | (((addr) >> 16) & 0xffff))
7878

7979
#define DMA_DIR(dir) ((dir) ? NFC_CMD_N2M : NFC_CMD_M2N)
80+
#define DMA_ADDR_ALIGN 8
8081

8182
#define ECC_CHECK_RETURN_FF (-1)
8283

@@ -905,6 +906,9 @@ static int meson_nfc_read_oob(struct nand_chip *nand, int page)
905906

906907
static bool meson_nfc_is_buffer_dma_safe(const void *buffer)
907908
{
909+
if ((uintptr_t)buffer % DMA_ADDR_ALIGN)
910+
return false;
911+
908912
if (virt_addr_valid(buffer) && (!object_is_on_stack(buffer)))
909913
return true;
910914
return false;

0 commit comments

Comments
 (0)