From patchwork Wed Sep 5 05:30:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1/3] mtd: cmdlinepart: make the partitions rule more strict X-Patchwork-Submitter: Shmulik Ladkani X-Patchwork-Id: 181722 Message-Id: <20120905083020.0bf6b0bd@halley> To: Huang Shijie Cc: Huang Shijie , linux-mtd@lists.infradead.org, dedekind1@gmail.com Date: Wed, 5 Sep 2012 08:30:20 +0300 From: Shmulik Ladkani List-Id: Linux MTD discussion mailing list On Wed, 5 Sep 2012 10:12:20 +0800 Huang Shijie wrote: > yes, it's really simple and flexible. > But I think it's not wise to export the 0-size partition to user. > The user may confused at this. > > And the mtd-utils, such as mtd-info/mtd-debug, do they can work with a > 0-size partition? I think the 0 sized partition case is really seldom, don't worth the trouble, the user will probably observe something went wrong in his cmdline parts specification. But nevertheless, if we think it's a MUST to forbid the 0 sized partitions, then amend my patch as follows: (sorry, didn't even compile tested this, please review and test, if the approach is acceptible) Also, I'll send a short coding cleanup patch, this loop's indent level is horrible... Regards, Shmulik 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; }