mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] scripts: bareboximd: fix write_file error handling
@ 2020-05-04  8:35 Steffen Trumtrar
  2020-05-04  8:35 ` [PATCH 2/2] common: imd: handle error in imd_write_crc32 Steffen Trumtrar
  2020-05-05  5:51 ` [PATCH 1/2] scripts: bareboximd: fix write_file error handling Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Steffen Trumtrar @ 2020-05-04  8:35 UTC (permalink / raw)
  To: Barebox List

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.trumtrar@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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-05-05  5:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-04  8:35 [PATCH 1/2] scripts: bareboximd: fix write_file error handling Steffen Trumtrar
2020-05-04  8:35 ` [PATCH 2/2] common: imd: handle error in imd_write_crc32 Steffen Trumtrar
2020-05-05  5:51 ` [PATCH 1/2] scripts: bareboximd: fix write_file error handling Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox