Skip to contentSkip to conversation

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

PATCH In review Daniel Golle 3 participants 3 messages Jan 19, 2023 – Jan 30, 2023

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

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

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
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 · 6 lines
2.39.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Reviewed-by on v1 1/1
#1 lore raw

Hi Daniel,

Quoted 4 lines · Daniel Golle

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.

Good catch!

Quoted 6 lines

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

---

Quoted 19 lines
  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 · 6 lines
Thanks and Regards,
Dhruva Gole

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
maintainer
#2 lore raw
In reply to Daniel Golle

Hi Daniel,

[email protected] wrote on Thu, 19 Jan 2023 03:45:43 +0000:

Quoted 10 lines

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.

---

Looks like my scripts did not properly sent the "applied" e-mail, so here it is, I applied this patch to nand/next.

Quoted 9 lines
 drivers/mtd/nand/spi/macronix.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mtd/nand/spi/macronix.c +0 -0
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

drivers/mtd/nand/spi/macronix.c static int mx35lf1ge4ab_ecc_get_status(struct spinand_device *spinand, · line 92

Quoted 10 lines
drivers/mtd/nand/spi/macronix.c +2 -1
 		 * 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;

Thanks,
Miquèl