mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] mtd: cmdlinepart: fix the overflow of big mtd partitions
@ 2012-11-01  5:58 Huang Shijie
  2012-11-15 13:45 ` Artem Bityutskiy
  0 siblings, 1 reply; 2+ messages in thread
From: Huang Shijie @ 2012-11-01  5:58 UTC (permalink / raw)
  To: dwmw2; +Cc: dedekind1, linux-mtd, linux-kernel, Huang Shijie

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>
---
 drivers/mtd/cmdlinepart.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c
index 4baab3b..1cfd741 100644
--- a/drivers/mtd/cmdlinepart.c
+++ b/drivers/mtd/cmdlinepart.c
@@ -56,8 +56,8 @@
 
 
 /* special size referring to all the remaining space in a partition */
-#define SIZE_REMAINING UINT_MAX
-#define OFFSET_CONTINUOUS UINT_MAX
+#define SIZE_REMAINING ULLONG_MAX
+#define OFFSET_CONTINUOUS ULLONG_MAX
 
 struct cmdline_mtd_partition {
 	struct cmdline_mtd_partition *next;
@@ -89,7 +89,7 @@ static struct mtd_partition * newpart(char *s,
 				      int extra_mem_size)
 {
 	struct mtd_partition *parts;
-	unsigned long size, offset = OFFSET_CONTINUOUS;
+	unsigned long long size, offset = OFFSET_CONTINUOUS;
 	char *name;
 	int name_len;
 	unsigned char *extra_mem;
@@ -104,7 +104,7 @@ static struct mtd_partition * newpart(char *s,
 	} else {
 		size = memparse(s, &s);
 		if (size < PAGE_SIZE) {
-			printk(KERN_ERR ERRP "partition size too small (%lx)\n", size);
+			printk(KERN_ERR ERRP "partition size too small (%llx)\n", size);
 			return ERR_PTR(-EINVAL);
 		}
 	}
@@ -296,7 +296,7 @@ static int parse_cmdline_partitions(struct mtd_info *master,
 				    struct mtd_partition **pparts,
 				    struct mtd_part_parser_data *data)
 {
-	unsigned long offset;
+	unsigned long long offset;
 	int i, err;
 	struct cmdline_mtd_partition *part;
 	const char *mtd_id = master->name;
-- 
1.7.0.4



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] mtd: cmdlinepart: fix the overflow of big mtd partitions
  2012-11-01  5:58 [PATCH] mtd: cmdlinepart: fix the overflow of big mtd partitions Huang Shijie
@ 2012-11-15 13:45 ` Artem Bityutskiy
  0 siblings, 0 replies; 2+ messages in thread
From: Artem Bityutskiy @ 2012-11-15 13:45 UTC (permalink / raw)
  To: Huang Shijie; +Cc: dwmw2, linux-mtd, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 971 bytes --]

On Thu, 2012-11-01 at 13:58 +0800, Huang Shijie wrote:
> 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>

Pushed to l2-mtd.git, thanks!

-- 
Best Regards,
Artem Bityutskiy

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-11-15 13:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-01  5:58 [PATCH] mtd: cmdlinepart: fix the overflow of big mtd partitions Huang Shijie
2012-11-15 13:45 ` Artem Bityutskiy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome