Skip to content

Commit 3c441ba

Browse files
committed
[MTD] Skip bad blocks when checking for RedBoot partition table
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
1 parent 9c37f33 commit 3c441ba

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

‎drivers/mtd/redboot.c‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,31 @@ static int parse_redboot_partitions(struct mtd_info *master,
5959
static char nullstring[] = "unallocated";
6060
#endif
6161

62+
if ( directory < 0 ) {
63+
offset = master->size + directory * master->erasesize;
64+
while (master->block_isbad &&
65+
master->block_isbad(master, offset)) {
66+
if (!offset) {
67+
nogood:
68+
printk(KERN_NOTICE "Failed to find a non-bad block to check for RedBoot partition table\n");
69+
return -EIO;
70+
}
71+
offset -= master->erasesize;
72+
}
73+
} else {
74+
offset = directory * master->erasesize;
75+
while (master->block_isbad &&
76+
master->block_isbad(master, offset)) {
77+
offset += master->erasesize;
78+
if (offset == master->size)
79+
goto nogood;
80+
}
81+
}
6282
buf = vmalloc(master->erasesize);
6383

6484
if (!buf)
6585
return -ENOMEM;
6686

67-
if ( directory < 0 )
68-
offset = master->size + directory*master->erasesize;
69-
else
70-
offset = directory*master->erasesize;
71-
7287
printk(KERN_NOTICE "Searching for RedBoot partition table in %s at offset 0x%lx\n",
7388
master->name, offset);
7489

0 commit comments

Comments
 (0)