mtd: cmdlinepart: make the partitions rule more strict
Linux-MTD Mailing List
linux-mtd at lists.infradead.org
Sat Sep 29 10:59:48 EDT 2012
Gitweb: http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=7baf04261062826ea225ab23e07c541e279143fa
Commit: 7baf04261062826ea225ab23e07c541e279143fa
Parent: 2fe87aef33b77d66fada83f5dc57b6798ad5df07
Author: Shmulik Ladkani <shmulik.ladkani at gmail.com>
AuthorDate: Wed Sep 5 08:30:20 2012 +0300
Committer: David Woodhouse <David.Woodhouse at intel.com>
CommitDate: Sat Sep 29 15:44:25 2012 +0100
mtd: cmdlinepart: make the partitions rule more strict
Huang Shijie <shijie8 at gmail.com> explains:
Assume we have a 1GiB(8Gib) NAND chip, and we set the partitions
in the command line like this:
#gpmi-nand:100m(boot),100m(kernel),1g(rootfs)
In this case, the partition truncating occurs. The current code will
get the following result:
----------------------------------
root at freescale ~$ cat /proc/mtd
dev: size erasesize name
mtd0: 06400000 00040000 "boot"
mtd1: 06400000 00040000 "kernel"
----------------------------------
It is obvious that we lost the truncated partition `rootfs` which should
be 824MiB in this case.
Also, forbid 0-sized partitions.
Signed-off-by: Shmulik Ladkani <shmulik.ladkani at gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy at linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse at intel.com>
---
drivers/mtd/cmdlinepart.c | 12 +++++++++++-
1 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c
index 17b0bd4..aed1b8a 100644
--- a/drivers/mtd/cmdlinepart.c
+++ b/drivers/mtd/cmdlinepart.c
@@ -319,12 +319,22 @@ static int parse_cmdline_partitions(struct mtd_info *master,
if (part->parts[i].size == SIZE_REMAINING)
part->parts[i].size = master->size - offset;
+ if (part->parts[i].size == 0) {
+ printk(KERN_WARNING ERRP
+ "%s: skipping zero sized partition\n",
+ part->mtd_id);
+ part->num_parts--;
+ memmove(&part->parts[i],
+ &part->parts[i + 1],
+ sizeof(*part->parts) * (part->num_parts - i));
+ continue;
+ }
+
if (offset + part->parts[i].size > master->size) {
printk(KERN_WARNING ERRP
"%s: partitioning exceeds flash size, truncating\n",
part->mtd_id);
part->parts[i].size = master->size - offset;
- part->num_parts = i;
}
offset += part->parts[i].size;
}
More information about the linux-mtd-cvs
mailing list