Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7baf0426 authored by Shmulik Ladkani's avatar Shmulik Ladkani Committed by David Woodhouse
Browse files

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: default avatarShmulik Ladkani <shmulik.ladkani@gmail.com>
Signed-off-by: default avatarArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent 2fe87aef
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -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;
			}