Skip to content

Commit 6f9f59e

Browse files
Huang Shijiededekind
authored andcommitted
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>
1 parent 3e9ce49 commit 6f9f59e

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

‎drivers/mtd/cmdlinepart.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656

5757

5858
/* 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
6161

6262
struct cmdline_mtd_partition {
6363
struct cmdline_mtd_partition *next;
@@ -89,7 +89,7 @@ static struct mtd_partition * newpart(char *s,
8989
int extra_mem_size)
9090
{
9191
struct mtd_partition *parts;
92-
unsigned long size, offset = OFFSET_CONTINUOUS;
92+
unsigned long long size, offset = OFFSET_CONTINUOUS;
9393
char *name;
9494
int name_len;
9595
unsigned char *extra_mem;
@@ -104,7 +104,8 @@ static struct mtd_partition * newpart(char *s,
104104
} else {
105105
size = memparse(s, &s);
106106
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);
108109
return ERR_PTR(-EINVAL);
109110
}
110111
}
@@ -296,7 +297,7 @@ static int parse_cmdline_partitions(struct mtd_info *master,
296297
struct mtd_partition **pparts,
297298
struct mtd_part_parser_data *data)
298299
{
299-
unsigned long offset;
300+
unsigned long long offset;
300301
int i, err;
301302
struct cmdline_mtd_partition *part;
302303
const char *mtd_id = master->name;

0 commit comments

Comments
 (0)