1 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
2 Subject: [PATCH] mtd: bcm47xxpart: check for bad blocks when calculating offsets
4 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
7 --- a/drivers/mtd/parsers/parser_trx.c
8 +++ b/drivers/mtd/parsers/parser_trx.c
9 @@ -25,6 +25,33 @@ struct trx_header {
14 + * Calculate real end offset (address) for a given amount of data. It checks
15 + * all blocks skipping bad ones.
17 +static size_t parser_trx_real_offset(struct mtd_info *mtd, size_t bytes)
19 + size_t real_offset = 0;
21 + if (mtd_block_isbad(mtd, real_offset))
22 + pr_warn("Base offset shouldn't be at bad block");
24 + while (bytes >= mtd->erasesize) {
25 + bytes -= mtd->erasesize;
26 + real_offset += mtd->erasesize;
27 + while (mtd_block_isbad(mtd, real_offset)) {
28 + real_offset += mtd->erasesize;
30 + if (real_offset >= mtd->size)
31 + return real_offset - mtd->erasesize;
35 + real_offset += bytes;
40 static const char *parser_trx_data_part_name(struct mtd_info *master,
43 @@ -79,21 +106,21 @@ static int parser_trx_parse(struct mtd_i
45 part = &parts[curr_part++];
46 part->name = "loader";
47 - part->offset = trx.offset[i];
48 + part->offset = parser_trx_real_offset(mtd, trx.offset[i]);
53 part = &parts[curr_part++];
55 - part->offset = trx.offset[i];
56 + part->offset = parser_trx_real_offset(mtd, trx.offset[i]);
61 part = &parts[curr_part++];
62 - part->name = parser_trx_data_part_name(mtd, trx.offset[i]);
63 - part->offset = trx.offset[i];
64 + part->offset = parser_trx_real_offset(mtd, trx.offset[i]);
65 + part->name = parser_trx_data_part_name(mtd, part->offset);