diff options
author | Huang Shijie <b32955@freescale.com> | 2012-11-01 01:58:17 -0400 |
---|---|---|
committer | Artem Bityutskiy <Artem.Bityutskiy@linux.intel.com> | 2012-11-15 12:50:30 -0500 |
commit | 6f9f59ee2e254a7e997985d8eb708930da49245a (patch) | |
tree | b2fe0de90ac6f12c33c9a281a4102df9afe5f08e /drivers/mtd/cmdlinepart.c | |
parent | 3e9ce49e0ef95e22790a74720f0068696b2477c9 (diff) |
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>
Diffstat (limited to 'drivers/mtd/cmdlinepart.c')
-rw-r--r-- | drivers/mtd/cmdlinepart.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c index 4baab3bc6136..c533f27d863f 100644 --- a/drivers/mtd/cmdlinepart.c +++ b/drivers/mtd/cmdlinepart.c | |||
@@ -56,8 +56,8 @@ | |||
56 | 56 | ||
57 | 57 | ||
58 | /* special size referring to all the remaining space in a partition */ | 58 | /* special size referring to all the remaining space in a partition */ |
59 | #define SIZE_REMAINING UINT_MAX | 59 | #define SIZE_REMAINING ULLONG_MAX |
60 | #define OFFSET_CONTINUOUS UINT_MAX | 60 | #define OFFSET_CONTINUOUS ULLONG_MAX |
61 | 61 | ||
62 | struct cmdline_mtd_partition { | 62 | struct cmdline_mtd_partition { |
63 | struct cmdline_mtd_partition *next; | 63 | struct cmdline_mtd_partition *next; |
@@ -89,7 +89,7 @@ static struct mtd_partition * newpart(char *s, | |||
89 | int extra_mem_size) | 89 | int extra_mem_size) |
90 | { | 90 | { |
91 | struct mtd_partition *parts; | 91 | struct mtd_partition *parts; |
92 | unsigned long size, offset = OFFSET_CONTINUOUS; | 92 | unsigned long long size, offset = OFFSET_CONTINUOUS; |
93 | char *name; | 93 | char *name; |
94 | int name_len; | 94 | int name_len; |
95 | unsigned char *extra_mem; | 95 | unsigned char *extra_mem; |
@@ -104,7 +104,8 @@ static struct mtd_partition * newpart(char *s, | |||
104 | } else { | 104 | } else { |
105 | size = memparse(s, &s); | 105 | size = memparse(s, &s); |
106 | if (size < PAGE_SIZE) { | 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 | return ERR_PTR(-EINVAL); | 109 | return ERR_PTR(-EINVAL); |
109 | } | 110 | } |
110 | } | 111 | } |
@@ -296,7 +297,7 @@ static int parse_cmdline_partitions(struct mtd_info *master, | |||
296 | struct mtd_partition **pparts, | 297 | struct mtd_partition **pparts, |
297 | struct mtd_part_parser_data *data) | 298 | struct mtd_part_parser_data *data) |
298 | { | 299 | { |
299 | unsigned long offset; | 300 | unsigned long long offset; |
300 | int i, err; | 301 | int i, err; |
301 | struct cmdline_mtd_partition *part; | 302 | struct cmdline_mtd_partition *part; |
302 | const char *mtd_id = master->name; | 303 | const char *mtd_id = master->name; |