From ff88cb1ac37eed20e7c9bcf9c36fc17947274abb Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sun, 27 Nov 2022 00:48:37 +0000 Subject: util/nvmutil: further improved errno handling --- util/nvmutil/nvmutil.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'util/nvmutil') diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 5ec28949..5081a3e2 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -109,20 +109,19 @@ main(int argc, char *argv[]) cmd = &cmd_copy; } - if (errno != 0) - goto nvmutil_exit; - - if (readFromFile(&fd, gbe, FILENAME, flags, SIZE_8KB) != SIZE_8KB) + if ((strMac == NULL) && (cmd == NULL)) + errno = EINVAL; + else if (readFromFile(&fd, gbe, FILENAME, flags, SIZE_8KB) != SIZE_8KB) goto nvmutil_exit; else if (errno == ENOTDIR) errno = 0; - if (strMac != NULL) + if (errno != 0) + goto nvmutil_exit; + else if (strMac != NULL) setmac(strMac); else if (cmd != NULL) (*cmd)(); - else - errno = EINVAL; if (gbeFileModified) writeGbeFile(&fd, FILENAME); -- cgit v1.2.1