ret = fdt_property_placeholder(fdt, "data", sbuf.st_size, &ptr);
if (ret)
- return ret;
+ goto err;
ret = read(fd, ptr, sbuf.st_size);
if (ret != sbuf.st_size) {
fprintf(stderr, "%s: Can't read %s: %s\n",
params->cmdname, fname, strerror(errno));
goto err;
}
+ close(fd);
return 0;
err:
if (ret < 0) {
fprintf(stderr, "%s: Failed to build FIT image\n",
params->cmdname);
- goto err;
+ goto err_buf;
}
size = ret;
fd = open(fname, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0666);
if (ret != size) {
fprintf(stderr, "%s: Can't write %s: %s\n",
params->cmdname, fname, strerror(errno));
- close(fd);
goto err;
}
close(fd);
+ free(buf);
return 0;
err:
+ close(fd);
+err_buf:
free(buf);
return -1;
}
buf = malloc(fit_size);
if (!buf) {
ret = -ENOMEM;
- goto err;
+ goto err_munmap;
}
buf_ptr = 0;
if (images < 0) {
debug("%s: Cannot find /images node: %d\n", __func__, images);
ret = -EINVAL;
- goto err;
+ goto err_munmap;
}
for (node = fdt_first_subnode(fdt, images);
ret = fdt_delprop(fdt, node, "data");
if (ret) {
ret = -EPERM;
- goto err;
+ goto err_munmap;
}
fdt_setprop_u32(fdt, node, "data-offset", buf_ptr);
fdt_setprop_u32(fdt, node, "data-size", len);
ret = -EIO;
goto err;
}
- ret = 0;
+ close(fd);
+ return 0;
+err_munmap:
+ munmap(fdt, sbuf.st_size);
err:
+ if (buf)
+ free(buf);
close(fd);
return ret;
}
if (fd < 0) {
fprintf(stderr, "%s: Can't open %s: %s\n",
params->cmdname, fname, strerror(errno));
- ret = -EIO;
- goto err;
+ free(fdt);
+ return -EIO;
}
if (write(fd, fdt, new_size) != new_size) {
debug("%s: Failed to write external data to file %s\n",
ret = 0;
err:
+ free(fdt);
close(fd);
return ret;
}