From 1f548604019c1745c2800a6a5e9f64b29700972f Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Thu, 1 Jun 2023 06:58:30 +0100 Subject: [PATCH] util/nvmutil: minor code cleanup Make word() a macro, simplify err_if(). Could also make setWord() a macro if I forego certain optimisations, but I'll leave it as-is. Signed-off-by: Leah Rowe --- util/nvmutil/nvmutil.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index e75ba650..319daf2a 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -52,7 +52,6 @@ void cmd_brick(void); void cmd_swap(void); void cmd_copy(void); int validChecksum(int partnum); -uint16_t word(int pos16, int partnum); void setWord(int pos16, int partnum, uint16_t val16); void byteswap(int n, int partnum); void writeGbeFile(int *fd, const char *filename, size_t nw); @@ -67,6 +66,8 @@ void err_if(int condition); #define SIZE_4KB 0x1000 #define SIZE_8KB 0x2000 +#define word(pos16, partnum) (buf16[pos16 + (partnum << 11)]) + uint16_t buf16[SIZE_4KB]; uint8_t *buf; size_t gbe[2]; @@ -322,12 +323,6 @@ validChecksum(int partnum) return (errno = ECANCELED) & 0; } -uint16_t -word(int pos16, int partnum) -{ - return buf16[pos16 + (partnum << 11)]; -} - void setWord(int pos16, int partnum, uint16_t val16) { @@ -397,9 +392,6 @@ xunveil(const char *path, const char *permissions) void err_if(int condition) { - if (!condition) - return; - if (!errno) - errno = ECANCELED; - err(errno, NULL); + if (condition) + err(errno = errno ? errno : ECANCELED, NULL); }