X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=tools%2Ffdtgrep.c;h=67aa41a24de3a2da474331d64989ccba6109f8a4;hb=5038d3e5f23ad979c05fa339284576ccb7e90c07;hp=caaf6006a5dd24c96cd6a969d8fda1b1fa2e2554;hpb=1043d0a0296a8580fd497a2eb1f411eb07ba98c1;p=u-boot diff --git a/tools/fdtgrep.c b/tools/fdtgrep.c index caaf6006a5..67aa41a24d 100644 --- a/tools/fdtgrep.c +++ b/tools/fdtgrep.c @@ -667,28 +667,16 @@ static int fdtgrep_find_regions(const void *fdt, new_count = fdt_add_alias_regions(fdt, region, count, max_regions, &state); - if (new_count > max_regions) { - region = malloc(new_count * sizeof(struct fdt_region)); - if (!region) { - fprintf(stderr, - "Out of memory for %d regions\n", - count); - return -1; - } - memcpy(region, state.region, - count * sizeof(struct fdt_region)); - free(state.region); - new_count = fdt_add_alias_regions(fdt, region, count, - max_regions, &state); + if (new_count <= max_regions) { + /* + * The alias regions will now be at the end of the list. + * Sort the regions by offset to get things into the + * right order + */ + count = new_count; + qsort(region, count, sizeof(struct fdt_region), + h_cmp_region); } - - /* - * The alias regions will now be at the end of the list. Sort - * the regions by offset to get things into the right order - */ - qsort(region, new_count, sizeof(struct fdt_region), - h_cmp_region); - count = new_count; } if (ret != -FDT_ERR_NOTFOUND) @@ -805,7 +793,7 @@ static int do_fdtgrep(struct display_info *disp, const char *filename) * The first pass will count the regions, but if it is too many, * we do another pass to actually record them. */ - for (i = 0; i < 2; i++) { + for (i = 0; i < 3; i++) { region = malloc(count * sizeof(struct fdt_region)); if (!region) { fprintf(stderr, "Out of memory for %d regions\n",