aboutsummaryrefslogtreecommitdiff
path: root/arch/sandbox/cpu/os.c
diff options
context:
space:
mode:
authorTom Rini2023-11-20 09:19:50 -0500
committerTom Rini2023-11-20 09:19:50 -0500
commitdca7a8958f8d0dbd53072caa4353353e062d80ca (patch)
tree2ba9b27f1799d23f5bd3355feaf6276646297b9d /arch/sandbox/cpu/os.c
parent9e4b42267e1fb5805ecddbb92629f456d8cd4047 (diff)
parent24ca49b33af98d54d6cd2e845f071f6565345ffd (diff)
Merge tag 'v2024.01-rc3' into next
Prepare v2024.01-rc3
Diffstat (limited to 'arch/sandbox/cpu/os.c')
-rw-r--r--arch/sandbox/cpu/os.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 8847c4cd0a8..cbae5109e85 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -219,7 +219,7 @@ int os_map_file(const char *pathname, int os_flags, void **bufp, int *sizep)
{
void *ptr;
off_t size;
- int ifd;
+ int ifd, ret = 0;
ifd = os_open(pathname, os_flags);
if (ifd < 0) {
@@ -229,23 +229,28 @@ int os_map_file(const char *pathname, int os_flags, void **bufp, int *sizep)
size = os_filesize(ifd);
if (size < 0) {
printf("Cannot get file size of '%s'\n", pathname);
- return -EIO;
+ ret = -EIO;
+ goto out;
}
if ((unsigned long long)size > (unsigned long long)SIZE_MAX) {
printf("File '%s' too large to map\n", pathname);
- return -EIO;
+ ret = -EIO;
+ goto out;
}
ptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, ifd, 0);
if (ptr == MAP_FAILED) {
printf("Can't map file '%s': %s\n", pathname, strerror(errno));
- return -EPERM;
+ ret = -EPERM;
+ goto out;
}
*bufp = ptr;
*sizep = size;
- return 0;
+out:
+ os_close(ifd);
+ return ret;
}
int os_unmap(void *buf, int size)