public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Brian Norris <computersforpeace@gmail.com>
To: <linux-mtd@lists.infradead.org>
Cc: Angus CLARK <angus.clark@st.com>,
	Dan Carpenter <error27@gmail.com>,
	Kulikov Vasiliy <segooon@gmail.com>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Nicolas Ferre <nicolas.ferre@atmel.com>,
	Dominik Brodowski <linux@dominikbrodowski.net>,
	Peter Wippich <pewi@gw-instruments.de>,
	Gabor Juhos <juhosg@openwrt.org>,
	Guillaume LECERF <glecerf@gmail.com>,
	Jonas Gorski <jonas.gorski@gmail.com>,
	Jamie Iles <jamie@jamieiles.com>,
	Ivan Djelic <ivan.djelic@parrot.com>,
	Robert Jarzmik <robert.jarzmik@free.fr>,
	David Woodhouse <David.Woodhouse@intel.com>,
	Maxim Levitsky <maximlevitsky@gmail.com>,
	Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>,
	Kevin Cernekee <cernekee@gmail.com>,
	Barry Song <21cnbao@gmail.com>,
	Jim Quinlan <jim2101024@gmail.com>,
	Andres Salomon <dilinger@queued.net>,
	Axel Lin <axel.lin@gmail.com>, Anatolij Gustschin <agust@denx.de>,
	Mike Frysinger <vapier@gentoo.org>, Arnd Bergmann <arnd@arndb.de>,
	Lei Wen <leiwen@marvell.com>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Artem Bityutskiy <artem.bityutskiy@intel.com>,
	Florian Fainelli <florian@openwrt.org>,
	Ricard Wanderlof <ricard.wanderlof@axis.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Matthieu CASTET <matthieu.castet@parrot.com>,
	Kyungmin Park <kyungmin.park@samsung.com>,
	Shmulik Ladkani <shmulik.ladkani@gmail.com>,
	Wolfram Sang <w.sang@pengutronix.de>,
	Chuanxiao Dong <chuanxiao.dong@intel.com>,
	Joe Perches <joe@perches.com>,
	Brian Norris <computersforpeace@gmail.com>,
	Roman Tereshonkov <roman.tereshonkov@nokia.com>
Subject: [PATCH v4 1/2] mtd: nand: move SCANLASTPAGE handling to the correct code block
Date: Fri, 20 Jan 2012 20:38:03 -0800	[thread overview]
Message-ID: <1327120684-7066-2-git-send-email-computersforpeace@gmail.com> (raw)
In-Reply-To: <1327120684-7066-1-git-send-email-computersforpeace@gmail.com>

As nand_default_block_markbad() is becoming more complex, it helps to
have code appear only in its relevant codepath(s). Here, the calculation
of `ofs' based on NAND_BBT_SCANLASTPAGE is only useful on paths where we
write bad block markers to OOB. We move the condition/calculation closer
to the `write' operation and update the comment to more correctly
describe the operation.

The variable `wr_ofs' is also used to help isolate our calculation of
the "write" offset from the usage of `ofs' to represent the eraseblock
offset. This will become useful when we reorder operations in the next
patch.

This patch should make no functional change.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---
 drivers/mtd/nand/nand_base.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index c6603d4..b902066 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -411,9 +411,6 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
 		nand_erase_nand(mtd, &einfo, 0);
 	}
 
-	if (chip->bbt_options & NAND_BBT_SCANLASTPAGE)
-		ofs += mtd->erasesize - mtd->writesize;
-
 	/* Get block number */
 	block = (int)(ofs >> chip->bbt_erase_shift);
 	if (chip->bbt)
@@ -424,11 +421,12 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
 		ret = nand_update_bbt(mtd, ofs);
 	else {
 		struct mtd_oob_ops ops;
+		loff_t wr_ofs = ofs;
 
 		nand_get_device(chip, mtd, FL_WRITING);
 
 		/*
-		 * Write to first two pages if necessary. If we write to more
+		 * Write to first/last page(s) if necessary. If we write to more
 		 * than one location, the first error encountered quits the
 		 * procedure.
 		 */
@@ -442,11 +440,14 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
 			ops.len = ops.ooblen = 1;
 		}
 		ops.mode = MTD_OPS_PLACE_OOB;
+
+		if (chip->bbt_options & NAND_BBT_SCANLASTPAGE)
+			wr_ofs += mtd->erasesize - mtd->writesize;
 		do {
-			ret = nand_do_write_oob(mtd, ofs, &ops);
+			ret = nand_do_write_oob(mtd, wr_ofs, &ops);
 
 			i++;
-			ofs += mtd->writesize;
+			wr_ofs += mtd->writesize;
 		} while (!ret && (chip->bbt_options & NAND_BBT_SCAN2NDPAGE) &&
 				i < 2);
 
-- 
1.7.5.4

  reply	other threads:[~2012-01-21  4:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-21  4:38 [PATCH v4 0/2] write OOB BBM + flash-based BBT Brian Norris
2012-01-21  4:38 ` Brian Norris [this message]
2012-01-27 14:56   ` [PATCH v4 1/2] mtd: nand: move SCANLASTPAGE handling to the correct code block Bityutskiy, Artem
2012-01-28 20:09     ` Brian Norris
2012-01-21  4:38 ` [PATCH v4 2/2] mtd: nand: write BBM to OOB even with flash-based BBT Brian Norris
2012-01-21  9:57   ` Shmulik Ladkani
2012-01-21 10:10   ` Shmulik Ladkani
2012-01-23 21:31     ` Brian Norris
2012-02-02  8:12   ` Bityutskiy, Artem

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1327120684-7066-2-git-send-email-computersforpeace@gmail.com \
    --to=computersforpeace@gmail.com \
    --cc=21cnbao@gmail.com \
    --cc=David.Woodhouse@intel.com \
    --cc=adrian.hunter@intel.com \
    --cc=agust@denx.de \
    --cc=angus.clark@st.com \
    --cc=arnd@arndb.de \
    --cc=artem.bityutskiy@intel.com \
    --cc=axel.lin@gmail.com \
    --cc=bigeasy@linutronix.de \
    --cc=cernekee@gmail.com \
    --cc=chuanxiao.dong@intel.com \
    --cc=dbaryshkov@gmail.com \
    --cc=dilinger@queued.net \
    --cc=error27@gmail.com \
    --cc=florian@openwrt.org \
    --cc=glecerf@gmail.com \
    --cc=ivan.djelic@parrot.com \
    --cc=jamie@jamieiles.com \
    --cc=jim2101024@gmail.com \
    --cc=joe@perches.com \
    --cc=jonas.gorski@gmail.com \
    --cc=juhosg@openwrt.org \
    --cc=kyungmin.park@samsung.com \
    --cc=leiwen@marvell.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux@dominikbrodowski.net \
    --cc=matthieu.castet@parrot.com \
    --cc=maximlevitsky@gmail.com \
    --cc=nicolas.ferre@atmel.com \
    --cc=pewi@gw-instruments.de \
    --cc=ricard.wanderlof@axis.com \
    --cc=robert.jarzmik@free.fr \
    --cc=roman.tereshonkov@nokia.com \
    --cc=s.hauer@pengutronix.de \
    --cc=segooon@gmail.com \
    --cc=shmulik.ladkani@gmail.com \
    --cc=vapier@gentoo.org \
    --cc=w.sang@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox