From 8ef15f9322dd4314ae26abf4e1290844850ff155 Mon Sep 17 00:00:00 2001 From: Richard Yao Date: Mon, 26 Sep 2022 20:02:38 -0400 Subject: Cleanup: Remove ineffective unsigned comparisons against 0 Coverity found a number of places where we either do MAX(unsigned, 0) or do assertions that a unsigned variable is >= 0. These do nothing, so let us drop them all. It also found a spot where we do `if (unsigned >= 0 && ...)`. Let us also drop the unsigned >= 0 check. Reviewed-by: Neal Gompa Reviewed-by: Brian Behlendorf Signed-off-by: Richard Yao Closes #13871 --- module/icp/algs/blake3/blake3_impl.c | 1 - module/os/freebsd/zfs/zfs_acl.c | 2 +- module/os/linux/zfs/zfs_acl.c | 2 +- module/os/linux/zfs/zvol_os.c | 2 +- module/zfs/arc.c | 2 +- module/zfs/dsl_dataset.c | 2 -- module/zfs/refcount.c | 1 - module/zfs/vdev_queue.c | 2 +- 8 files changed, 5 insertions(+), 9 deletions(-) diff --git a/module/icp/algs/blake3/blake3_impl.c b/module/icp/algs/blake3/blake3_impl.c index 5276fd88f..1692916ce 100644 --- a/module/icp/algs/blake3/blake3_impl.c +++ b/module/icp/algs/blake3/blake3_impl.c @@ -155,7 +155,6 @@ blake3_impl_setid(uint32_t id) atomic_swap_32(&blake3_impl_chosen, IMPL_CYCLE); break; default: - ASSERT3U(id, >=, 0); ASSERT3U(id, <, blake3_supp_impls_cnt); atomic_swap_32(&blake3_impl_chosen, id); break; diff --git a/module/os/freebsd/zfs/zfs_acl.c b/module/os/freebsd/zfs/zfs_acl.c index ad482ee9d..963102f3b 100644 --- a/module/os/freebsd/zfs/zfs_acl.c +++ b/module/os/freebsd/zfs/zfs_acl.c @@ -527,7 +527,7 @@ zfs_acl_valid_ace_type(uint_t type, uint_t flags) entry_type == ACE_EVERYONE || entry_type == 0 || entry_type == ACE_IDENTIFIER_GROUP); default: - if (type >= MIN_ACE_TYPE && type <= MAX_ACE_TYPE) + if (type <= MAX_ACE_TYPE) return (B_TRUE); } return (B_FALSE); diff --git a/module/os/linux/zfs/zfs_acl.c b/module/os/linux/zfs/zfs_acl.c index 4fd071d3c..5935403b4 100644 --- a/module/os/linux/zfs/zfs_acl.c +++ b/module/os/linux/zfs/zfs_acl.c @@ -525,7 +525,7 @@ zfs_acl_valid_ace_type(uint_t type, uint_t flags) entry_type == ACE_EVERYONE || entry_type == 0 || entry_type == ACE_IDENTIFIER_GROUP); default: - if (type >= MIN_ACE_TYPE && type <= MAX_ACE_TYPE) + if (type <= MAX_ACE_TYPE) return (B_TRUE); } return (B_FALSE); diff --git a/module/os/linux/zfs/zvol_os.c b/module/os/linux/zfs/zvol_os.c index 8904dc5bb..0d4e0dcd5 100644 --- a/module/os/linux/zfs/zvol_os.c +++ b/module/os/linux/zfs/zvol_os.c @@ -1433,7 +1433,7 @@ zvol_os_create_minor(const char *name) * Prefetching the blocks commonly scanned by blkid(8) will speed * up this process. */ - len = MIN(MAX(zvol_prefetch_bytes, 0), SPA_MAXBLOCKSIZE); + len = MIN(zvol_prefetch_bytes, SPA_MAXBLOCKSIZE); if (len > 0) { dmu_prefetch(os, ZVOL_OBJ, 0, 0, len, ZIO_PRIORITY_SYNC_READ); dmu_prefetch(os, ZVOL_OBJ, 0, volsize - len, len, diff --git a/module/zfs/arc.c b/module/zfs/arc.c index b9969bff5..7957b1b56 100644 --- a/module/zfs/arc.c +++ b/module/zfs/arc.c @@ -7664,7 +7664,7 @@ arc_tuning_update(boolean_t verbose) /* Valid range: 0 - */ if ((zfs_arc_sys_free) && (zfs_arc_sys_free != arc_sys_free)) - arc_sys_free = MIN(MAX(zfs_arc_sys_free, 0), allmem); + arc_sys_free = MIN(zfs_arc_sys_free, allmem); WARN_IF_TUNING_IGNORED(zfs_arc_sys_free, arc_sys_free, verbose); } diff --git a/module/zfs/dsl_dataset.c b/module/zfs/dsl_dataset.c index a7aca48aa..c9d0a9940 100644 --- a/module/zfs/dsl_dataset.c +++ b/module/zfs/dsl_dataset.c @@ -2128,8 +2128,6 @@ dsl_livelist_should_disable(dsl_dataset_t *ds) used = dsl_dir_get_usedds(ds->ds_dir); referenced = dsl_get_referenced(ds); - ASSERT3U(referenced, >=, 0); - ASSERT3U(used, >=, 0); if (referenced == 0) return (B_FALSE); percent_shared = (100 * (referenced - used)) / referenced; diff --git a/module/zfs/refcount.c b/module/zfs/refcount.c index b215df98d..c65228457 100644 --- a/module/zfs/refcount.c +++ b/module/zfs/refcount.c @@ -137,7 +137,6 @@ zfs_refcount_add_many(zfs_refcount_t *rc, uint64_t number, const void *holder) ref->ref_holder = holder; ref->ref_number = number; mutex_enter(&rc->rc_mtx); - ASSERT3U(rc->rc_count, >=, 0); list_insert_head(&rc->rc_list, ref); rc->rc_count += number; count = rc->rc_count; diff --git a/module/zfs/vdev_queue.c b/module/zfs/vdev_queue.c index 9a805f2c3..7acb9915c 100644 --- a/module/zfs/vdev_queue.c +++ b/module/zfs/vdev_queue.c @@ -614,7 +614,7 @@ vdev_queue_aggregate(vdev_queue_t *vq, zio_t *zio) limit = zfs_vdev_aggregation_limit_non_rotating; else limit = zfs_vdev_aggregation_limit; - limit = MAX(MIN(limit, maxblocksize), 0); + limit = MIN(limit, maxblocksize); if (zio->io_flags & ZIO_FLAG_DONT_AGGREGATE || limit == 0) return (NULL); -- cgit v1.2.3