aboutsummaryrefslogtreecommitdiff
path: root/tools/sfspl.c
diff options
context:
space:
mode:
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>2023-10-24 09:26:38 +0200
committerTom Rini <trini@konsulko.com>2023-10-30 15:32:49 -0400
commit54024c8021ab9ca50927e2c08df1bc95dd63d3f1 (patch)
treebec686ba8c04a15084dfe3365c4a066cac928393 /tools/sfspl.c
parent482a0f17649f4fbae0f1aa02582cd27a955bf612 (diff)
downloadu-boot-54024c8021ab9ca50927e2c08df1bc95dd63d3f1.zip
u-boot-54024c8021ab9ca50927e2c08df1bc95dd63d3f1.tar.gz
u-boot-54024c8021ab9ca50927e2c08df1bc95dd63d3f1.tar.bz2
tools: mkimage: fix sfspl_image_extract_subimage()
Do not leak file descriptor if writing fails. Correct the error text if opening a file fails. Addresses-Coverity-ID: 467054 Resource leaks Fixes: 64fd30d367a1 ("tools: mkimage: Add StarFive SPL image support") Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/sfspl.c')
-rw-r--r--tools/sfspl.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/tools/sfspl.c b/tools/sfspl.c
index ec18a0a..c76420c 100644
--- a/tools/sfspl.c
+++ b/tools/sfspl.c
@@ -99,7 +99,7 @@ static int sfspl_image_extract_subimage(void *ptr,
{
struct spl_hdr *hdr = (void *)ptr;
unsigned char *buf = ptr;
- int fd;
+ int fd, ret = EXIT_SUCCESS;
unsigned int hdr_size = le32_to_cpu(hdr->hdr_size);
unsigned int file_size = le32_to_cpu(hdr->file_size);
@@ -110,16 +110,16 @@ static int sfspl_image_extract_subimage(void *ptr,
fd = open(params->outfile, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd == -1) {
- perror("Can write file");
+ perror("Cannot open file");
return EXIT_FAILURE;
}
if (write(fd, &buf[hdr_size], file_size) != file_size) {
perror("Cannot write file");
- return EXIT_FAILURE;
+ ret = EXIT_FAILURE;
}
close(fd);
- return EXIT_SUCCESS;
+ return ret;
}
static int sfspl_check_image_type(uint8_t type)