Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 18630c36 authored by Christophe Kerello's avatar Christophe Kerello Committed by Greg Kroah-Hartman
Browse files

mtd: rawnand: stm32_fmc2: fix ECC overwrite



commit 811c0da4542df3c065f6cb843ced68780e27bb44 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: default avatarChristophe Kerello <christophe.kerello@foss.st.com>
Cc: stable@vger.kernel.org
Fixes: 2cd457f3 ("mtd: rawnand: stm32_fmc2: add STM32 FMC2 NAND flash controller driver")
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 16e518ca
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -1037,9 +1037,21 @@ static int stm32_fmc2_sequencer_write(struct nand_chip *chip,

	/* 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;
	}