Commit 7baf04261062826ea225ab23e07c541e279143fa

Authored by Shmulik Ladkani
Committed by David Woodhouse
1 parent 2fe87aef33

mtd: cmdlinepart: make the partitions rule more strict

Huang Shijie <shijie8@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@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@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>

Showing 1 changed file with 11 additions and 1 deletions Side-by-side Diff

drivers/mtd/cmdlinepart.c
... ... @@ -319,12 +319,22 @@
319 319 if (part->parts[i].size == SIZE_REMAINING)
320 320 part->parts[i].size = master->size - offset;
321 321  
  322 + if (part->parts[i].size == 0) {
  323 + printk(KERN_WARNING ERRP
  324 + "%s: skipping zero sized partition\n",
  325 + part->mtd_id);
  326 + part->num_parts--;
  327 + memmove(&part->parts[i],
  328 + &part->parts[i + 1],
  329 + sizeof(*part->parts) * (part->num_parts - i));
  330 + continue;
  331 + }
  332 +
322 333 if (offset + part->parts[i].size > master->size) {
323 334 printk(KERN_WARNING ERRP
324 335 "%s: partitioning exceeds flash size, truncating\n",
325 336 part->mtd_id);
326 337 part->parts[i].size = master->size - offset;
327   - part->num_parts = i;
328 338 }
329 339 offset += part->parts[i].size;
330 340 }