From patchwork Thu Aug 25 00:05:46 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 111437 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E5BBBB6F64 for ; Thu, 25 Aug 2011 10:06:35 +1000 (EST) Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QwNSQ-0002xv-8q; Thu, 25 Aug 2011 00:06:06 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QwNSP-0001uH-RF; Thu, 25 Aug 2011 00:06:05 +0000 Received: from mail-pz0-f41.google.com ([209.85.210.41]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QwNSL-0001ty-Mm for linux-mtd@lists.infradead.org; Thu, 25 Aug 2011 00:06:02 +0000 Received: by pzk4 with SMTP id 4so2297004pzk.28 for ; Wed, 24 Aug 2011 17:05:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; bh=vWBZRtfef1nsx3Q6wWoNW2XylxSmw5ZYynaSM0PINSg=; b=To5ee3Jw40IKQgMgB8v9WBaM6mJMb2McVItRwTS/zSGNSm+28c2NPDlpoy38I99Owy eZhDvMgp0Sl2t5B7Uhi/u8pQclaSeyircLNm2H9UzXMJiV9H679KEC5lRsKj5oVMKcct sVvFQseqMrFYA6LqfXh3F6hVaBhZoyF6dKl0U= Received: by 10.142.224.7 with SMTP id w7mr3028282wfg.215.1314230757628; Wed, 24 Aug 2011 17:05:57 -0700 (PDT) Received: from localhost.localdomain (cpe-76-174-190-12.socal.res.rr.com. [76.174.190.12]) by mx.google.com with ESMTPS id u2sm415029pbq.9.2011.08.24.17.05.55 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 24 Aug 2011 17:05:56 -0700 (PDT) From: Brian Norris To: Artem Bityutskiy Subject: [PATCH] mtd: nand: initialize chip->oob_poi before write Date: Wed, 24 Aug 2011 17:05:46 -0700 Message-Id: <1314230746-3833-1-git-send-email-computersforpeace@gmail.com> X-Mailer: git-send-email 1.7.5.4 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110824_200602_087763_71C22016 X-CRM114-Status: GOOD ( 14.65 ) X-Spam-Score: -0.8 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-0.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.210.41 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (computersforpeace[at]gmail.com) -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Brian Norris , linux-mtd@lists.infradead.org, Adam Thomson X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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 :) Signed-off-by: Brian Norris Cc: Adam Thomson --- 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(-) diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index d2ee68a..273e6a5 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -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,