public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Timo Lindhorst <lindhors@linux.vnet.ibm.com>
To: MTD list <linux-mtd@lists.infradead.org>
Subject: [PATCH] [MTD] UBI: Fix counting of ec value
Date: Mon, 12 Feb 2007 10:16:40 +0100	[thread overview]
Message-ID: <200702121016.40516.lindhors@linux.vnet.ibm.com> (raw)

If the torture is triggered on a peb, the block is erased more than
once. So the ec value should be increased accordingly.
ubi_io_sync_erase returns the number of erasures made, so this value
can be used instead of a static 1.

Signed-off-by: Timo Lindhorst <lindhors@linux.vnet.ibm.com>
---
 drivers/mtd/ubi/wl.c |   27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

--- ubi-2.6.git.orig/drivers/mtd/ubi/wl.c
+++ ubi-2.6.git/drivers/mtd/ubi/wl.c
@@ -1395,34 +1395,37 @@ bitflip:
 static int sync_erase(const struct ubi_info *ubi, struct ubi_wl_entry *e,
 		      int torture)
 {
-	int err;
+	int err, ret;
 	struct ubi_ec_hdr *ec_hdr;
 	struct ubi_wl_info *wl = ubi->wl;
-	uint64_t ec = e->ec + 1;
+	uint64_t ec = e->ec;
 
-	dbg_wl("erase PEB %d, new EC %lld", e->pnum, (long long)ec);
+	dbg_wl("erase PEB %d, old EC %lld", e->pnum, (long long)ec);
 
 	err = paranoid_check_ec(ubi, e->pnum, e->ec);
 	if (unlikely(err > 0))
 		return -EINVAL;
 
+	ec_hdr = ubi_zalloc_ec_hdr(ubi);
+	if (unlikely(!ec_hdr))
+		return -ENOMEM;
+
+	ret = err = ubi_io_sync_erase(ubi, e->pnum, torture);
+	if (unlikely(err < 0))
+		goto out_free;
+
+	ec += ret;
 	if (unlikely(ec > UBI_MAX_ERASECOUNTER)) {
 		/*
 		 * Erase counter overflow. Upgrade UBI and use 64-bit
 		 * erase counters internally.
 		 */
 		ubi_err("erase counter overflow at PEB %d, EC %d",
-			e->pnum, e->ec);
+			e->pnum, ec);
 		return -EINVAL;
 	}
 
-	ec_hdr = ubi_zalloc_ec_hdr(ubi);
-	if (unlikely(!ec_hdr))
-		return -ENOMEM;
-
-	err = ubi_io_sync_erase(ubi, e->pnum, torture);
-	if (unlikely(err < 0))
-		goto out_free;
+	dbg_wl("erased PEB %d, new EC %lld", e->pnum, (long long)ec);
 
 	ec_hdr->ec = cpu_to_ubi64(ec);
 
@@ -1430,7 +1433,7 @@ static int sync_erase(const struct ubi_i
 	if (unlikely(err))
 		goto out_free;
 
-	e->ec += 1;
+	e->ec = ec;
 	if (e->ec > wl->max_ec)
 		wl->max_ec = e->ec;
 

             reply	other threads:[~2007-02-12  9:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-12  9:16 Timo Lindhorst [this message]
2007-02-12  9:52 ` [PATCH] [MTD] UBI: Fix counting of ec value Artem Bityutskiy
2007-02-12 10:48   ` Timo Lindhorst
2007-02-12 11:38     ` Artem Bityutskiy

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=200702121016.40516.lindhors@linux.vnet.ibm.com \
    --to=lindhors@linux.vnet.ibm.com \
    --cc=linux-mtd@lists.infradead.org \
    /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