Add a debug assertion in `ARef::dismiss` to verify that the request refcount is at least two when an `ARef` exists. This helps catch reference counting bugs during development. Signed-off-by: Andreas Hindborg --- 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 exist" + ); + core::mem::forget(self); } } -- 2.51.2