Skip to content

Commit b6f8cd7

Browse files
Christophe Kerellogregkh
authored andcommitted
mtd: rawnand: stm32_fmc2: fix ECC overwrite
commit 811c0da upstream. 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: 2cd457f ("mtd: rawnand: stm32_fmc2: add STM32 FMC2 NAND flash controller driver") Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 26adba1 commit b6f8cd7

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

drivers/mtd/nand/raw/stm32_fmc2_nand.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -985,9 +985,21 @@ static int stm32_fmc2_nfc_seq_write(struct nand_chip *chip, const u8 *buf,
985985

986986
/* Write oob */
987987
if (oob_required) {
988-
ret = nand_change_write_column_op(chip, mtd->writesize,
989-
chip->oob_poi, mtd->oobsize,
990-
false);
988+
unsigned int offset_in_page = mtd->writesize;
989+
const void *buf = chip->oob_poi;
990+
unsigned int len = mtd->oobsize;
991+
992+
if (!raw) {
993+
struct mtd_oob_region oob_free;
994+
995+
mtd_ooblayout_free(mtd, 0, &oob_free);
996+
offset_in_page += oob_free.offset;
997+
buf += oob_free.offset;
998+
len = oob_free.length;
999+
}
1000+
1001+
ret = nand_change_write_column_op(chip, offset_in_page,
1002+
buf, len, false);
9911003
if (ret)
9921004
return ret;
9931005
}

0 commit comments

Comments
 (0)