aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/cmdlinepart.c
diff options
context:
space:
mode:
authorShmulik Ladkani <shmulik.ladkani@gmail.com>2012-09-23 03:52:29 -0400
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>2012-11-15 08:37:45 -0500
commit438db5a92b7526a12591f764042528a86d2ebb4b (patch)
tree22dfe6e013b16e8d732e6663faf7514d8377a295 /drivers/mtd/cmdlinepart.c
parent6924d99fcdf1a688538a3cdebd1f135c22eec191 (diff)
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: Shmulik Ladkani <shmulik.ladkani@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Diffstat (limited to 'drivers/mtd/cmdlinepart.c')
-rw-r--r--drivers/mtd/cmdlinepart.c80
1 files changed, 42 insertions, 38 deletions
diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c
index aed1b8a63c9f..4baab3bc6136 100644
--- a/drivers/mtd/cmdlinepart.c
+++ b/drivers/mtd/cmdlinepart.c
@@ -308,48 +308,52 @@ static int parse_cmdline_partitions(struct mtd_info *master,
308 return err; 308 return err;
309 } 309 }
310 310
311 /*
312 * Search for the partition definition matching master->name.
313 * If master->name is not set, stop at first partition definition.
314 */
311 for (part = partitions; part; part = part->next) { 315 for (part = partitions; part; part = part->next) {
312 if ((!mtd_id) || (!strcmp(part->mtd_id, mtd_id))) { 316 if ((!mtd_id) || (!strcmp(part->mtd_id, mtd_id)))
313 for (i = 0, offset = 0; i < part->num_parts; i++) { 317 break;
314 if (part->parts[i].offset == OFFSET_CONTINUOUS) 318 }
315 part->parts[i].offset = offset; 319
316 else 320 if (!part)
317 offset = part->parts[i].offset; 321 return 0;
318 322
319 if (part->parts[i].size == SIZE_REMAINING) 323 for (i = 0, offset = 0; i < part->num_parts; i++) {
320 part->parts[i].size = master->size - offset; 324 if (part->parts[i].offset == OFFSET_CONTINUOUS)
321 325 part->parts[i].offset = offset;
322 if (part->parts[i].size == 0) { 326 else
323 printk(KERN_WARNING ERRP 327 offset = part->parts[i].offset;
324 "%s: skipping zero sized partition\n", 328
325 part->mtd_id); 329 if (part->parts[i].size == SIZE_REMAINING)
326 part->num_parts--; 330 part->parts[i].size = master->size - offset;
327 memmove(&part->parts[i], 331
328 &part->parts[i + 1], 332 if (part->parts[i].size == 0) {
329 sizeof(*part->parts) * (part->num_parts - i)); 333 printk(KERN_WARNING ERRP
330 continue; 334 "%s: skipping zero sized partition\n",
331 } 335 part->mtd_id);
332 336 part->num_parts--;
333 if (offset + part->parts[i].size > master->size) { 337 memmove(&part->parts[i], &part->parts[i + 1],
334 printk(KERN_WARNING ERRP 338 sizeof(*part->parts) * (part->num_parts - i));
335 "%s: partitioning exceeds flash size, truncating\n", 339 continue;
336 part->mtd_id);
337 part->parts[i].size = master->size - offset;
338 }
339 offset += part->parts[i].size;
340 }
341
342 *pparts = kmemdup(part->parts,
343 sizeof(*part->parts) * part->num_parts,
344 GFP_KERNEL);
345 if (!*pparts)
346 return -ENOMEM;
347
348 return part->num_parts;
349 } 340 }
341
342 if (offset + part->parts[i].size > master->size) {
343 printk(KERN_WARNING ERRP
344 "%s: partitioning exceeds flash size, truncating\n",
345 part->mtd_id);
346 part->parts[i].size = master->size - offset;
347 }
348 offset += part->parts[i].size;
350 } 349 }
351 350
352 return 0; 351 *pparts = kmemdup(part->parts, sizeof(*part->parts) * part->num_parts,
352 GFP_KERNEL);
353 if (!*pparts)
354 return -ENOMEM;
355
356 return part->num_parts;
353} 357}
354 358
355 359