tools: mkimage: use /* fallthrough */ as needed
[oweals/u-boot.git] / tools / fit_image.c
index f32ee49575b0a82d3bcf01cc8d86b56db0c959a2..88ff093d05bed6f5da152dbbad8428eec219e4d7 100644 (file)
@@ -17,6 +17,7 @@
 #include "fit_common.h"
 #include "mkimage.h"
 #include <image.h>
+#include <string.h>
 #include <stdarg.h>
 #include <version.h>
 #include <u-boot/crc.h>
@@ -534,8 +535,7 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname)
 err_munmap:
        munmap(fdt, sbuf.st_size);
 err:
-       if (buf)
-               free(buf);
+       free(buf);
        close(fd);
        return ret;
 }
@@ -563,21 +563,21 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
                fprintf(stderr, "%s: Failed to allocate memory (%d bytes)\n",
                        __func__, size);
                ret = -ENOMEM;
-               goto err_has_fd;
+               goto err_munmap;
        }
        ret = fdt_open_into(old_fdt, fdt, size);
        if (ret) {
                debug("%s: Failed to expand FIT: %s\n", __func__,
                      fdt_strerror(errno));
                ret = -EINVAL;
-               goto err_has_fd;
+               goto err_munmap;
        }
 
        images = fdt_path_offset(fdt, FIT_IMAGES_PATH);
        if (images < 0) {
                debug("%s: Cannot find /images node: %d\n", __func__, images);
                ret = -EINVAL;
-               goto err_has_fd;
+               goto err_munmap;
        }
 
        for (node = fdt_first_subnode(fdt, images);
@@ -598,10 +598,12 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
                        debug("%s: Failed to write property: %s\n", __func__,
                              fdt_strerror(ret));
                        ret = -EINVAL;
-                       goto err_has_fd;
+                       goto err_munmap;
                }
        }
 
+       munmap(old_fdt, sbuf.st_size);
+
        /* Close the old fd so we can re-use it. */
        close(fd);
 
@@ -616,22 +618,24 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
                fprintf(stderr, "%s: Can't open %s: %s\n",
                        params->cmdname, fname, strerror(errno));
                ret = -EIO;
-               goto err_no_fd;
+               goto err;
        }
        if (write(fd, fdt, new_size) != new_size) {
                debug("%s: Failed to write external data to file %s\n",
                      __func__, strerror(errno));
                ret = -EIO;
-               goto err_has_fd;
+               goto err;
        }
 
-       ret = 0;
-
-err_has_fd:
+       free(fdt);
        close(fd);
-err_no_fd:
+       return 0;
+
+err_munmap:
        munmap(old_fdt, sbuf.st_size);
+err:
        free(fdt);
+       close(fd);
        return ret;
 }
 
@@ -741,6 +745,9 @@ static int fit_handle_file(struct image_tool_params *params)
                snprintf(cmd, sizeof(cmd), "cp \"%s\" \"%s\"",
                         params->imagefile, tmpfile);
        }
+       if (strlen(cmd) >= MKIMAGE_MAX_DTC_CMDLINE_LEN - 1) {
+               fprintf(stderr, "WARNING: command-line for FIT creation might be truncated and will probably fail.\n");
+       }
 
        if (*cmd && system(cmd) == -1) {
                fprintf (stderr, "%s: system(%s) failed: %s\n",