diff mbox series

[1/1] sandbox: don't call os_close with invalid file descriptor

Message ID 20240410215034.18806-1-heinrich.schuchardt@canonical.com
State Accepted
Commit 2c3fa4b8add3cb6a440184ab67debc6867d383c0
Delegated to: Tom Rini
Headers show
Series [1/1] sandbox: don't call os_close with invalid file descriptor | expand

Commit Message

Heinrich Schuchardt April 10, 2024, 9:50 p.m. UTC
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>
---
 arch/sandbox/cpu/os.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Sean Anderson April 11, 2024, 2:40 a.m. UTC | #1
On 4/10/24 17:50, Heinrich Schuchardt wrote:
> 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>
> ---
>   arch/sandbox/cpu/os.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
> index cbae5109e85..154a5d77490 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) {

Fixes: 566bf3a8698 ("sandbox: Add a function to read a host file")
Reviewed-by: Sean Anderson <seanga2@gmail.com>
Tom Rini April 18, 2024, 3:40 a.m. UTC | #2
On Wed, 10 Apr 2024 23:50:34 +0200, Heinrich Schuchardt wrote:

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

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index cbae5109e85..154a5d77490 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) {