Skip to content

Commit 3e5e433

Browse files
ubi: fastmap: Detect EBA mismatches on-the-fly
Now we have the machinery to detect EBA mismatches on-the-fly by comparing the in-memory volume ID and LEB number with the found VID header. This helps to detect malfunction of Fastmap. Signed-off-by: Richard Weinberger <[email protected]>
1 parent 34653fd commit 3e5e433

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

drivers/mtd/ubi/eba.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ static int check_mapping(struct ubi_device *ubi, struct ubi_volume *vol, int lnu
513513
{
514514
int err;
515515
struct ubi_vid_io_buf *vidb;
516+
struct ubi_vid_hdr *vid_hdr;
516517

517518
if (!ubi->fast_attach)
518519
return 0;
@@ -552,6 +553,22 @@ static int check_mapping(struct ubi_device *ubi, struct ubi_volume *vol, int lnu
552553
*pnum, err);
553554

554555
goto out_free;
556+
} else {
557+
int found_vol_id, found_lnum;
558+
559+
ubi_assert(err == 0 || err == UBI_IO_BITFLIPS);
560+
561+
vid_hdr = ubi_get_vid_hdr(vidb);
562+
found_vol_id = be32_to_cpu(vid_hdr->vol_id);
563+
found_lnum = be32_to_cpu(vid_hdr->lnum);
564+
565+
if (found_lnum != lnum || found_vol_id != vol->vol_id) {
566+
ubi_err(ubi, "EBA mismatch! PEB %i is LEB %i:%i instead of LEB %i:%i",
567+
*pnum, found_vol_id, found_lnum, vol->vol_id, lnum);
568+
ubi_ro_mode(ubi);
569+
err = -EINVAL;
570+
goto out_free;
571+
}
555572
}
556573

557574
set_bit(lnum, vol->checkmap);

0 commit comments

Comments
 (0)