aboutsummaryrefslogtreecommitdiffstats
path: root/module/zfs/zap_leaf.c
diff options
context:
space:
mode:
authorRichard Yao <[email protected]>2023-03-04 17:57:01 -0500
committerBrian Behlendorf <[email protected]>2023-03-08 13:51:46 -0800
commit17443e0b2044377f8cc7b9f4bc23b7fe6cbb3e3d (patch)
tree40c523805798c9b685ec35939a61c09a345005ce /module/zfs/zap_leaf.c
parent5dd0f019cd1c579c42f6c3d06b0ac1b03be342ba (diff)
Cleanup: Remove constant comparisons reported by CodeQL
CodeQL's cpp/constant-comparison query from its security-and-extended query set reported 4 instances where we have comparions that always evaluate the same way. In `draid_config_by_type()`, we have an early `if (nparity == 0)` check that returns `EINVAL`, making a later `if (nparity == 0 || nparity > VDEV_DRAID_MAXPARITY)` partially redundant. The later check prints an error message when parity is 0, but the early check does not. This is not useful feedback, so we move the later check to the place where the early check runs to replace the early check. In `perform_thread_merge()`, we return when `num_threads == 0`. After that block, we do `if (num_threads > 0) {`, which will always be true. We remove the `if` statement. In `sa_modify_attrs()`, we have a loop condition that is `k != 2`, but at the end of the loop, we have `if (k == 0 && hdl->sa_spill)` followed by an else that does a break. The result is that k != 2 will never be evaluated when it is false. We drop the comparison. In `zap_leaf_array_read()`, we have a for loop condition that is `i < ZAP_LEAF_ARRAY_BYTES && len > 0`. However, that loop itself is in a loop that is `while (len > 0)` and while the value of len is decremented inside the loop, when `len == 0`, it will return, such that `len > 0` inside the loop condition will always be true. We drop that part of the condition. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Richard Yao <[email protected]> Closes #14575
Diffstat (limited to 'module/zfs/zap_leaf.c')
-rw-r--r--module/zfs/zap_leaf.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/module/zfs/zap_leaf.c b/module/zfs/zap_leaf.c
index 2e8489c7d..e6afb1c58 100644
--- a/module/zfs/zap_leaf.c
+++ b/module/zfs/zap_leaf.c
@@ -315,7 +315,7 @@ zap_leaf_array_read(zap_leaf_t *l, uint16_t chunk,
struct zap_leaf_array *la = &ZAP_LEAF_CHUNK(l, chunk).l_array;
ASSERT3U(chunk, <, ZAP_LEAF_NUMCHUNKS(l));
- for (int i = 0; i < ZAP_LEAF_ARRAY_BYTES && len > 0; i++) {
+ for (int i = 0; i < ZAP_LEAF_ARRAY_BYTES; i++) {
value = (value << 8) | la->la_array[i];
byten++;
if (byten == array_int_len) {