Skip to content

Commit e9874dc

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 75686c4 commit e9874dc

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
@@ -968,9 +968,21 @@ static int stm32_fmc2_nfc_seq_write(struct nand_chip *chip, const u8 *buf,
968968

969969
/* Write oob */
970970
if (oob_required) {
971-
ret = nand_change_write_column_op(chip, mtd->writesize,
972-
chip->oob_poi, mtd->oobsize,
973-
false);
971+
unsigned int offset_in_page = mtd->writesize;
972+
const void *buf = chip->oob_poi;
973+
unsigned int len = mtd->oobsize;
974+
975+
if (!raw) {
976+
struct mtd_oob_region oob_free;
977+
978+
mtd_ooblayout_free(mtd, 0, &oob_free);
979+
offset_in_page += oob_free.offset;
980+
buf += oob_free.offset;
981+
len = oob_free.length;
982+
}
983+
984+
ret = nand_change_write_column_op(chip, offset_in_page,
985+
buf, len, false);
974986
if (ret)
975987
return ret;
976988
}

0 commit comments

Comments
 (0)