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
fsdg20230625
Leah Rowe 2023-01-28 22:14:35 +00:00
parent adc76e3814
commit 257eedca0c
1 changed files with 7 additions and 3 deletions

View File

@ -61,7 +61,7 @@ uint8_t buf[SIZE_8KB];
size_t gbe[2] = {(size_t) buf, ((size_t) buf) + SIZE_4KB}; size_t gbe[2] = {(size_t) buf, ((size_t) buf) + SIZE_4KB};
uint8_t skipread[2] = {0, 0}; uint8_t skipread[2] = {0, 0};
int part, gbeFileModified = 0; int part, gbeWriteAttempted = 0, gbeFileModified = 0;
uint8_t nvmPartModified[2] = {0, 0}; uint8_t nvmPartModified[2] = {0, 0};
uint16_t test; uint16_t test;
@ -127,10 +127,13 @@ main(int argc, char *argv[])
else if (cmd != NULL) else if (cmd != NULL)
(*cmd)(); (*cmd)();
if (gbeFileModified) if (gbeFileModified) {
writeGbeFile(&fd, FILENAME); writeGbeFile(&fd, FILENAME);
else if ((cmd != &cmd_dump)) } else if ((cmd != &cmd_dump)) {
printf("File `%s` not modified.\n", FILENAME); printf("File `%s` not modified.\n", FILENAME);
if (gbeWriteAttempted)
errno = 0;
}
nvmutil_exit: nvmutil_exit:
if ((errno != 0) && (cmd != &cmd_dump)) if ((errno != 0) && (cmd != &cmd_dump))
@ -408,6 +411,7 @@ word(int pos16, int partnum)
void void
setWord(int pos16, int partnum, uint16_t val16) setWord(int pos16, int partnum, uint16_t val16)
{ {
gbeWriteAttempted = 1;
if (word(pos16, partnum) == val16) if (word(pos16, partnum) == val16)
return; return;