diff options
author | Richard Yao <[email protected]> | 2022-09-23 19:52:03 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2022-09-23 16:52:03 -0700 |
commit | 2a493a4c7127258b14c39e8c71a9d6f01167c5cd (patch) | |
tree | 3fcf8e9b9a84ec0dac5ae3e306524f6c02fcce7e /tests/zfs-tests/cmd | |
parent | d25153d55568afc92a7b3ec8329d7fbad7382a80 (diff) |
Fix unchecked return values and unused return values
Coverity complained about unchecked return values and unused values that
turned out to be unused return values.
Different approaches were used to handle the different cases of
unchecked return values:
* cmd/zdb/zdb.c: VERIFY0 was used in one place since the existing code
had no error handling. An error message was printed in another to
match the rest of the code.
* cmd/zed/agents/zfs_retire.c: We dismiss the return value with `(void)`
because the value is expected to be potentially unset.
* cmd/zpool_influxdb/zpool_influxdb.c: We dismiss the return value with
`(void)` because the values are expected to be potentially unset.
* cmd/ztest.c: VERIFY0 was used since we want failures if something goes
wrong in ztest.
* module/zfs/dsl_dir.c: We dismiss the return value with `(void)`
because there is no guarantee that the zap entry will always be there.
For example, old pools imported readonly would not have it and we do
not want to fail here because of that.
* module/zfs/zfs_fm.c: `fnvlist_add_*()` was used since the
allocations sleep and thus can never fail.
* module/zfs/zvol.c: We dismiss the return value with `(void)` because
we do not need it. This matches what is already done in the analogous
`zfs_replay_write2()`.
* tests/zfs-tests/cmd/draid.c: We suppress one return value with
`(void)` since the code handles errors already. The other return value
is handled by switching to `fnvlist_lookup_uint8_array()`.
* tests/zfs-tests/cmd/file/file_fadvise.c: We add error handling.
* tests/zfs-tests/cmd/mmap_sync.c: We add error handling for munmap, but
ignore failures on remove() with (void) since it is expected to be
able to fail.
* tests/zfs-tests/cmd/mmapwrite.c: We add error handling.
As for unused return values, they were all in places where there was
error handling, so logic was added to handle the return values.
Reviewed-by: Alexander Motin <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Richard Yao <[email protected]>
Closes #13920
Diffstat (limited to 'tests/zfs-tests/cmd')
-rw-r--r-- | tests/zfs-tests/cmd/draid.c | 4 | ||||
-rw-r--r-- | tests/zfs-tests/cmd/file/file_fadvise.c | 6 | ||||
-rw-r--r-- | tests/zfs-tests/cmd/mmap_sync.c | 5 | ||||
-rw-r--r-- | tests/zfs-tests/cmd/mmapwrite.c | 6 |
4 files changed, 15 insertions, 6 deletions
diff --git a/tests/zfs-tests/cmd/draid.c b/tests/zfs-tests/cmd/draid.c index b995be46a..831039288 100644 --- a/tests/zfs-tests/cmd/draid.c +++ b/tests/zfs-tests/cmd/draid.c @@ -139,7 +139,7 @@ read_map_key(const char *filename, const char *key, nvlist_t **cfg) if (error != 0) return (error); - nvlist_lookup_nvlist(allcfgs, key, &foundcfg); + (void) nvlist_lookup_nvlist(allcfgs, key, &foundcfg); if (foundcfg != NULL) { nvlist_dup(foundcfg, cfg, KM_SLEEP); error = 0; @@ -375,7 +375,7 @@ dump_map_nv(const char *key, nvlist_t *cfg, int verbose) map.dm_checksum = fnvlist_lookup_uint64(cfg, MAP_CHECKSUM); map.dm_children = fnvlist_lookup_uint64(cfg, MAP_CHILDREN); map.dm_nperms = fnvlist_lookup_uint64(cfg, MAP_NPERMS); - nvlist_lookup_uint8_array(cfg, MAP_PERMS, &map.dm_perms, &c); + map.dm_perms = fnvlist_lookup_uint8_array(cfg, MAP_PERMS, &c); dump_map(&map, key, (double)worst_ratio / 1000.0, avg_ratio / 1000.0, verbose); diff --git a/tests/zfs-tests/cmd/file/file_fadvise.c b/tests/zfs-tests/cmd/file/file_fadvise.c index e1afb6d0a..d64e2dea3 100644 --- a/tests/zfs-tests/cmd/file/file_fadvise.c +++ b/tests/zfs-tests/cmd/file/file_fadvise.c @@ -89,7 +89,11 @@ main(int argc, char *argv[]) return (1); } - posix_fadvise(fd, 0, 0, advise); + if (posix_fadvise(fd, 0, 0, advise) != 0) { + perror("posix_fadvise"); + close(fd); + return (1); + } close(fd); diff --git a/tests/zfs-tests/cmd/mmap_sync.c b/tests/zfs-tests/cmd/mmap_sync.c index 0e4bba37d..618f1284a 100644 --- a/tests/zfs-tests/cmd/mmap_sync.c +++ b/tests/zfs-tests/cmd/mmap_sync.c @@ -32,7 +32,7 @@ static void cleanup(char *file) { - remove(file); + (void) remove(file); } int @@ -125,7 +125,8 @@ main(int argc, char *argv[]) elapsed += ((t2.tv_usec - t1.tv_usec) / 1000.0); if (elapsed > max_msync_time_ms) { fprintf(stderr, "slow msync: %f ms\n", elapsed); - munmap(ptr, LEN); + if (munmap(ptr, LEN) != 0) + perror("munmap"); cleanup(file); return (1); } diff --git a/tests/zfs-tests/cmd/mmapwrite.c b/tests/zfs-tests/cmd/mmapwrite.c index 0d277d6e3..8534db339 100644 --- a/tests/zfs-tests/cmd/mmapwrite.c +++ b/tests/zfs-tests/cmd/mmapwrite.c @@ -73,7 +73,11 @@ normal_writer(void *filename) err(1, "write failed!"); break; } - lseek(fd, page_size, SEEK_CUR); + if (lseek(fd, page_size, SEEK_CUR) == -1) { + err(1, "lseek failed on %s: %s", file_path, + strerror(errno)); + break; + } } } |