mtd: cmdlinepart: minor fixes handling zero sized partitions
cover mtd: cmdlinepart: minor fixes handling zero sized partitions
Removing zero sized partitions was introduced in commit 7baf04261062826ea225ab23e07c541e279143fa.
http://permalink.gmane.org/gmane.linux.drivers.mtd/43507
These changes fix a minor error and make the handling more consistent.
Christopher Cordahi (2):
mtd: cmdlinepart: fix skipping zero sized partition
mtd: cmdlinepart: skip partitions truncated to zero
drivers/mtd/cmdlinepart.c | 18 +++++++++--------- 1 files changed, 9 insertions(+), 9 deletions(-)
PATCH 1/2 mtd: cmdlinepart: fix skipping zero sized partition
Decrement index i after skipping a zero sized partition. On next loop iteration, the index will be the same as before, but the data will be new as it was moved when earlier partition was skipped.
--- drivers/mtd/cmdlinepart.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/mtd/cmdlinepart.c +1 -0
@@ -337,6 +337,7 @@ static int parse_cmdline_partitions(struct mtd_info *master, part->num_parts--;memmove (&part->parts[i], &part->parts[i +1 ],sizeof (*part->parts) * (part->num_parts - i)); + i--;continue ; }
Signature · 1 line
1.7.1
Re: [PATCH 1/2] mtd: cmdlinepart: fix skipping zero sized partition
Thanks Chris.
Quoted 5 lines · On Sun, 16 Dec 2012 19:59:29 -0500 Christopher Cordahi…
Decrement index i after skipping a zero sized partition. On next loop iteration, the index will be the same as before, but the data will be new as it was moved when earlier partition was skipped.
Signed-off-by Christopher Cordahi <[email protected]>
PATCH 2/2 mtd: cmdlinepart: skip partitions truncated to zero
In reply to Christopher CordahiPerform flash size truncation before skipping zero sized partition so that if the result is a zero sized, it will be skipped like the others.
--- drivers/mtd/cmdlinepart.c | 17 ++++++++--------- 1 files changed, 8 insertions(+), 9 deletions(-)
drivers/mtd/cmdlinepart.c +8 -9
@@ -330,6 +330,14 @@ static int parse_cmdline_partitions(struct mtd_info *master,if (part->parts[i].size ==SIZE_REMAINING ) part->parts[i].size = master->size - offset; +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; + } + offset += part->parts[i].size; +if (part->parts[i].size ==0 ) { printk(KERN_WARNING ERRP "%s: skipping zero sized partition\n",
@@ -338,16 +346,7 @@ static int parse_cmdline_partitions(struct mtd_info *master,memmove (&part->parts[i], &part->parts[i +1 ],sizeof (*part->parts) * (part->num_parts - i)); 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; - } - offset += part->parts[i].size; } *pparts = kmemdup(part->parts, sizeof(*part->parts) * part->num_parts,
Signature · 1 line
1.7.1
Re: [PATCH 2/2] mtd: cmdlinepart: skip partitions truncated to zero
Thanks Chris,
Quoted 5 lines · On Sun, 16 Dec 2012 19:59:30 -0500 Christopher Cordahi…
Perform flash size truncation before skipping zero sized partition so that if the result is a zero sized, it will be skipped like the others.
Signed-off-by Christopher Cordahi <[email protected]>
Quoted 16 lines
drivers/mtd/cmdlinepart.c +8
-0@@ -330,6 +330,14 @@ static int parse_cmdline_partitions(struct mtd_info *master,if (part->parts[i].size ==SIZE_REMAINING ) part->parts[i].size = master->size - offset; +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; + } + offset += part->parts[i].size; +if (part->parts[i].size ==0 ) { printk(KERN_WARNING ERRP "%s: skipping zero sized partition\n",
drivers/mtd/cmdlinepart.c static int parse_cmdline_partitions(struct mtd_info *master, · line 349
Quoted 5 lines
drivers/mtd/cmdlinepart.c +0
-1@@ -338,16 +346,7 @@ static int parse_cmdline_partitions(struct mtd_info *master,memmove (&part->parts[i], &part->parts[i +1 ],sizeof (*part->parts) * (part->num_parts - i)); i--; -continue ; }
Taking another look (this relates to your prev patch as well), maybe it would be cleaner to avoid the "i--" by converting this 'for' loop to a 'while' loop, executing the "i++" at the end of the loop, keeping the explicit 'continue' in the 'size == 0' case.
Regards,
Shmulik
Quoted 4 lines · Christopher Cordahi
Removing zero sized partitions was introduced in commit
7baf04261062826ea225ab23e07c541e279143fa.
http://permalink.gmane.org/gmane.linux.drivers.mtd/43507
These changes fix a minor error and make the handling more consistent.
Pushed both to l2-mtd.git, thanks!
Signature · 2 lines
Best Regards, Artem Bityutskiy