summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2015-10-17 19:41:16 -0600
committerMichal Simek <michal.simek@xilinx.com>2015-11-04 14:49:51 +0100
commitf403914dfc0e08f6dd2284429097faa27d29c1ac (patch)
treeb72284cfaecbd735f6f97da0b2a516689a11c33a /tools
parent9d8ac956af304072dd11054e2b981ac3770ca49b (diff)
downloadu-boot-f403914dfc0e08f6dd2284429097faa27d29c1ac.tar.gz
u-boot-f403914dfc0e08f6dd2284429097faa27d29c1ac.tar.bz2
u-boot-f403914dfc0e08f6dd2284429097faa27d29c1ac.zip
fdtgrep: Simplify the alias generation code
We don't need to allocate a new region list when we run out of space. The outer function can take care of this for us. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/fdtgrep.c32
1 files changed, 10 insertions, 22 deletions
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",