1 --- a/drivers/mtd/bcm47xxpart.c
2 +++ b/drivers/mtd/bcm47xxpart.c
4 /* 10 parts were found on sflash on Netgear WNDR4500 */
5 #define BCM47XXPART_MAX_PARTS 12
8 + * Amount of bytes we read when analyzing each block of flash memory.
9 + * Set it big enough to allow detecting partition and reading important data.
11 +#define BCM47XXPART_BYTES_TO_READ 0x404
14 #define BOARD_DATA_MAGIC 0x5246504D /* MPFR */
15 #define POT_MAGIC1 0x54544f50 /* POTT */
16 @@ -57,17 +63,14 @@ static int bcm47xxpart_parse(struct mtd_
17 struct trx_header *trx;
19 int last_trx_part = -1;
20 - int max_bytes_to_read = 0x8004;
22 if (blocksize <= 0x10000)
24 - if (blocksize == 0x20000)
25 - max_bytes_to_read = 0x18004;
28 parts = kzalloc(sizeof(struct mtd_partition) * BCM47XXPART_MAX_PARTS,
30 - buf = kzalloc(max_bytes_to_read, GFP_KERNEL);
31 + buf = kzalloc(BCM47XXPART_BYTES_TO_READ, GFP_KERNEL);
33 /* Parse block by block looking for magics */
34 for (offset = 0; offset <= master->size - blocksize;
35 @@ -82,7 +85,7 @@ static int bcm47xxpart_parse(struct mtd_
38 /* Read beginning of the block */
39 - if (mtd_read(master, offset, max_bytes_to_read,
40 + if (mtd_read(master, offset, BCM47XXPART_BYTES_TO_READ,
41 &bytes_read, (uint8_t *)buf) < 0) {
42 pr_err("mtd_read error while parsing (offset: 0x%X)!\n",
44 @@ -97,16 +100,9 @@ static int bcm47xxpart_parse(struct mtd_
48 - if (buf[0x000 / 4] == NVRAM_HEADER ||
49 - buf[0x1000 / 4] == NVRAM_HEADER ||
50 - buf[0x8000 / 4] == NVRAM_HEADER ||
51 - (blocksize == 0x20000 && (
52 - buf[0x10000 / 4] == NVRAM_HEADER ||
53 - buf[0x11000 / 4] == NVRAM_HEADER ||
54 - buf[0x18000 / 4] == NVRAM_HEADER))) {
55 + if (buf[0x000 / 4] == NVRAM_HEADER) {
56 bcm47xxpart_add_part(&parts[curr_part++], "nvram",
58 - offset = rounddown(offset, blocksize);