diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-05-26 21:41:02 +0100 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-05-26 21:46:07 +0100 |
| commit | 049ee793dbbe5c528077402f8ba9cd01b90b6669 (patch) | |
| tree | 1373a0be5b53cd6f60af910793f226e7641d8abe /util | |
| parent | bc4bc4b67eb8601e48e43b36ad4d57393d2cc382 (diff) | |
maximum safety.
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util')
| -rw-r--r-- | util/nvmutil/nvmutil.c | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 5d174040..8cab66ac 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -77,26 +77,41 @@ op_t op[] = { }; void (*cmd)(void) = NULL; -#define err_if(x) if (x) err(EXIT_FAILURE, "%s", filename) +#define err_if(x) \ + do { \ + if (x) { \ + err(EXIT_FAILURE, "%s", filename); \ + } \ + } while(0) #define xopen(f,l,p) \ do { \ - if ((f = open_on_eintr(l, p)) == -1) \ - err(EXIT_FAILURE, "%s", l); \ - if (fstat(f, &st) == -1) \ - err(EXIT_FAILURE, "%s", l); \ + if ((f = open_on_eintr(l, p)) == -1) { \ + err(EXIT_FAILURE, "%s", l); \ + } \ + if (fstat(f, &st) == -1) { \ + err(EXIT_FAILURE, "%s", l); \ + } \ } while(0) -#define word(pos16, partnum) ((uint16_t *) gbe[partnum])[pos16] -#define setWord(pos16, p, val16) if (word(pos16, p) != val16) \ - nvmPartChanged[p] = 1 | (word(pos16, p) = val16) +#define word(pos16, partnum) \ + (((uint16_t *) gbe[partnum])[pos16]) + +#define setWord(pos16, p, val16) \ + do { \ + if (word(pos16, p) != val16) { \ + nvmPartChanged[p] = 1 | (word(pos16, p) = val16); \ + } \ + } while(0) -#define SUCCESS(x) ((x) >= 0) +#define SUCCESS(x) \ + ((x) >= 0) #define reset_caller_errno(return_value) \ do { \ - if (SUCCESS(return_value) && (!errno)) \ - errno = saved_errno; \ + if (SUCCESS(return_value) && (!errno)) { \ + errno = saved_errno; \ + } \ } while (0) int @@ -726,21 +741,24 @@ if_err_sys(int condition) #define fs_err_retry() \ do { \ if ((rval == -1) && \ - (errno == EINTR)) \ + (errno == EINTR)) { \ return 1; \ - if (rval >= 0 && !errno) \ + } \ + if (rval >= 0 && !errno) { \ errno = saved_errno; \ - return 0; \ + } \ } while(0) int fs_retry(int saved_errno, int rval) { fs_err_retry(); + return 0; } int rw_retry(int saved_errno, ssize_t rval) { fs_err_retry(); + return 0; } |
