[Skiboot] [PATCH] pflash: Respect write(2) return values
Cyril Bur
cyril.bur at au1.ibm.com
Fri Dec 1 14:50:23 AEDT 2017
The write(2) system call returns the number of bytes written, this is
important since it is entitled to write less than what we requested.
Currently we ignore the return value and assume it wrote everything we
requested. While in practice this is likely to always be the case, it
isn't actually correct.
This patch addresses this.
Signed-off-by: Cyril Bur <cyril.bur at au1.ibm.com>
---
external/pflash/pflash.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c
index 381df24f..048dba3b 100644
--- a/external/pflash/pflash.c
+++ b/external/pflash/pflash.c
@@ -500,13 +500,18 @@ static int do_read_file(struct blocklevel_device *bl, const char *file,
break;
}
rc = write(fd, file_buf, len);
- if (rc < 0) {
+ /*
+ * zero isn't strictly an error.
+ * Treat it as such so we can be sure we'lre always
+ * making forward progress.
+ */
+ if (rc <= 0) {
perror("Error writing file");
break;
}
- start += len;
- size -= len;
- done += len;
+ start += rc;
+ size -= rc;
+ done += rc;
progress_tick(done >> 8);
}
progress_end();
--
2.15.1
More information about the Skiboot
mailing list