From 856cefcd1c57da665e1690786a8be011ce7e4fa2 Mon Sep 17 00:00:00 2001 From: Richard Yao Date: Fri, 20 Jan 2023 14:10:15 -0500 Subject: [PATCH] Cleanup ->dd_space_towrite should be unsigned This is only ever used with unsigned data, so the type itself should be unsigned. Also, PVS Studio's 2016 FreeBSD kernel report correctly identified the following assertion as always being true, so we can drop it: ASSERT3U(dd->dd_space_towrite[i & TXG_MASK], >=, 0); The reason it was always true is because it would do casts to give us unsigned comparisons. This could have been fixed by switching to `ASSERT3S()`, but upon inspection, it turned out that this variable never should have been allowed to be signed in the first place. Reviewed-by: Ryan Moeller Reviewed-by: Brian Behlendorf Signed-off-by: Richard Yao Closes #14408 --- include/sys/dsl_dir.h | 2 +- module/zfs/dsl_dir.c | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/sys/dsl_dir.h b/include/sys/dsl_dir.h index 384f98e8f..f7c0d9acd 100644 --- a/include/sys/dsl_dir.h +++ b/include/sys/dsl_dir.h @@ -116,7 +116,7 @@ struct dsl_dir { /* gross estimate of space used by in-flight tx's */ uint64_t dd_tempreserved[TXG_SIZE]; /* amount of space we expect to write; == amount of dirty data */ - int64_t dd_space_towrite[TXG_SIZE]; + uint64_t dd_space_towrite[TXG_SIZE]; dsl_deadlist_t dd_livelist; bplist_t dd_pending_frees; diff --git a/module/zfs/dsl_dir.c b/module/zfs/dsl_dir.c index c1afaa6aa..18142cef9 100644 --- a/module/zfs/dsl_dir.c +++ b/module/zfs/dsl_dir.c @@ -1186,10 +1186,9 @@ dsl_dir_space_towrite(dsl_dir_t *dd) ASSERT(MUTEX_HELD(&dd->dd_lock)); - for (int i = 0; i < TXG_SIZE; i++) { + for (int i = 0; i < TXG_SIZE; i++) space += dd->dd_space_towrite[i & TXG_MASK]; - ASSERT3U(dd->dd_space_towrite[i & TXG_MASK], >=, 0); - } + return (space); }