提交 438db5a9 编写于 作者: S Shmulik Ladkani 提交者: Artem Bityutskiy

mtd: cmdlinepart: Simplify parse_cmdline_partitions

Simply 'parse_cmdline_partitions': the outer loop iterating over
'partitions' is actually a search loop, it does not execute the inner
loop for each partition, only for the matched partition.

Let's break when search is successful, and move all inner code (relevant
only for the matched partition) outside of the outer loop.

Resulting code is much more readable, and makes the indent level sane.
Signed-off-by: NShmulik Ladkani <shmulik.ladkani@gmail.com>
Signed-off-by: NArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
上级 6924d99f
...@@ -308,48 +308,52 @@ static int parse_cmdline_partitions(struct mtd_info *master, ...@@ -308,48 +308,52 @@ static int parse_cmdline_partitions(struct mtd_info *master,
return err; return err;
} }
/*
* Search for the partition definition matching master->name.
* If master->name is not set, stop at first partition definition.
*/
for (part = partitions; part; part = part->next) { for (part = partitions; part; part = part->next) {
if ((!mtd_id) || (!strcmp(part->mtd_id, mtd_id))) { if ((!mtd_id) || (!strcmp(part->mtd_id, mtd_id)))
for (i = 0, offset = 0; i < part->num_parts; i++) { break;
if (part->parts[i].offset == OFFSET_CONTINUOUS) }
part->parts[i].offset = offset;
else if (!part)
offset = part->parts[i].offset; return 0;
if (part->parts[i].size == SIZE_REMAINING) for (i = 0, offset = 0; i < part->num_parts; i++) {
part->parts[i].size = master->size - offset; if (part->parts[i].offset == OFFSET_CONTINUOUS)
part->parts[i].offset = offset;
if (part->parts[i].size == 0) { else
printk(KERN_WARNING ERRP offset = part->parts[i].offset;
"%s: skipping zero sized partition\n",
part->mtd_id); if (part->parts[i].size == SIZE_REMAINING)
part->num_parts--; part->parts[i].size = master->size - offset;
memmove(&part->parts[i],
&part->parts[i + 1], if (part->parts[i].size == 0) {
sizeof(*part->parts) * (part->num_parts - i)); printk(KERN_WARNING ERRP
continue; "%s: skipping zero sized partition\n",
} part->mtd_id);
part->num_parts--;
if (offset + part->parts[i].size > master->size) { memmove(&part->parts[i], &part->parts[i + 1],
printk(KERN_WARNING ERRP sizeof(*part->parts) * (part->num_parts - i));
"%s: partitioning exceeds flash size, truncating\n", continue;
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,
GFP_KERNEL);
if (!*pparts)
return -ENOMEM;
return part->num_parts;
} }
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;
} }
return 0; *pparts = kmemdup(part->parts, sizeof(*part->parts) * part->num_parts,
GFP_KERNEL);
if (!*pparts)
return -ENOMEM;
return part->num_parts;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册