[Skiboot] [PATCH] external/pflash: Fix non-zero return code for successful read when size%256 != 0

Suraj Jitindar Singh sjitindarsingh at gmail.com
Fri Dec 1 13:41:10 AEDT 2017


When performing a read the return value from pflash is non-zero, even for
a successful read, when the size being read is not a multiple of 256.
This is because do_read_file returns the value from the write system
call which is then returned by pflash. When the size is a multiple of
256 we get lucky in that this wraps around back to zero. However for any
other value the return code is size % 256. This means even when the
operation is successful the return code will seem to reflect an error.

Fix this by returning zero if the entire size was read correctly,
otherwise return the corresponding error code.

Fixes: e1cf130d ("external/pflash: Remove use of exit() and fix memory leaks")

Reported-by: Pridhiviraj Paidipeddi <ppaidipe at linux.vnet.ibm.com>
Signed-off-by: Suraj Jitindar Singh <sjitindarsingh at gmail.com>
---
 external/pflash/pflash.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c
index 381df24f..a5e7bc35 100644
--- a/external/pflash/pflash.c
+++ b/external/pflash/pflash.c
@@ -511,7 +511,7 @@ static int do_read_file(struct blocklevel_device *bl, const char *file,
 	}
 	progress_end();
 	close(fd);
-	return rc;
+	return size ? rc : 0;
 }
 
 static int enable_4B_addresses(struct blocklevel_device *bl)
-- 
2.13.6



More information about the Skiboot mailing list