From: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Date: Wed, 10 Apr 2024 21:50:34 +0000 (+0200)
Subject: sandbox: don't call os_close with invalid file descriptor
X-Git-Tag: v2025.01-rc5-pxa1908~536
X-Git-Url: http://git.dujemihanovic.xyz/img/html/static/login.html?a=commitdiff_plain;h=2c3fa4b8add3cb6a440184ab67debc6867d383c0;p=u-boot.git

sandbox: don't call os_close with invalid file descriptor

If open() fails it returns -1. Calling close() with this value
makes no sense. Return -EIO instead.

Addresses-Coverity-ID: 185828 Improper use of negative value
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Fixes: 566bf3a8698 ("sandbox: Add a function to read a host file")
Reviewed-by: Sean Anderson <seanga2@gmail.com>
---

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index cbae5109e8..154a5d7749 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -188,7 +188,7 @@ int os_read_file(const char *fname, void **bufp, int *sizep)
 	fd = os_open(fname, OS_O_RDONLY);
 	if (fd < 0) {
 		printf("Cannot open file '%s'\n", fname);
-		goto err;
+		return -EIO;
 	}
 	size = os_filesize(fd);
 	if (size < 0) {