From: Bin Meng <bmeng.cn@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH 2/3] mkimage: fit: Unmmap the memory before closing fd in fit_import_data()
Date: Sat, 18 Apr 2020 01:59:10 -0700 [thread overview]
Message-ID: <1587200351-12590-2-git-send-email-bmeng.cn@gmail.com> (raw)
In-Reply-To: <1587200351-12590-1-git-send-email-bmeng.cn@gmail.com>
From: Lihua Zhao <lihua.zhao@windriver.com>
Without calling munmap(), the follow-up call to open() the same file
with a flag O_TRUNC seems not to cause any issue on Linux, but it fails
on Windows with error like below:
Can't open kernel_fdt.itb.tmp: Permission denied
Fix this by unmapping the memory before closing fd in fit_import_data().
Signed-off-by: Lihua Zhao <lihua.zhao@windriver.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---
tools/fit_image.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/tools/fit_image.c b/tools/fit_image.c
index dd61a81..05c1f00 100644
--- a/tools/fit_image.c
+++ b/tools/fit_image.c
@@ -556,21 +556,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);
@@ -591,10 +591,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);
@@ -609,22 +611,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;
}
--
2.7.4
next prev parent reply other threads:[~2020-04-18 8:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-18 8:59 [PATCH 1/3] tools: Remove the out-of-date MinGW support codes Bin Meng
2020-04-18 8:59 ` Bin Meng [this message]
2020-04-24 17:12 ` [PATCH 2/3] mkimage: fit: Unmmap the memory before closing fd in fit_import_data() Tom Rini
2020-04-18 8:59 ` [PATCH 3/3] mkimage: fit: Free buf directly in fit_extract_data() Bin Meng
2020-04-24 17:13 ` Tom Rini
2020-04-24 17:12 ` [PATCH 1/3] tools: Remove the out-of-date MinGW support codes Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1587200351-12590-2-git-send-email-bmeng.cn@gmail.com \
--to=bmeng.cn@gmail.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox