summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2023-01-28 22:14:35 +0000
committerLeah Rowe <leah@libreboot.org>2023-01-28 22:14:35 +0000
commit257eedca0c729ae7341733306bc87d29b8113c28 (patch)
tree0f34c1bbde02003609a32ffbd62033ebea686c60 /util
parentadc76e38140e29526131d35f2c102009bfafeff8 (diff)
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
Diffstat (limited to 'util')
-rw-r--r--util/nvmutil/nvmutil.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index 6dbe518..c8b866a 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;