[PATCH v2 0/5] rust: add DropGuard

From: Mohamed Osama

Date: Sat Sep 26 2026 - 12:36:04 EST


Add the Rust kernel DropGuard API and migrate the existing ScopeGuard
users in the block, serdev, and locking code.

DropGuard runs a FnOnce callback when dropped and provides dismiss() to
take ownership of the wrapped value without running the cleanup callback.

Changes since v1:
- Split the changes into separate patches for each affected module.
- Added a separate KUnit configuration patch.

The series was tested with:
- make LLVM=1 rustfmtcheck
- make LLVM=1 rustdoc
- make LLVM=1 -j$(nproc)
- git diff --check
- scripts/checkpatch.pl

Mohamed Osama (5):
rust: add DropGuard KUnit test configuration
rust: mem: add DropGuard
rust: block: gen_disk: use DropGuard
rust: serdev: use DropGuard
rust: sync: lock: use DropGuard

rust/kernel/Kconfig.test | 10 +++
rust/kernel/block/mq/gen_disk.rs | 11 +--
rust/kernel/mem.rs | 123 +++++++++++++++++++++++++++++++
rust/kernel/serdev.rs | 10 +--
rust/kernel/sync/lock.rs | 5 +-
5 files changed, 146 insertions(+), 13 deletions(-)

--
2.43.0