Commit 6f9f59ee2e254a7e997985d8eb708930da49245a
Committed by
Artem Bityutskiy
1 parent
3e9ce49e0e
Exists in
master
and in
20 other branches
mtd: cmdlinepart: fix the overflow of big mtd partitions
When the kernel parses the following cmdline #mtdparts=gpmi-nand:16m(boot),16m(kernel),1g(home),4g(test),-(usr) for a big nand chip Micron MT29F64G08AFAAAWP(8GB), we got the following wrong result: ............................................. "mtd: partition size too small (0)" ............................................. We can not get any partition. The "4g(test)" partition triggers a overflow of the "size". The memparse() returns 4g to the "size", but the size is "unsigned long" type, so a overflow occurs, the "size" becomes zero in the end. This patch changes the "size"/"offset" to "unsigned long long" type, and replaces the UINT_MAX with ULLONG_MAX for macros SIZE_REMAINING and OFFSET_CONTINUOUS. Signed-off-by: Huang Shijie <b32955@freescale.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Showing 1 changed file with 6 additions and 5 deletions Side-by-side Diff
drivers/mtd/cmdlinepart.c
... | ... | @@ -56,8 +56,8 @@ |
56 | 56 | |
57 | 57 | |
58 | 58 | /* special size referring to all the remaining space in a partition */ |
59 | -#define SIZE_REMAINING UINT_MAX | |
60 | -#define OFFSET_CONTINUOUS UINT_MAX | |
59 | +#define SIZE_REMAINING ULLONG_MAX | |
60 | +#define OFFSET_CONTINUOUS ULLONG_MAX | |
61 | 61 | |
62 | 62 | struct cmdline_mtd_partition { |
63 | 63 | struct cmdline_mtd_partition *next; |
... | ... | @@ -89,7 +89,7 @@ |
89 | 89 | int extra_mem_size) |
90 | 90 | { |
91 | 91 | struct mtd_partition *parts; |
92 | - unsigned long size, offset = OFFSET_CONTINUOUS; | |
92 | + unsigned long long size, offset = OFFSET_CONTINUOUS; | |
93 | 93 | char *name; |
94 | 94 | int name_len; |
95 | 95 | unsigned char *extra_mem; |
... | ... | @@ -104,7 +104,8 @@ |
104 | 104 | } else { |
105 | 105 | size = memparse(s, &s); |
106 | 106 | if (size < PAGE_SIZE) { |
107 | - printk(KERN_ERR ERRP "partition size too small (%lx)\n", size); | |
107 | + printk(KERN_ERR ERRP "partition size too small (%llx)\n", | |
108 | + size); | |
108 | 109 | return ERR_PTR(-EINVAL); |
109 | 110 | } |
110 | 111 | } |
... | ... | @@ -296,7 +297,7 @@ |
296 | 297 | struct mtd_partition **pparts, |
297 | 298 | struct mtd_part_parser_data *data) |
298 | 299 | { |
299 | - unsigned long offset; | |
300 | + unsigned long long offset; | |
300 | 301 | int i, err; |
301 | 302 | struct cmdline_mtd_partition *part; |
302 | 303 | const char *mtd_id = master->name; |