/**
* erase_block - Manually erase a PEB.
* @ubi: UBI device object
- * @pnum: PEB to be erased
+ * @e: the physical eraseblock to erase
*
- * Returns the new EC value on success, < 0 indicates an internal error.
+ * This function returns zero in case of success and a negative error code in
+ * case of failure.
*/
-static int erase_block(struct ubi_device *ubi, int pnum)
+static int erase_block(struct ubi_device *ubi, struct ubi_wl_entry *e)
{
int ret;
struct ubi_ec_hdr *ec_hdr;
if (!ec_hdr)
return -ENOMEM;
- ret = ubi_io_read_ec_hdr(ubi, pnum, ec_hdr, 0);
+ ret = ubi_io_read_ec_hdr(ubi, e->pnum, ec_hdr, 0);
if (ret < 0)
goto out;
else if (ret && ret != UBI_IO_BITFLIPS) {
goto out;
}
- ret = ubi_io_sync_erase(ubi, pnum, 0);
+ ret = ubi_io_sync_erase(ubi, e->pnum, 0);
if (ret < 0)
goto out;
}
ec_hdr->ec = cpu_to_be64(ec);
- ret = ubi_io_write_ec_hdr(ubi, pnum, ec_hdr);
+ ret = ubi_io_write_ec_hdr(ubi, e->pnum, ec_hdr);
if (ret < 0)
goto out;
- ret = ec;
+ e->ec = ec;
+ spin_lock(&ubi->wl_lock);
+ if (e->ec > ubi->max_ec)
+ ubi->max_ec = e->ec;
+ spin_unlock(&ubi->wl_lock);
+
out:
kfree(ec_hdr);
return ret;
if (!tmp_e) {
if (old_fm && old_fm->e[i]) {
- ret = erase_block(ubi, old_fm->e[i]->pnum);
+ ret = erase_block(ubi, old_fm->e[i]);
if (ret < 0) {
ubi_err(ubi, "could not erase old fastmap PEB");
if (old_fm) {
/* no fresh anchor PEB was found, reuse the old one */
if (!tmp_e) {
- ret = erase_block(ubi, old_fm->e[0]->pnum);
+ ret = erase_block(ubi, old_fm->e[0]);
if (ret < 0) {
ubi_err(ubi, "could not erase old anchor PEB");
goto err;
}
new_fm->e[0] = old_fm->e[0];
- new_fm->e[0]->ec = ret;
old_fm->e[0] = NULL;
} else {
/* we've got a new anchor PEB, return the old one */