]> www.infradead.org Git - users/hch/misc.git/commitdiff
mtd: rawnand: stm32_fmc2: fix ECC overwrite
authorChristophe Kerello <christophe.kerello@foss.st.com>
Tue, 12 Aug 2025 07:30:08 +0000 (09:30 +0200)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Thu, 28 Aug 2025 12:26:51 +0000 (14:26 +0200)
In case OOB write is requested during a data write, ECC is currently
lost. Avoid this issue by only writing in the free spare area.
This issue has been seen with a YAFFS2 file system.

Signed-off-by: Christophe Kerello <christophe.kerello@foss.st.com>
Cc: stable@vger.kernel.org
Fixes: 2cd457f328c1 ("mtd: rawnand: stm32_fmc2: add STM32 FMC2 NAND flash controller driver")
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
drivers/mtd/nand/raw/stm32_fmc2_nand.c

index 222c3c3b684841879a55835e802dcf9983860c28..d957327fb4fa047db3df0c32365e2c27d5b4e663 100644 (file)
@@ -985,9 +985,21 @@ static int stm32_fmc2_nfc_seq_write(struct nand_chip *chip, const u8 *buf,
 
        /* Write oob */
        if (oob_required) {
-               ret = nand_change_write_column_op(chip, mtd->writesize,
-                                                 chip->oob_poi, mtd->oobsize,
-                                                 false);
+               unsigned int offset_in_page = mtd->writesize;
+               const void *buf = chip->oob_poi;
+               unsigned int len = mtd->oobsize;
+
+               if (!raw) {
+                       struct mtd_oob_region oob_free;
+
+                       mtd_ooblayout_free(mtd, 0, &oob_free);
+                       offset_in_page += oob_free.offset;
+                       buf += oob_free.offset;
+                       len = oob_free.length;
+               }
+
+               ret = nand_change_write_column_op(chip, offset_in_page,
+                                                 buf, len, false);
                if (ret)
                        return ret;
        }