1 --- a/drivers/mtd/ubi/attach.c
2 +++ b/drivers/mtd/ubi/attach.c
3 @@ -939,6 +939,13 @@ static bool vol_ignored(int vol_id)
7 +static bool ec_hdr_has_eof(struct ubi_ec_hdr *ech)
9 + return ech->padding1[0] == 'E' &&
10 + ech->padding1[1] == 'O' &&
11 + ech->padding1[2] == 'F';
15 * scan_peb - scan and process UBI headers of a PEB.
16 * @ubi: UBI device description object
17 @@ -971,9 +978,21 @@ static int scan_peb(struct ubi_device *u
21 - err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
24 + if (!ai->eof_found) {
25 + err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
29 + if (ec_hdr_has_eof(ech)) {
30 + pr_notice("UBI: EOF marker found, PEBs from %d will be erased",
32 + ai->eof_found = true;
37 + err = UBI_IO_FF_BITFLIPS;
42 --- a/drivers/mtd/ubi/ubi.h
43 +++ b/drivers/mtd/ubi/ubi.h
44 @@ -779,6 +779,7 @@ struct ubi_attach_info {
49 struct kmem_cache *aeb_slab_cache;
50 struct ubi_ec_hdr *ech;
51 struct ubi_vid_io_buf *vidb;