From 9fd4be3fc095e38f5c11eb8397c949d68576af83 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 4 Apr 2022 12:21:34 +0200 Subject: [PATCH] 4.14-stable patches added patches: ubi-fastmap-return-error-code-if-memory-allocation-fails-in-add_aeb.patch --- queue-4.14/series | 1 + ...f-memory-allocation-fails-in-add_aeb.patch | 86 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 queue-4.14/ubi-fastmap-return-error-code-if-memory-allocation-fails-in-add_aeb.patch diff --git a/queue-4.14/series b/queue-4.14/series index 528f2f77a01..cc61d4d5ed5 100644 --- a/queue-4.14/series +++ b/queue-4.14/series @@ -199,3 +199,4 @@ ubi-fix-race-condition-between-ctrl_cdev_ioctl-and-ubi_cdev_ioctl.patch acpi-cppc-avoid-out-of-bounds-access-when-parsing-_cpc-data.patch mm-mmap-return-1-from-stack_guard_gap-__setup-handler.patch mm-memcontrol-return-1-from-cgroup.memory-__setup-handler.patch +ubi-fastmap-return-error-code-if-memory-allocation-fails-in-add_aeb.patch diff --git a/queue-4.14/ubi-fastmap-return-error-code-if-memory-allocation-fails-in-add_aeb.patch b/queue-4.14/ubi-fastmap-return-error-code-if-memory-allocation-fails-in-add_aeb.patch new file mode 100644 index 00000000000..c6cb3100891 --- /dev/null +++ b/queue-4.14/ubi-fastmap-return-error-code-if-memory-allocation-fails-in-add_aeb.patch @@ -0,0 +1,86 @@ +From c3c07fc25f37c157fde041b3a0c3dfcb1590cbce Mon Sep 17 00:00:00 2001 +From: Zhihao Cheng +Date: Mon, 27 Dec 2021 11:22:42 +0800 +Subject: ubi: fastmap: Return error code if memory allocation fails in add_aeb() + +From: Zhihao Cheng + +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: dbb7d2a88d2a7b ("UBI: Add fastmap core") +Signed-off-by: Zhihao Cheng +Signed-off-by: Richard Weinberger +Signed-off-by: Greg Kroah-Hartman +--- + drivers/mtd/ubi/fastmap.c | 28 +++++++++++++++++++--------- + 1 file changed, 19 insertions(+), 9 deletions(-) + +--- a/drivers/mtd/ubi/fastmap.c ++++ b/drivers/mtd/ubi/fastmap.c +@@ -478,7 +478,9 @@ static int scan_pool(struct ubi_device * + 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 + if (fm_pos >= fm_size) + goto fail_bad; + +- add_aeb(ai, &ai->free, be32_to_cpu(fmec->pnum), +- be32_to_cpu(fmec->ec), 0); ++ 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 + if (fm_pos >= fm_size) + goto fail_bad; + +- add_aeb(ai, &used, be32_to_cpu(fmec->pnum), +- be32_to_cpu(fmec->ec), 0); ++ 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 + if (fm_pos >= fm_size) + goto fail_bad; + +- add_aeb(ai, &used, be32_to_cpu(fmec->pnum), +- be32_to_cpu(fmec->ec), 1); ++ 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 + if (fm_pos >= fm_size) + goto fail_bad; + +- add_aeb(ai, &ai->erase, be32_to_cpu(fmec->pnum), +- be32_to_cpu(fmec->ec), 1); ++ 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); -- 2.47.3