diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-14 23:35:24 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-14 23:35:24 +0000 |
| commit | 23e7170897c2f812b565fe0415f52184ca26ed7b (patch) | |
| tree | 4737e5d0c6ef15db5046412a36adcdf33ed98730 /util/nvmutil/nvmutil.c | |
| parent | 67a7f16ba268eafba3ec5ad8dda0340509d6fd94 (diff) | |
util/nvmutil: re-add io_args()
unified arg check for prw and rw_file_exact
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/nvmutil/nvmutil.c')
| -rw-r--r-- | util/nvmutil/nvmutil.c | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 98f5bdcd..9659c5c2 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -416,6 +416,8 @@ static ssize_t rw_file_exact(int fd, u8 *mem, size_t len, static ssize_t prw(int fd, void *mem, size_t nrw, off_t off, int rw_type, int loop_eagain, int loop_eintr, int off_reset); +static int io_args(int fd, void *mem, size_t nrw, + off_t off, int rw_type); static int check_file(int fd, struct stat *st); static ssize_t rw_over_nrw(ssize_t r, size_t nrw); #if !defined(HAVE_REAL_PREAD_PWRITE) || \ @@ -1888,15 +1890,8 @@ rw_file_exact(int fd, u8 *mem, size_t nrw, size_t nrw_cur; void *mem_cur; - if (mem == NULL) - goto err_rw_file_exact; - - if (fd < 0 - || off < 0 - || !nrw /* prevent zero read request */ - || nrw > (size_t)SSIZE_MAX /* prevent overflow */ - || (uint)rw_type > IO_PWRITE) - goto err_rw_file_exact; + if (io_args(fd, mem, nrw, off, rw_type) == -1) + return -1; while (1) { @@ -1997,15 +1992,8 @@ prw(int fd, void *mem, size_t nrw, off_t off_last; #endif - if (mem == NULL) - goto err_prw; - - if (fd < 0 - || off < 0 - || !nrw /* prevent zero read request */ - || nrw > (size_t)SSIZE_MAX /* prevent overflow */ - || (uint)rw_type > IO_PWRITE) - goto err_prw; + if (io_args(fd, mem, nrw, off, rw_type) == -1) + return -1; r = -1; @@ -2135,6 +2123,27 @@ err_prw: } static int +io_args(int fd, void *mem, size_t nrw, + off_t off, int rw_type) +{ + if (mem == NULL) + goto err_io_args; + + if (fd < 0 + || off < 0 + || !nrw /* prevent zero read request */ + || nrw > (size_t)SSIZE_MAX /* prevent overflow */ + || (uint)rw_type > IO_PWRITE) + goto err_io_args; + + return 0; + +err_io_args: + errno = EIO; + return -1; +} + +static int check_file(int fd, struct stat *st) { if (fstat(fd, st) == -1) |
