write will never return 0 on POSIX conformant systems. Remove this error
path.
Also, close the file on error.

Signed-off-by: Steffen Trumtrar <s.trumt...@pengutronix.de>
---
 scripts/bareboximd.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/scripts/bareboximd.c b/scripts/bareboximd.c
index b332d435a66f..6ba6dabf3a2c 100644
--- a/scripts/bareboximd.c
+++ b/scripts/bareboximd.c
@@ -56,7 +56,7 @@ int imd_command_setenv(const char *variable_name, const char 
*value)
 
 static int write_file(const char *filename, const void *buf, size_t size)
 {
-       int fd, ret;
+       int fd, ret = 0;
        int now;
 
        fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR | 
S_IRGRP | S_IROTH);
@@ -65,22 +65,17 @@ static int write_file(const char *filename, const void 
*buf, size_t size)
 
        while (size) {
                now = write(fd, buf, size);
-               if (now == 0) {
-                       errno = ENOSPC;
-                       return -1;
+               if (now < 0) {
+                       ret = now;
+                       goto out;
                }
-               if (now < 0)
-                       return now;
                size -= now;
                buf += now;
        }
 
+out:
        close(fd);
-
-       if (ret < 0)
-               return ret;
-
-       return 0;
+       return ret;
 }
 
 static int read_file_2(const char *filename, size_t *size, void **outbuf, 
size_t max_size)
-- 
2.26.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

Reply via email to