Skip to contentSkip to conversation

mtd: nand: initialize chip->oob_poi before write

PATCH New Brian Norris 1 participant 1 message Aug 25, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: nand: initialize chip->oob_poi before write

For raw (noecc) page writes (without OOB), we may not have initialized and filled the chip->oob_poi buffer. This can end up writing junk to the flash if we're not careful. Say, for example, we use `nandwrite -n' (without OOB). Then nand_do_write_ops calls chip->write_page, which writes OOB data with some previous, junk data.

This fixes a bug with this commit (from l2-mtd-2.6.git):

commit a8ee364bbf14861d5d0af39c4da06c30441895fb
mtd: nand_base: always initialise oob_poi before writing OOB data

That commit removed the memset from under a conditional for:

if (likely(!oob))

to be inside `nand_fill_oob', which was under:

if (unlikely(oob))

Though the "likely" and "unlikely" can be confusing, these are not the same conditions :)

---
If the buggy commit is going into -stable, this should go -stable as well (or just amend the original).

 drivers/mtd/nand/nand_base.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/mtd/nand/nand_base.c +3 -0
index d2ee68a..273e6a5 100644
@@ -2227,6 +2227,9 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
 			size_t len = min(oobwritelen, oobmaxlen);
 			oob = nand_fill_oob(mtd, oob, len, ops);
 			oobwritelen -= len;
+		} else {
+			/* We still need to erase leftover OOB data */
+			memset(chip->oob_poi, 0xff, mtd->oobsize);
 		}
 
 		ret = chip->write_page(mtd, chip, wbuf, page, cached,
Signature · 1 line
1.7.5.4