Skip to contentSkip to conversation

mtd: spinand: macronix: use scratch buffer for DMA operation

PATCH Applied Frieder Schrempf 2 participants 2 messages Mar 10 – Mar 21

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: spinand: macronix: use scratch buffer for DMA operation

From: Daniel Golle <[email protected]>

[ Upstream commit ebed787a0becb9354f0a23620a5130cccd6c730c ]

The mx35lf1ge4ab_get_eccsr() function uses an SPI DMA operation to read the eccsr, hence the buffer should not be on stack. Since commit 380583227c0c7f ("spi: spi-mem: Add extra sanity checks on the op param") the kernel emmits a warning and blocks such operations.

Use the scratch buffer to get eccsr instead of trying to directly read into a stack-allocated variable.

---
This backport fixes the following error in 6.1:

[  102.320032] WARNING: CPU: 0 PID: 537 at drivers/spi/spi-mem.c:216 spi_mem_check_op+0x15c/0x168
[  102.328775] Modules linked in: bluetooth rfkill ipv6 snd_soc_fsl_asrc
[  102.335289] CPU: 0 PID: 537 Comm: nandtest Not tainted 6.1.158-ktn #1
[  102.341745] Hardware name: Freescale i.MX6 Ultralite (Device Tree)
[  102.347943]  unwind_backtrace from show_stack+0x10/0x14
[  102.353203]  show_stack from dump_stack_lvl+0x24/0x2c
[  102.358280]  dump_stack_lvl from __warn+0x74/0x120
[  102.363092]  __warn from warn_slowpath_fmt+0x178/0x188
[  102.368250]  warn_slowpath_fmt from spi_mem_check_op+0x15c/0x168
[  102.374286]  spi_mem_check_op from spi_mem_exec_op+0x3c/0x3e0
[  102.380063]  spi_mem_exec_op from mx35lf1ge4ab_ecc_get_status+0x9c/0xf8
[  102.386712]  mx35lf1ge4ab_ecc_get_status from spinand_ondie_ecc_finish_io_req+0x38/0x9c
[  102.394748]  spinand_ondie_ecc_finish_io_req from spinand_mtd_read+0x184/0x350
[  102.401998]  spinand_mtd_read from mtd_read_oob+0x98/0x160
[  102.407517]  mtd_read_oob from mtd_read+0x5c/0x80
[  102.412247]  mtd_read from mtdchar_read+0x108/0x2bc
[  102.417158]  mtdchar_read from vfs_read+0x98/0x24c
[  102.421977]  vfs_read from sys_pread64+0x8c/0xb8
[  102.426613]  sys_pread64 from ret_fast_syscall+0x0/0x54
[  102.431858] Exception stack(0xe0ce1fa8 to 0xe0ce1ff0)
[  102.436922] 1fa0:                   00200000 00000000 00000003 b6e1f008 00040000 00000000
[  102.445110] 1fc0: 00200000 00000000 00000001 000000b4 b6ff3220 b6e1f008 b6e1f008 b6ddf008
[  102.453294] 1fe0: 000000b4 be925b38 b6f3d611 b6ec1b26
[  102.458414] ---[ end trace 0000000000000000 ]---
---
 drivers/mtd/nand/spi/macronix.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mtd/nand/spi/macronix.c +2 -1
index dce835132a1e2..722a9738ba370 100644
@@ -83,9 +83,10 @@ static int mx35lf1ge4ab_ecc_get_status(struct spinand_device *spinand,
 		 * in order to avoid forcing the wear-leveling layer to move
 		 * data around if it's not necessary.
 		 */
-		if (mx35lf1ge4ab_get_eccsr(spinand, &eccsr))
+		if (mx35lf1ge4ab_get_eccsr(spinand, spinand->scratchbuf))
 			return nanddev_get_ecc_conf(nand)->strength;
 
+		eccsr = *spinand->scratchbuf;
 		if (WARN_ON(eccsr > nanddev_get_ecc_conf(nand)->strength ||
 			    !eccsr))
 			return nanddev_get_ecc_conf(nand)->strength;
Signature · 1 line
2.53.0
maintainer Applied
#1 lore raw

Patch "mtd: spinand: macronix: use scratch buffer for DMA operation" has been added to the 6.1-stable tree

This is a note to let you know that I've just added the patch titled

mtd: spinand: macronix: use scratch buffer for DMA operation

to the 6.1-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
mtd-spinand-macronix-use-scratch-buffer-for-dma-operation.patch
and it can be found in the queue-6.1 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

From [email protected] Tue Mar 10 18:16:43 2026
From: Frieder Schrempf <[email protected]>
Date: Tue, 10 Mar 2026 18:15:44 +0100
Subject: mtd: spinand: macronix: use scratch buffer for DMA operation
To: Greg Kroah-Hartman <[email protected]>, Sasha Levin <[email protected]>, [email protected], [email protected], [email protected], Miquel Raynal <[email protected]>, Richard Weinberger <[email protected]>, Vignesh Raghavendra <[email protected]>
Cc: Daniel Golle <[email protected]>, Dhruva Gole <[email protected]>, Frieder Schrempf <[email protected]>
Message-ID: <[email protected]>

From: Daniel Golle <[email protected]>

[ Upstream commit ebed787a0becb9354f0a23620a5130cccd6c730c ]

The mx35lf1ge4ab_get_eccsr() function uses an SPI DMA operation to read the eccsr, hence the buffer should not be on stack. Since commit 380583227c0c7f ("spi: spi-mem: Add extra sanity checks on the op param") the kernel emmits a warning and blocks such operations.

Use the scratch buffer to get eccsr instead of trying to directly read into a stack-allocated variable.

---
 drivers/mtd/nand/spi/macronix.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mtd/nand/spi/macronix.c +2 -1
@@ -83,9 +83,10 @@ static int mx35lf1ge4ab_ecc_get_status(s
 		 * in order to avoid forcing the wear-leveling layer to move
 		 * data around if it's not necessary.
 		 */
-		if (mx35lf1ge4ab_get_eccsr(spinand, &eccsr))
+		if (mx35lf1ge4ab_get_eccsr(spinand, spinand->scratchbuf))
 			return nanddev_get_ecc_conf(nand)->strength;
 
+		eccsr = *spinand->scratchbuf;
 		if (WARN_ON(eccsr > nanddev_get_ecc_conf(nand)->strength ||
 			    !eccsr))
 			return nanddev_get_ecc_conf(nand)->strength;

Patches currently in stable-queue which might be from [email protected] are

queue-6.1/regulator-pca9450-make-irq-optional.patch queue-6.1/mtd-spinand-macronix-use-scratch-buffer-for-dma-operation.patch

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/