aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi/eba.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/ubi/eba.c')
-rw-r--r--drivers/mtd/ubi/eba.c42
1 files changed, 39 insertions, 3 deletions
diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index b582671ca3a0..fe74749e0dae 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -1166,6 +1166,44 @@ out_unlock_leb:
1166} 1166}
1167 1167
1168/** 1168/**
1169 * print_rsvd_warning - warn about not having enough reserved PEBs.
1170 * @ubi: UBI device description object
1171 *
1172 * This is a helper function for 'ubi_eba_init_scan()' which is called when UBI
1173 * cannot reserve enough PEBs for bad block handling. This function makes a
1174 * decision whether we have to print a warning or not. The algorithm is as
1175 * follows:
1176 * o if this is a new UBI image, then just print the warning
1177 * o if this is an UBI image which has already been used for some time, print
1178 * a warning only if we can reserve less than 10% of the expected amount of
1179 * the reserved PEB.
1180 *
1181 * The idea is that when UBI is used, PEBs become bad, and the reserved pool
1182 * of PEBs becomes smaller, which is normal and we do not want to scare users
1183 * with a warning every time they attach the MTD device. This was an issue
1184 * reported by real users.
1185 */
1186static void print_rsvd_warning(struct ubi_device *ubi,
1187 struct ubi_scan_info *si)
1188{
1189 /*
1190 * The 1 << 18 (256KiB) number is picked randomly, just a reasonably
1191 * large number to distinguish between newly flashed and used images.
1192 */
1193 if (si->max_sqnum > (1 << 18)) {
1194 int min = ubi->beb_rsvd_level / 10;
1195
1196 if (!min)
1197 min = 1;
1198 if (ubi->beb_rsvd_pebs > min)
1199 return;
1200 }
1201
1202 ubi_warn("cannot reserve enough PEBs for bad PEB handling, reserved %d,"
1203 " need %d", ubi->beb_rsvd_pebs, ubi->beb_rsvd_level);
1204}
1205
1206/**
1169 * ubi_eba_init_scan - initialize the EBA sub-system using scanning information. 1207 * ubi_eba_init_scan - initialize the EBA sub-system using scanning information.
1170 * @ubi: UBI device description object 1208 * @ubi: UBI device description object
1171 * @si: scanning information 1209 * @si: scanning information
@@ -1237,9 +1275,7 @@ int ubi_eba_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si)
1237 if (ubi->avail_pebs < ubi->beb_rsvd_level) { 1275 if (ubi->avail_pebs < ubi->beb_rsvd_level) {
1238 /* No enough free physical eraseblocks */ 1276 /* No enough free physical eraseblocks */
1239 ubi->beb_rsvd_pebs = ubi->avail_pebs; 1277 ubi->beb_rsvd_pebs = ubi->avail_pebs;
1240 ubi_warn("cannot reserve enough PEBs for bad PEB " 1278 print_rsvd_warning(ubi, si);
1241 "handling, reserved %d, need %d",
1242 ubi->beb_rsvd_pebs, ubi->beb_rsvd_level);
1243 } else 1279 } else
1244 ubi->beb_rsvd_pebs = ubi->beb_rsvd_level; 1280 ubi->beb_rsvd_pebs = ubi->beb_rsvd_level;
1245 1281