From 257eedca0c729ae7341733306bc87d29b8113c28 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sat, 28 Jan 2023 22:14:35 +0000 Subject: util/nvmutil: reset errno if any write attempted the way nvmutil is designed, setWord() is only ever called under non-error conditions. however, if one part is valid but the other one isn't, and a command is run that touches both parts, errno is non-zero write writeGbeFile is called in situations where one part is valid, but the other isn't, AND the writes to gbe (in memory) results in a non-change, writeGbeFile is not called; in this situation, errno is not being reset, despite non-error condition this patch fixed the bug, resulting in zero status upon exit under such conditions --- util/nvmutil/nvmutil.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'util/nvmutil') diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 6dbe5186..c8b866a9 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -61,7 +61,7 @@ uint8_t buf[SIZE_8KB]; size_t gbe[2] = {(size_t) buf, ((size_t) buf) + SIZE_4KB}; uint8_t skipread[2] = {0, 0}; -int part, gbeFileModified = 0; +int part, gbeWriteAttempted = 0, gbeFileModified = 0; uint8_t nvmPartModified[2] = {0, 0}; uint16_t test; @@ -127,10 +127,13 @@ main(int argc, char *argv[]) else if (cmd != NULL) (*cmd)(); - if (gbeFileModified) + if (gbeFileModified) { writeGbeFile(&fd, FILENAME); - else if ((cmd != &cmd_dump)) + } else if ((cmd != &cmd_dump)) { printf("File `%s` not modified.\n", FILENAME); + if (gbeWriteAttempted) + errno = 0; + } nvmutil_exit: if ((errno != 0) && (cmd != &cmd_dump)) @@ -408,6 +411,7 @@ word(int pos16, int partnum) void setWord(int pos16, int partnum, uint16_t val16) { + gbeWriteAttempted = 1; if (word(pos16, partnum) == val16) return; -- cgit v1.2.1