Commit 02f9f25b authored by Zhihao Cheng's avatar Zhihao Cheng
Browse files

ubi: fastmap: erase_block: Get erase counter from wl_entry rather than flash

mainline inclusion
from mainline-v6.7-rc1
commit 08a4267874164b2e9c8c50831acd466f47208acc
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I9195H
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=08a4267874164b2e9c8c50831acd466f47208acc



-------------------------------------------------

Just like sync_erase() does, getting erase counter from wl_entry is
faster than reading from flash.

Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
parent 69bb0207
Loading
Loading
Loading
Loading
+9 −18
Original line number Diff line number Diff line
@@ -1388,36 +1388,27 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
 */
static int erase_block(struct ubi_device *ubi, struct ubi_wl_entry *e)
{
	int ret;
	int err;
	struct ubi_ec_hdr *ec_hdr;
	long long ec;
	long long ec = e->ec;

	ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
	if (!ec_hdr)
		return -ENOMEM;

	ret = ubi_io_read_ec_hdr(ubi, e->pnum, ec_hdr, 0);
	if (ret < 0)
		goto out;
	else if (ret && ret != UBI_IO_BITFLIPS) {
		ret = -EINVAL;
		goto out;
	}

	ret = ubi_io_sync_erase(ubi, e->pnum, 0);
	if (ret < 0)
	err = ubi_io_sync_erase(ubi, e->pnum, 0);
	if (err < 0)
		goto out;

	ec = be64_to_cpu(ec_hdr->ec);
	ec += ret;
	ec += err;
	if (ec > UBI_MAX_ERASECOUNTER) {
		ret = -EINVAL;
		err = -EINVAL;
		goto out;
	}

	ec_hdr->ec = cpu_to_be64(ec);
	ret = ubi_io_write_ec_hdr(ubi, e->pnum, ec_hdr);
	if (ret < 0)
	err = ubi_io_write_ec_hdr(ubi, e->pnum, ec_hdr);
	if (err < 0)
		goto out;

	e->ec = ec;
@@ -1428,7 +1419,7 @@ static int erase_block(struct ubi_device *ubi, struct ubi_wl_entry *e)

out:
	kfree(ec_hdr);
	return ret;
	return err;
}

/**