[PATCH 01/20] Catch errors in calls to ngnfs_tblk_zero_tail()

Valerie Aurora val at versity.com
Thu Jun 12 13:10:53 PDT 2025


ngnfs_tblk_zero_tail() was testing for the head (area to not zero)
being larger than than the tail by subtracting and checking for a
negative result and silently doing nothing. But the variables are the
same type as those being passed in, which are always unsigned, so the
test never triggered. Instead, assert that the head is less than or
equal to the tail. head == tail should be allowed since the main use
is zeroing out the difference between the unaligned length and aligned
length of a btree item, which are sometimes the same.

Signed-off-by: Valerie Aurora <val at versity.com>
---
 shared/txn.h | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/shared/txn.h b/shared/txn.h
index 2d656a7..081dc30 100644
--- a/shared/txn.h
+++ b/shared/txn.h
@@ -57,17 +57,16 @@ do {								\
 } while (0)
 
 /*
- * Given a (buf) buffer of (total) size, zero the tail bytes	\
- * after (head) initial bytes.					\
- * skipping (head) initial bytes.
+ * Given a (buf) buffer of (total) size, zero the tail bytes
+ * after (head) initial bytes, skipping (head) initial bytes.
  */
 #define ngnfs_tblk_zero_tail(tblk, buf, head, total)		\
 do {								\
 	__typeof__(head) head_ = (head);			\
-	__typeof__(head) tail_ = (total) - head_;		\
+	__typeof__(total) tail_ = (total) - head_;		\
 								\
-	if (tail_ > 0)						\
-		ngnfs_tblk_memset((tblk), (void *)(buf) + head_, 0, tail_); \
+	BUG_ON(head > total);					\
+	ngnfs_tblk_memset((tblk), (void *)(buf) + head_, 0, tail_);	\
 } while (0)
 
 /*
-- 
2.49.0




More information about the ngnfs-devel mailing list