configs: MPC8548CDS: enable DM_I2C
[oweals/u-boot.git] / tools / fdtgrep.c
index 8f44f599c1c437525b9bfe9cb405ce6e9838a257..7e168a1e6befd11bb981d09de7dfcef6d2147d50 100644 (file)
@@ -17,6 +17,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <fdt_region.h>
 
 #include "fdt_host.h"
 #include "libfdt_internal.h"
@@ -805,7 +806,7 @@ static int do_fdtgrep(struct display_info *disp, const char *filename)
         * we do another pass to actually record them.
         */
        for (i = 0; i < 2; i++) {
-               region = malloc(count * sizeof(struct fdt_region));
+               region = realloc(region, count * sizeof(struct fdt_region));
                if (!region) {
                        fprintf(stderr, "Out of memory for %d regions\n",
                                count);
@@ -823,8 +824,10 @@ static int do_fdtgrep(struct display_info *disp, const char *filename)
                }
                if (count <= max_regions)
                        break;
+       }
+       if (count > max_regions) {
                free(region);
-               fprintf(stderr, "Internal error with fdtgrep_find_region)(\n");
+               fprintf(stderr, "Internal error with fdtgrep_find_region()\n");
                return -1;
        }