Patchwork [1/3] mtd: cmdlinepart: make the partitions rule more strict

login
register
mail settings
Submitter Shmulik Ladkani
Date Sept. 5, 2012, 5:30 a.m.
Message ID <20120905083020.0bf6b0bd@halley>
Download mbox | patch
Permalink /patch/181722/
State New
Headers show

Comments

Shmulik Ladkani - Sept. 5, 2012, 5:30 a.m.
On Wed, 5 Sep 2012 10:12:20 +0800 Huang Shijie <b32955@freescale.com> 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
Artem Bityutskiy - Sept. 22, 2012, 4:01 p.m.
On Wed, 2012-09-05 at 08:30 +0300, Shmulik Ladkani wrote:
> On Wed, 5 Sep 2012 10:12:20 +0800 Huang Shijie <b32955@freescale.com> 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:

OK, pushed this one to l2-mtd.git. Guys, if there are more patches on
top of this, please, re-send them.

Patch

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;
 			}