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

UBI: print a warning if too many PEBs are corrupted

There was a bug report recently where UBI prints:

UBI error: ubi_attach_mtd_dev: failed to attach by scanning, error -22

error messages and refuses to attach a PEB. It turned out to be a
buggy flash driver which returned garbage to almost every UBI read.
This patch makes UBI print a better message in such cases. Namely,
if UBI finds 8 or more corrupted PEBs, it prints a warning and
lists the corrupted PEBs.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

+18 -2
+16 -2
drivers/mtd/ubi/scan.c
··· 75 75 dbg_bld("add to free: PEB %d, EC %d", pnum, ec); 76 76 else if (list == &si->erase) 77 77 dbg_bld("add to erase: PEB %d, EC %d", pnum, ec); 78 - else if (list == &si->corr) 78 + else if (list == &si->corr) { 79 79 dbg_bld("add to corrupted: PEB %d, EC %d", pnum, ec); 80 - else if (list == &si->alien) 80 + si->corr_count += 1; 81 + } else if (list == &si->alien) 81 82 dbg_bld("add to alien: PEB %d, EC %d", pnum, ec); 82 83 else 83 84 BUG(); ··· 937 936 938 937 if (si->is_empty) 939 938 ubi_msg("empty MTD device detected"); 939 + 940 + /* 941 + * Few corrupted PEBs are not a problem and may be just a result of 942 + * unclean reboots. However, many of them may indicate some problems 943 + * with the flash HW or driver. Print a warning in this case. 944 + */ 945 + if (si->corr_count >= 8 || si->corr_count >= ubi->peb_count / 4) { 946 + ubi_warn("%d PEBs are corrupted", si->corr_count); 947 + printk(KERN_WARNING "corrupted PEBs are:"); 948 + list_for_each_entry(seb, &si->corr, u.list) 949 + printk(KERN_CONT " %d", seb->pnum); 950 + printk(KERN_CONT "\n"); 951 + } 940 952 941 953 /* 942 954 * In case of unknown erase counter we use the mean erase counter
+2
drivers/mtd/ubi/scan.h
··· 102 102 * @mean_ec: mean erase counter value 103 103 * @ec_sum: a temporary variable used when calculating @mean_ec 104 104 * @ec_count: a temporary variable used when calculating @mean_ec 105 + * @corr_count: count of corrupted PEBs 105 106 * @image_seq_set: indicates @ubi->image_seq is known 106 107 * 107 108 * This data structure contains the result of scanning and may be used by other ··· 126 125 int mean_ec; 127 126 uint64_t ec_sum; 128 127 int ec_count; 128 + int corr_count; 129 129 int image_seq_set; 130 130 }; 131 131