[PATCH 68/79] block: rust: add a debug assert for refcounts

Andreas Hindborg
2026-02-15T23:46:11Z

Add a debug assertion in `ARef<Request>::dismiss` to verify that the
request refcount is at least two when an `ARef<Request>` exists. This
helps catch reference counting bugs during development.

Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
---
rust/kernel/block/mq/request.rs | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/rust/kernel/block/mq/request.rs b/rust/kernel/block/mq/request.rs
index e22af7ea77bbc..9a05bce39c64b 100644
--- a/rust/kernel/block/mq/request.rs
+++ b/rust/kernel/block/mq/request.rs
@@ -579,6 +579,17 @@ pub fn dismiss(mut self) {
// SAFETY: `inner` is valid for reads and writes, is properly aligned and nonnull. We have
// exclusive access to `inner` and we do not access `inner` after this call.
unsafe { core::ptr::drop_in_place(inner) };
+
+ debug_assert!(
+ self.inner
+ .wrapper_ref()
+ .refcount()
+ .as_atomic()
+ .load(ordering::Relaxed)
+ >= 2,
+ "Request refcount must be at least two when an ARef<Request> exist"
+ );
+
core::mem::forget(self);
}
}

--
2.51.2