[U-Boot] [PATCH v4 4/4] mtdparts: new add.spread: add part skipping bad blocks

Scott Wood
2010-08-26T22:26:14Z

On Mon, Aug 09, 2010 at 04:44:00PM -0400, Ben Gardiner wrote:
> +#if defined(CONFIG_CMD_MTDPARTS_SPREAD)
> + s = strchr(argv[1], '.');
> +
> + if (get_mtd_info(dev->id->type, dev->id->num, &mtd))
> + return 1;
> +#endif
> +
> if ((dev_tmp = device_find(dev->id->type, dev->id->num)) == NULL) {
> +#if defined(CONFIG_CMD_MTDPARTS_SPREAD)
> + if (s && !strcmp(s, ".spread")) {

No need for the strchr, just do "if (!strcmp(&argv[1][3], ".spread"))".

> + p = list_entry(dev->parts.next,
> + struct part_info, link);
> + spread_partition(mtd, p, &next_offset);
> +
> + debug("increased %s to %d bytes\n", p->name,
> + p->size);
> + }
> +#endif
> device_add(dev);
> } else {
> /* merge new partition with existing ones*/
> p = list_entry(dev->parts.next, struct part_info, link);
> +#if defined(CONFIG_CMD_MTDPARTS_SPREAD)
> + if (s && !strcmp(s, ".spread")) {
> + spread_partition(mtd, p, &next_offset);
> +
> + debug("increased %s to %d bytes\n", p->name,
> + p->size);
> + }
> +#endif

Don't duplicate this on both sides of the "if"; instead do something like:

p = list_entry(dev->parts.next...);

if (!strcmp(&argv[1][3], ".spread"))
spread_partition(mtd, p, &next_offset);

if ((dev_tmp = ...) {
device_add(dev);
} else if (part_add(dev_tmp, p)) {
device_del(dev);
return 1;
}

-Scott