summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-07 10:07:05 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-07 10:07:05 +0000
commitc195e8cc2b8b9d9d47a11677e682ef0edee4adb3 (patch)
treebf86a6d1c09a0b30ad8a115f3abdbac6396e6bd7 /util
parent6a505c9162cd31d398db0f58dfc63c195b2c158c (diff)
util/nvmutil: tidy up open_dev_urandom
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util')
-rw-r--r--util/nvmutil/nvmutil.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index 69a392fd..b6e28cfa 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -357,21 +357,24 @@ open_dev_urandom(void)
{
struct stat st_urandom_fd;
+ /*
+ * Try /dev/urandom first
+ */
rname = newrandom;
+ if ((urandom_fd = open(rname, O_RDONLY)) != -1)
+ return;
- if ((urandom_fd = open(rname, O_RDONLY)) == -1) {
- /*
- * Fall back to /dev/random on old platforms
- * where /dev/urandom does not exist.
- *
- * We must reset the error condition first,
- * to prevent stale error status later.
- */
- errno = 0;
+ /*
+ * Fall back to /dev/random on old platforms
+ * where /dev/urandom does not exist.
+ *
+ * We must reset the error condition first,
+ * to prevent stale error status later.
+ */
+ errno = 0;
- rname = oldrandom;
- xopen(&urandom_fd, rname, O_RDONLY, &st_urandom_fd);
- }
+ rname = oldrandom;
+ xopen(&urandom_fd, rname, O_RDONLY, &st_urandom_fd);
}
#endif