Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5a86cd06 authored by Zhihao Cheng's avatar Zhihao Cheng Committed by Greg Kroah-Hartman
Browse files

ubi: fastmap: Return error code if memory allocation fails in add_aeb()



commit c3c07fc25f37c157fde041b3a0c3dfcb1590cbce upstream.

Abort fastmap scanning and return error code if memory allocation fails
in add_aeb(). Otherwise ubi will get wrong peb statistics information
after scanning.

Fixes: dbb7d2a8 ("UBI: Add fastmap core")
Signed-off-by: default avatarZhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent bf1e2583
Loading
Loading
Loading
Loading
+19 −9
Original line number Diff line number Diff line
@@ -478,7 +478,9 @@ static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
			if (err == UBI_IO_FF_BITFLIPS)
				scrub = 1;

			add_aeb(ai, free, pnum, ec, scrub);
			ret = add_aeb(ai, free, pnum, ec, scrub);
			if (ret)
				goto out;
			continue;
		} else if (err == 0 || err == UBI_IO_BITFLIPS) {
			dbg_bld("Found non empty PEB:%i in pool", pnum);
@@ -648,8 +650,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
		if (fm_pos >= fm_size)
			goto fail_bad;

		add_aeb(ai, &ai->free, be32_to_cpu(fmec->pnum),
		ret = add_aeb(ai, &ai->free, be32_to_cpu(fmec->pnum),
			      be32_to_cpu(fmec->ec), 0);
		if (ret)
			goto fail;
	}

	/* read EC values from used list */
@@ -659,8 +663,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
		if (fm_pos >= fm_size)
			goto fail_bad;

		add_aeb(ai, &used, be32_to_cpu(fmec->pnum),
		ret = add_aeb(ai, &used, be32_to_cpu(fmec->pnum),
			      be32_to_cpu(fmec->ec), 0);
		if (ret)
			goto fail;
	}

	/* read EC values from scrub list */
@@ -670,8 +676,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
		if (fm_pos >= fm_size)
			goto fail_bad;

		add_aeb(ai, &used, be32_to_cpu(fmec->pnum),
		ret = add_aeb(ai, &used, be32_to_cpu(fmec->pnum),
			      be32_to_cpu(fmec->ec), 1);
		if (ret)
			goto fail;
	}

	/* read EC values from erase list */
@@ -681,8 +689,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
		if (fm_pos >= fm_size)
			goto fail_bad;

		add_aeb(ai, &ai->erase, be32_to_cpu(fmec->pnum),
		ret = add_aeb(ai, &ai->erase, be32_to_cpu(fmec->pnum),
			      be32_to_cpu(fmec->ec), 1);
		if (ret)
			goto fail;
	}

	ai->mean_ec = div_u64(ai->ec_sum, ai->ec_count);