summaryrefslogtreecommitdiff
path: root/tools/fit_image.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2017-10-07 11:27:59 -0400
committerTom Rini <trini@konsulko.com>2017-10-07 11:27:59 -0400
commitbf52fcdef4aac242b5e6b6b9827acf6d69ce1951 (patch)
treececa9d544b473499e659bd04c77432dac29df0ae /tools/fit_image.c
parent83e92f79d3abe520f30bbd958c2b5068c049caf0 (diff)
downloadu-boot-bf52fcdef4aac242b5e6b6b9827acf6d69ce1951.tar.gz
u-boot-bf52fcdef4aac242b5e6b6b9827acf6d69ce1951.tar.bz2
u-boot-bf52fcdef4aac242b5e6b6b9827acf6d69ce1951.zip
cmd/gpt.c, cmd/nvedit.c, tools/fit_image.c: Rework recent fixes for Coverity
The recent changes to these files did not completely fix the previous issues, or introduced different (minor) issues. In cmd/gpt.c we need to dereference str_disk_guid to be sure that malloc worked. In cmd/nvedit.c we need to be careful that we can also fit in that leading space when adding to the string. And in tools/fit_image.c we need to re-work the error handling slightly in fit_import_data() so that we only call munmap() once. We have two error paths here, one where we have an fd to close and one where we do not. Adjust labels to match this. Reported-by: Coverity (CID: 167366, 167367, 167370) Signed-off-by: Tom Rini <trini@konsulko.com>
Diffstat (limited to 'tools/fit_image.c')
-rw-r--r--tools/fit_image.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/tools/fit_image.c b/tools/fit_image.c
index c6026567f3..30257b178e 100644
--- a/tools/fit_image.c
+++ b/tools/fit_image.c
@@ -537,21 +537,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;
+ goto err_has_fd;
}
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;
+ goto err_has_fd;
}
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;
+ goto err_has_fd;
}
for (node = fdt_first_subnode(fdt, images);
@@ -572,11 +572,11 @@ 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;
+ goto err_has_fd;
}
}
- munmap(old_fdt, sbuf.st_size);
+ /* Close the old fd so we can re-use it. */
close(fd);
/* Pack the FDT and place the data after it */
@@ -589,22 +589,23 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
if (fd < 0) {
fprintf(stderr, "%s: Can't open %s: %s\n",
params->cmdname, fname, strerror(errno));
- free(fdt);
- return -EIO;
+ ret = -EIO;
+ goto err_no_fd;
}
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;
+ goto err_has_fd;
}
ret = 0;
-err:
+err_has_fd:
+ close(fd);
+err_no_fd:
munmap(old_fdt, sbuf.st_size);
free(fdt);
- close(fd);
return ret;
}