]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
sandbox: don't call os_close with invalid file descriptor
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Wed, 10 Apr 2024 21:50:34 +0000 (23:50 +0200)
committerTom Rini <trini@konsulko.com>
Wed, 17 Apr 2024 23:06:16 +0000 (17:06 -0600)
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>
arch/sandbox/cpu/os.c

index cbae5109e8575ddf49883b0e0c0a545d7dfa489d..154a5d77490c3132be9f1df4a722d132f203d020 100644 (file)
@@ -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) {