UBI: Fix counting of ec value
Subsystems (2)
PATCH 1/1 UBI: Fix counting of ec value
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.
--- drivers/mtd/ubi/wl.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)
drivers/mtd/ubi/wl.c +15 -12
@@ -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_iif (unlikely (err)) goto out_free; - e->ec +=1 ; + e->ec = ec;if (e->ec > wl->max_ec) wl->max_ec = e->ec;
Hi Timo,
thanks for the patches. The comment-fixing one is fine - applied. This one is fine in general, but i have questions.
Quoted 10 lines · Timo Lindhorst
static int sync_erase(const struct
ubi_info*ubi, structubi_wl_entry*e,drivers/mtd/ubi/wl.c +2
-2int 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;
drivers/mtd/ubi/wl.c bitflip: · line 1411
Quoted 10 lines
drivers/mtd/ubi/wl.c +4
-1-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 ;
So why have you moved this memory allocation here?
drivers/mtd/ubi/wl.c bitflip: · line 1417
Quoted 6 lines
drivers/mtd/ubi/wl.c +6
-0+ + ret = err =ubi_io_sync_erase (ubi, e->pnum, torture); +if (unlikely (err <0 )) + goto out_free; + + ec += ret;
What's the point in the new 'ret' variable? Why ec += err does not work?
drivers/mtd/ubi/wl.c bitflip: · line 1425
Quoted 9 lines
drivers/mtd/ubi/wl.c +1
-1if (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 ;
And now you do not free memory. Please do not move the allocation if it is not really necessary.
Signature · 2 lines
Best regards, Artem Bityutskiy (Битюцкий Артём)
Hi Artem,
Quoted 6 lines
drivers/mtd/ubi/wl.c bitflip: · line 1411
Quoted 3 lines
drivers/mtd/ubi/wl.c +3
-0+ ec_hdr =ubi_zalloc_ec_hdr (ubi); +if (unlikely (!ec_hdr)) +return -ENOMEM ;So why have you moved this memory allocation here?
Actually I have not moved up the allocation, but moved down the
'if (unlikely(ec > UBI_MAX_ERASECOUNTER)) { ... ' block, since we need to know the new ec value before we can do this test.
I thought you want the allocation to be done before erasure, to prevent the erasure if the ec_hdr cannot be written due to a failure of memory allocation. Otherwise, the allocation can be moved down again, but than the new ec is possibly not written to the EB if no memory can be allocated for ec_hdr.
Do I miss something? What do you think?
Quoted 8 lines
drivers/mtd/ubi/wl.c bitflip: · line 1417
Quoted 6 lines
drivers/mtd/ubi/wl.c +6
-0+ + ret = err =ubi_io_sync_erase (ubi, e->pnum, torture); +if (unlikely (err <0 )) + goto out_free; + + ec += ret;What's the point in the new 'ret' variable? Why ec += err does not work?
I just thought adding an error code to a counter seems odd. Do you prefer this way?
Quoted 12 lines
Quoted 10 lines
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",drivers/mtd/ubi/wl.c +1
-1- e->pnum, e->ec); + e->pnum, ec);return -EINVAL;And now you do not free memory.
Yes, sorry! I have changed it to:
err = -EINVAL; goto out_free; }
I will resend the patch when I have got your comments to the upper points.
Kind regards,
Timo
Quoted 4 lines · Timo Lindhorst
Quoted 1 line
So why have you moved this memory allocation here?
Actually I have not moved up the allocation, but moved down the 'if (
unlikely(ec > UBI_MAX_ERASECOUNTER)) { ... ' block, since we need to know the new ec value before we can do this test.
OK, fine, just free the memory there.
Quoted 3 lines
Quoted 1 line
What's the point in the new 'ret' variable? Why ec += err does not work?
I just thought adding an error code to a counter seems odd. Do you prefer this way?
Well, it's anyway better then a distinct variable IMO. Moreover, it is used like this across the UBI code, so just assume it is UBI style :-)
Signature · 2 lines
Best regards, Artem Bityutskiy (Битюцкий Артём)