summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2023-01-27 19:52:11 +0000
committerLeah Rowe <leah@libreboot.org>2023-01-27 19:52:11 +0000
commitb1186968e83d4b21875d9949b28a2d3e7b281b64 (patch)
treec8c5cec953a71ced275b5cedf3467ec13f1a678e /util
parent7a98649764347a1485a1bf819db71cc3560244e1 (diff)
util/nvmutil: code cleanup
Diffstat (limited to 'util')
-rw-r--r--util/nvmutil/nvmutil.c28
1 files changed, 9 insertions, 19 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index d68585a5..c8bd829f 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -62,7 +62,7 @@ size_t gbe[2];
uint8_t skipread[2] = {0, 0};
int part, gbeFileModified = 0;
-uint8_t nvmPartModified[2];
+uint8_t nvmPartModified[2] = {0, 0};
uint16_t test;
uint8_t little_endian;
@@ -70,11 +70,9 @@ uint8_t little_endian;
int
main(int argc, char *argv[])
{
- int fd;
size_t nr = 128;
- int flags = O_RDWR;
- char *strMac = NULL;
- char *strRMac = "??:??:??:??:??:??";
+ int fd, flags = O_RDWR;
+ char *strMac = NULL, *strRMac = "??:??:??:??:??:??";
void (*cmd)(void) = NULL;
#ifdef HAVE_PLEDGE
@@ -84,11 +82,7 @@ main(int argc, char *argv[])
if ((buf = (uint8_t *) malloc(SIZE_8KB)) == NULL)
err(errno, NULL);
- gbe[0] = gbe[1] = (size_t) buf;
- gbe[1] += SIZE_4KB;
-
- nvmPartModified[0] = 0;
- nvmPartModified[1] = 0;
+ gbe[1] = (gbe[0] = (size_t) buf) + SIZE_4KB;
test = 1;
little_endian = ((uint8_t *) &test)[0];
@@ -141,19 +135,17 @@ main(int argc, char *argv[])
writeGbeFile(&fd, FILENAME);
nvmutil_exit:
- if (!((errno == ECANCELED) && (flags == O_RDONLY)))
- if (errno != 0)
- err(errno, NULL);
-
- return errno;
+ if ((errno != 0) && (cmd != &cmd_dump))
+ err(errno, NULL);
+ else
+ return errno;
}
void
readGbeFile(int *fd, const char *path, int flags, size_t nr)
{
struct stat st;
- int r, tr = 0;
- int p;
+ int p, r, tr = 0;
if (opendir(path) != NULL)
err(errno = EISDIR, path);
@@ -463,8 +455,6 @@ writeGbeFile(int *fd, const char *filename)
}
if (close((*fd)))
err(errno, "%s", filename);
- if (errno != 0)
- err(errno, "%s", filename);
printf("%d bytes written to file: `%s`\n", tw, filename);
}