The 'fdt' variable is not unmapped in all error cases. Fix this.
Reported-by: Coverity (CID: 138493)
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
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:
close(fd);
return ret;