From 2d129c257ccba03229048131a8617e216ecdebdb Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Fri, 13 Mar 2026 14:41:36 +0000 Subject: util/nvmutil: tidy up prw() Signed-off-by: Leah Rowe --- util/nvmutil/nvmutil.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'util/nvmutil/nvmutil.c') diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index b659f254..667726ab 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -1663,20 +1663,22 @@ prw(int fd, void *mem, size_t nrw, || (unsigned int)prw_type > IO_WRITE) goto err_prw; + flags = fcntl(fd, F_GETFL); + if (flags == -1) + return -1; + /* * O_APPEND must not be used, because this * allows POSIX write() to ignore the * current write offset and write at EOF, * which would therefore break pread/pwrite */ - flags = fcntl(fd, F_GETFL); - if (flags == -1) - return -1; if (flags & O_APPEND) goto err_prw; if ((off_orig = lseek_eintr(fd, (off_t)0, SEEK_CUR)) == (off_t)-1) return -1; + if (lseek_eintr(fd, off, SEEK_SET) == (off_t)-1) return -1; @@ -1688,6 +1690,7 @@ prw(int fd, void *mem, size_t nrw, if (lseek_eintr(fd, off_orig, SEEK_SET) == (off_t)-1) { if (r < 0) errno = saved_errno; + return -1; } errno = saved_errno; -- cgit v1.2.1