Skip to content

Commit c3c07fc

Browse files
Zhihao Chengrichardweinberger
authored andcommitted
ubi: fastmap: Return error code if memory allocation fails in add_aeb()
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: dbb7d2a ("UBI: Add fastmap core") Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com> Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent 3b67db8 commit c3c07fc

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

drivers/mtd/ubi/fastmap.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,9 @@ static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
468468
if (err == UBI_IO_FF_BITFLIPS)
469469
scrub = 1;
470470

471-
add_aeb(ai, free, pnum, ec, scrub);
471+
ret = add_aeb(ai, free, pnum, ec, scrub);
472+
if (ret)
473+
goto out;
472474
continue;
473475
} else if (err == 0 || err == UBI_IO_BITFLIPS) {
474476
dbg_bld("Found non empty PEB:%i in pool", pnum);
@@ -638,8 +640,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
638640
if (fm_pos >= fm_size)
639641
goto fail_bad;
640642

641-
add_aeb(ai, &ai->free, be32_to_cpu(fmec->pnum),
642-
be32_to_cpu(fmec->ec), 0);
643+
ret = add_aeb(ai, &ai->free, be32_to_cpu(fmec->pnum),
644+
be32_to_cpu(fmec->ec), 0);
645+
if (ret)
646+
goto fail;
643647
}
644648

645649
/* read EC values from used list */
@@ -649,8 +653,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
649653
if (fm_pos >= fm_size)
650654
goto fail_bad;
651655

652-
add_aeb(ai, &used, be32_to_cpu(fmec->pnum),
653-
be32_to_cpu(fmec->ec), 0);
656+
ret = add_aeb(ai, &used, be32_to_cpu(fmec->pnum),
657+
be32_to_cpu(fmec->ec), 0);
658+
if (ret)
659+
goto fail;
654660
}
655661

656662
/* read EC values from scrub list */
@@ -660,8 +666,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
660666
if (fm_pos >= fm_size)
661667
goto fail_bad;
662668

663-
add_aeb(ai, &used, be32_to_cpu(fmec->pnum),
664-
be32_to_cpu(fmec->ec), 1);
669+
ret = add_aeb(ai, &used, be32_to_cpu(fmec->pnum),
670+
be32_to_cpu(fmec->ec), 1);
671+
if (ret)
672+
goto fail;
665673
}
666674

667675
/* read EC values from erase list */
@@ -671,8 +679,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
671679
if (fm_pos >= fm_size)
672680
goto fail_bad;
673681

674-
add_aeb(ai, &ai->erase, be32_to_cpu(fmec->pnum),
675-
be32_to_cpu(fmec->ec), 1);
682+
ret = add_aeb(ai, &ai->erase, be32_to_cpu(fmec->pnum),
683+
be32_to_cpu(fmec->ec), 1);
684+
if (ret)
685+
goto fail;
676686
}
677687

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

0 commit comments

Comments
 (0)