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

UBI: remove bogus debugging checks

The 'paranoid_check_empty()' is bogus because, which is easilly
seen on NOR flash, which has long erase cycles, and which may
easilly end-up with half-erased eraseblocks. In this case the
paranoid check fails. I is just wrong to assume that PEBs which
do not have EC headers always contain all 0xFF. Such assumption
should not be made on the I/O level, which is quite low.

Thus, just kill the check.

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

+2 -88
+1
drivers/mtd/ubi/debug.h
··· 173 173 #define ubi_dbg_is_bitflip() 0 174 174 #define ubi_dbg_is_write_failure() 0 175 175 #define ubi_dbg_is_erase_failure() 0 176 + #define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0 176 177 177 178 #endif /* !CONFIG_MTD_UBI_DEBUG */ 178 179 #endif /* !__UBI_DEBUG_H__ */
-87
drivers/mtd/ubi/io.c
··· 98 98 static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum); 99 99 static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum, 100 100 const struct ubi_vid_hdr *vid_hdr); 101 - static int paranoid_check_empty(struct ubi_device *ubi, int pnum); 102 101 #else 103 102 #define paranoid_check_not_bad(ubi, pnum) 0 104 103 #define paranoid_check_peb_ec_hdr(ubi, pnum) 0 105 104 #define paranoid_check_ec_hdr(ubi, pnum, ec_hdr) 0 106 105 #define paranoid_check_peb_vid_hdr(ubi, pnum) 0 107 106 #define paranoid_check_vid_hdr(ubi, pnum, vid_hdr) 0 108 - #define paranoid_check_empty(ubi, pnum) 0 109 107 #endif 110 108 111 109 /** ··· 667 669 if (read_err != -EBADMSG && 668 670 check_pattern(ec_hdr, 0xFF, UBI_EC_HDR_SIZE)) { 669 671 /* The physical eraseblock is supposedly empty */ 670 - err = ubi_dbg_check_all_ff(ubi, pnum, 0, ubi->peb_size); 671 - if (err) 672 - return err > 0 ? UBI_IO_BAD_EC_HDR : err; 673 - 674 672 if (verbose) 675 673 ubi_warn("no EC header found at PEB %d, " 676 674 "only 0xFF bytes", pnum); ··· 937 943 if (read_err != -EBADMSG && 938 944 check_pattern(vid_hdr, 0xFF, UBI_VID_HDR_SIZE)) { 939 945 /* The physical eraseblock is supposedly free */ 940 - 941 - /* 942 - * The below is just a paranoid check, it has to be 943 - * compiled out if paranoid checks are disabled. 944 - */ 945 - err = paranoid_check_empty(ubi, pnum); 946 - if (err) 947 - return err > 0 ? UBI_IO_BAD_VID_HDR : err; 948 - 949 946 if (verbose) 950 947 ubi_warn("no VID header found at PEB %d, " 951 948 "only 0xFF bytes", pnum); ··· 1226 1241 int err; 1227 1242 loff_t addr = (loff_t)pnum * ubi->peb_size + offset; 1228 1243 1229 - ubi_assert(!mutex_is_locked(&ubi->dbg_buf_mutex)); 1230 - 1231 1244 mutex_lock(&ubi->dbg_buf_mutex); 1232 1245 err = ubi->mtd->read(ubi->mtd, addr, len, &read, ubi->dbg_peb_buf); 1233 1246 if (err && err != -EUCLEAN) { ··· 1247 1264 fail: 1248 1265 ubi_err("paranoid check failed for PEB %d", pnum); 1249 1266 ubi_msg("hex dump of the %d-%d region", offset, offset + len); 1250 - print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, 1251 - ubi->dbg_peb_buf, len, 1); 1252 - err = 1; 1253 - error: 1254 - ubi_dbg_dump_stack(); 1255 - mutex_unlock(&ubi->dbg_buf_mutex); 1256 - return err; 1257 - } 1258 - 1259 - /** 1260 - * paranoid_check_empty - whether a PEB is empty. 1261 - * @ubi: UBI device description object 1262 - * @pnum: the physical eraseblock number to check 1263 - * 1264 - * This function makes sure PEB @pnum is empty, which means it contains only 1265 - * %0xFF data bytes. Returns zero if the PEB is empty, %1 if not, and a 1266 - * negative error code in case of failure. 1267 - * 1268 - * Empty PEBs have the EC header, and do not have the VID header. The caller of 1269 - * this function should have already made sure the PEB does not have the VID 1270 - * header. However, this function re-checks that, because it is possible that 1271 - * the header and data has already been written to the PEB. 1272 - * 1273 - * Let's consider a possible scenario. Suppose there are 2 tasks - A and B. 1274 - * Task A is in 'wear_leveling_worker()'. It is reading VID header of PEB X to 1275 - * find which LEB it corresponds to. PEB X is currently unmapped, and has no 1276 - * VID header. Task B is trying to write to PEB X. 1277 - * 1278 - * Task A: in 'ubi_io_read_vid_hdr()': reads the VID header from PEB X. The 1279 - * read data contain all 0xFF bytes; 1280 - * Task B: writes VID header and some data to PEB X; 1281 - * Task A: assumes PEB X is empty, calls 'paranoid_check_empty()'. And if we 1282 - * do not re-read the VID header, and do not cancel the checking if it 1283 - * is there, we fail. 1284 - */ 1285 - static int paranoid_check_empty(struct ubi_device *ubi, int pnum) 1286 - { 1287 - int err, offs = ubi->vid_hdr_aloffset, len = ubi->vid_hdr_alsize; 1288 - size_t read; 1289 - uint32_t magic; 1290 - const struct ubi_vid_hdr *vid_hdr; 1291 - 1292 - mutex_lock(&ubi->dbg_buf_mutex); 1293 - err = ubi->mtd->read(ubi->mtd, offs, len, &read, ubi->dbg_peb_buf); 1294 - if (err && err != -EUCLEAN) { 1295 - ubi_err("error %d while reading %d bytes from PEB %d:%d, " 1296 - "read %zd bytes", err, len, pnum, offs, read); 1297 - goto error; 1298 - } 1299 - 1300 - vid_hdr = ubi->dbg_peb_buf; 1301 - magic = be32_to_cpu(vid_hdr->magic); 1302 - if (magic == UBI_VID_HDR_MAGIC) 1303 - /* The PEB contains VID header, so it is not empty */ 1304 - goto out; 1305 - 1306 - err = check_pattern(ubi->dbg_peb_buf, 0xFF, len); 1307 - if (err == 0) { 1308 - ubi_err("flash region at PEB %d:%d, length %d does not " 1309 - "contain all 0xFF bytes", pnum, offs, len); 1310 - goto fail; 1311 - } 1312 - 1313 - out: 1314 - mutex_unlock(&ubi->dbg_buf_mutex); 1315 - return 0; 1316 - 1317 - fail: 1318 - ubi_err("paranoid check failed for PEB %d", pnum); 1319 - ubi_msg("hex dump of the %d-%d region", offs, offs + len); 1320 1267 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, 1321 1268 ubi->dbg_peb_buf, len, 1); 1322 1269 err = 1;
+1 -1
drivers/mtd/ubi/wl.c
··· 463 463 err = ubi_dbg_check_all_ff(ubi, e->pnum, ubi->vid_hdr_aloffset, 464 464 ubi->peb_size - ubi->vid_hdr_aloffset); 465 465 if (err) { 466 - dbg_err("new PEB does not contain all 0xFF bytes"); 466 + ubi_err("new PEB %d does not contain all 0xFF bytes", e->pnum); 467 467 return err > 0 ? -EINVAL : err; 468 468 } 469 469