Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: dbb7d2a88d2a7b ("UBI: Add fastmap core")
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: Richard Weinberger <richard@nod.at>

authored by

Zhihao Cheng and committed by
Richard Weinberger
c3c07fc2 3b67db8a

+19 -9
+19 -9
drivers/mtd/ubi/fastmap.c
··· 468 468 if (err == UBI_IO_FF_BITFLIPS) 469 469 scrub = 1; 470 470 471 - add_aeb(ai, free, pnum, ec, scrub); 471 + ret = add_aeb(ai, free, pnum, ec, scrub); 472 + if (ret) 473 + goto out; 472 474 continue; 473 475 } else if (err == 0 || err == UBI_IO_BITFLIPS) { 474 476 dbg_bld("Found non empty PEB:%i in pool", pnum); ··· 640 638 if (fm_pos >= fm_size) 641 639 goto fail_bad; 642 640 643 - add_aeb(ai, &ai->free, be32_to_cpu(fmec->pnum), 644 - be32_to_cpu(fmec->ec), 0); 641 + ret = add_aeb(ai, &ai->free, be32_to_cpu(fmec->pnum), 642 + be32_to_cpu(fmec->ec), 0); 643 + if (ret) 644 + goto fail; 645 645 } 646 646 647 647 /* read EC values from used list */ ··· 653 649 if (fm_pos >= fm_size) 654 650 goto fail_bad; 655 651 656 - add_aeb(ai, &used, be32_to_cpu(fmec->pnum), 657 - be32_to_cpu(fmec->ec), 0); 652 + ret = add_aeb(ai, &used, be32_to_cpu(fmec->pnum), 653 + be32_to_cpu(fmec->ec), 0); 654 + if (ret) 655 + goto fail; 658 656 } 659 657 660 658 /* read EC values from scrub list */ ··· 666 660 if (fm_pos >= fm_size) 667 661 goto fail_bad; 668 662 669 - add_aeb(ai, &used, be32_to_cpu(fmec->pnum), 670 - be32_to_cpu(fmec->ec), 1); 663 + ret = add_aeb(ai, &used, be32_to_cpu(fmec->pnum), 664 + be32_to_cpu(fmec->ec), 1); 665 + if (ret) 666 + goto fail; 671 667 } 672 668 673 669 /* read EC values from erase list */ ··· 679 671 if (fm_pos >= fm_size) 680 672 goto fail_bad; 681 673 682 - add_aeb(ai, &ai->erase, be32_to_cpu(fmec->pnum), 683 - be32_to_cpu(fmec->ec), 1); 674 + ret = add_aeb(ai, &ai->erase, be32_to_cpu(fmec->pnum), 675 + be32_to_cpu(fmec->ec), 1); 676 + if (ret) 677 + goto fail; 684 678 } 685 679 686 680 ai->mean_ec = div_u64(ai->ec_sum, ai->ec_count);