[PATCH take 2] [MTD] UBI: Fix counting of ec value

Timo Lindhorst
2007-02-12T15:01:33Z

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 | 30 +++++++++++++++++-------------
1 file changed, 17 insertions(+), 13 deletions(-)

--- ubi-2.6.git.orig/drivers/mtd/ubi/wl.c
+++ ubi-2.6.git/drivers/mtd/ubi/wl.c
@@ -1398,24 +1398,14 @@ static int sync_erase(const struct ubi_i
int err;
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 %llu", e->pnum, (unsigned long long)ec);

err = paranoid_check_ec(ubi, e->pnum, e->ec);
if (unlikely(err > 0))
return -EINVAL;

- 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);
- return -EINVAL;
- }
-
ec_hdr = ubi_zalloc_ec_hdr(ubi);
if (unlikely(!ec_hdr))
return -ENOMEM;
@@ -1424,13 +1414,27 @@ static int sync_erase(const struct ubi_i
if (unlikely(err < 0))
goto out_free;

+ ec += err;
+ 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 %llu",
+ e->pnum, (unsigned long long)ec);
+ err = -EINVAL;
+ goto out_free;
+ }
+
+ dbg_wl("erased PEB %d, new EC %llu", e->pnum, (unsigned long long)ec);
+
ec_hdr->ec = cpu_to_ubi64(ec);

err = ubi_io_write_ec_hdr(ubi, e->pnum, ec_hdr);
if (unlikely(err))
goto out_free;

- e->ec += 1;
+ e->ec = ec;
if (e->ec > wl->max_ec)
wl->max_ec = e->ec;