Skip to contentSkip to conversation

mtd: cmdlinepart: minor fixes handling zero sized partitions

PATCH In review Christopher Cordahi 3 participants 6 messages Dec 17, 2012 – Jan 15, 2013 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

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(-)
#1 lore raw

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
index c533f27..c1efb4c 100644
@@ -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
#3 lore raw

PATCH 2/2 mtd: cmdlinepart: skip partitions truncated to zero

In reply to 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.

---
 drivers/mtd/cmdlinepart.c |   17 ++++++++---------
 1 files changed, 8 insertions(+), 9 deletions(-)
drivers/mtd/cmdlinepart.c +8 -9
index c1efb4c..525c579 100644
@@ -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
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] mtd: cmdlinepart: fix skipping zero sized partition

In reply to Christopher Cordahi

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.

Acked-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] mtd: cmdlinepart: skip partitions truncated to zero

In reply to Christopher Cordahi

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.

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