39
39
* eraseblocks are put to the @free list and the physical eraseblock to be
40
40
* erased are put to the @erase list.
45
* UBI protects EC and VID headers with CRC-32 checksums, so it can detect
46
* whether the headers are corrupted or not. Sometimes UBI also protects the
47
* data with CRC-32, e.g., when it executes the atomic LEB change operation, or
48
* when it moves the contents of a PEB for wear-leveling purposes.
42
50
* UBI tries to distinguish between 2 types of corruptions.
43
* 1. Corruptions caused by power cuts. These are harmless and expected
44
* corruptions and UBI tries to handle them gracefully, without printing too
45
* many warnings and error messages. The idea is that we do not lose
46
* important data in these case - we may lose only the data which was being
47
* written to the media just before the power cut happened, and the upper
48
* layers (e.g., UBIFS) are supposed to handle these situations. UBI puts
49
* these PEBs to the head of the @erase list and they are scheduled for
52
* 1. Corruptions caused by power cuts. These are expected corruptions and UBI
53
* tries to handle them gracefully, without printing too many warnings and
54
* error messages. The idea is that we do not lose important data in these case
55
* - we may lose only the data which was being written to the media just before
56
* the power cut happened, and the upper layers (e.g., UBIFS) are supposed to
57
* handle such data losses (e.g., by using the FS journal).
59
* When UBI detects a corruption (CRC-32 mismatch) in a PEB, and it looks like
60
* the reason is a power cut, UBI puts this PEB to the @erase list, and all
61
* PEBs in the @erase list are scheduled for erasure later.
52
63
* 2. Unexpected corruptions which are not caused by power cuts. During
53
* scanning, such PEBs are put to the @corr list and UBI preserves them.
54
* Obviously, this lessens the amount of available PEBs, and if at some
55
* point UBI runs out of free PEBs, it switches to R/O mode. UBI also loudly
56
* informs about such PEBs every time the MTD device is attached.
64
* scanning, such PEBs are put to the @corr list and UBI preserves them.
65
* Obviously, this lessens the amount of available PEBs, and if at some point
66
* UBI runs out of free PEBs, it switches to R/O mode. UBI also loudly informs
67
* about such PEBs every time the MTD device is attached.
58
69
* However, it is difficult to reliably distinguish between these types of
59
* corruptions and UBI's strategy is as follows. UBI assumes (2.) if the VID
60
* header is corrupted and the data area does not contain all 0xFFs, and there
61
* were not bit-flips or integrity errors while reading the data area. Otherwise
62
* UBI assumes (1.). The assumptions are:
63
* o if the data area contains only 0xFFs, there is no data, and it is safe
64
* to just erase this PEB.
65
* o if the data area has bit-flips and data integrity errors (ECC errors on
70
* corruptions and UBI's strategy is as follows. UBI assumes corruption type 2
71
* if the VID header is corrupted and the data area does not contain all 0xFFs,
72
* and there were no bit-flips or integrity errors while reading the data area.
73
* Otherwise UBI assumes corruption type 1. So the decision criteria are as
75
* o If the data area contains only 0xFFs, there is no data, and it is safe
76
* to just erase this PEB - this is corruption type 1.
77
* o If the data area has bit-flips or data integrity errors (ECC errors on
66
78
* NAND), it is probably a PEB which was being erased when power cut
79
* happened, so this is corruption type 1. However, this is just a guess,
80
* which might be wrong.
81
* o Otherwise this it corruption type 2.
70
84
#include <linux/err.h>
1266
1289
list_for_each_entry_safe(seb, seb_tmp, &si->alien, u.list) {
1267
1290
list_del(&seb->u.list);
1291
kmem_cache_free(si->scan_leb_slab, seb);
1270
1293
list_for_each_entry_safe(seb, seb_tmp, &si->erase, u.list) {
1271
1294
list_del(&seb->u.list);
1295
kmem_cache_free(si->scan_leb_slab, seb);
1274
1297
list_for_each_entry_safe(seb, seb_tmp, &si->corr, u.list) {
1275
1298
list_del(&seb->u.list);
1299
kmem_cache_free(si->scan_leb_slab, seb);
1278
1301
list_for_each_entry_safe(seb, seb_tmp, &si->free, u.list) {
1279
1302
list_del(&seb->u.list);
1303
kmem_cache_free(si->scan_leb_slab, seb);
1283
1306
/* Destroy the volume RB-tree */