Skip to contentSkip to conversation

mtd: spinand: micron: fix division by zero

PATCH In review Micha Ober 2 participants 2 messages Dec 28, 2024 – Dec 30, 2024

Subsystems (2)
lore
Share & tools
lore

Micha Ober

author
#0 lore raw

PATCH 1/1 mtd: spinand: micron: fix division by zero

The ecc_step_size field ist not set at this point in the call tree, leading to a division by zero.

Read the step size from the mtd device ecc config instead.

---
 drivers/mtd/nand/spi/micron.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mtd/nand/spi/micron.c +2 -1
index 12601bc4227a..7973996519d3 100644
@@ -106,9 +106,10 @@ static int micron_4_ooblayout_free(struct mtd_info *mtd, int section,
 				   struct mtd_oob_region *region)
 {
 	struct spinand_device *spinand = mtd_to_spinand(mtd);
+	struct nand_device *nand = mtd_to_nanddev(mtd);
 
 	if (section >= spinand->base.memorg.pagesize /
-			mtd->ecc_step_size)
+			nanddev_get_ecc_conf(nand)->step_size)
 		return -ERANGE;
 
 	if (section) {
Signature · 6 lines
2.39.5 (Apple Git-154)


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

Hi Micha,

Thanks for the patch, looks important.

Please fix Richard's address in next submission.

Quoted 1 line · Micha Ober

The ecc_step_size field ist not set at this point

typo ^

Quoted 1 line

in the call tree, leading to a division by zero.

Definitely needs Fixes: + Cc: stable!

Quoted 1 line

Read the step size from the mtd device ecc config instead.

s/mtd device//
s/ecc config/ECC configuration/

drivers/mtd/nand/spi/micron.c static int micron_4_ooblayout_free(struct mtd_info *mtd, int section, · line 106

Quoted 12 lines
---
 drivers/mtd/nand/spi/micron.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mtd/nand/spi/micron.c +0 -0
index 12601bc4227a..7973996519d3 100644
@@ -106,9 +106,10 @@ static int micron_4_ooblayout_free(struct mtd_info *mtd, int section,
 				   struct mtd_oob_region *region)

What about the exact same situation in the .ecc() hook?

drivers/mtd/nand/spi/micron.c static int micron_4_ooblayout_free(struct mtd_info *mtd, int section, · line 115

Quoted 10 lines
drivers/mtd/nand/spi/micron.c +2 -1
 {
 	struct spinand_device *spinand = mtd_to_spinand(mtd);
+	struct nand_device *nand = mtd_to_nanddev(mtd);
 
 	if (section >= spinand->base.memorg.pagesize /
-			mtd->ecc_step_size)
+			nanddev_get_ecc_conf(nand)->step_size)
 		return -ERANGE;
 
 	if (section) {

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