1 --- a/drivers/mtd/ubi/attach.c
2 +++ b/drivers/mtd/ubi/attach.c
3 @@ -803,6 +803,13 @@ out_unlock:
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 @@ -833,9 +840,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 + ubi_msg("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 @@ -702,6 +702,7 @@ struct ubi_attach_info {
49 struct kmem_cache *aeb_slab_cache;