[PATCH v3 0/5] rust: add DropGuard

From: Mohamed Osama

Date: Sat Sep 26 2026 - 13:33:36 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 v2:
- Clarified why DropGuard is added alongside the existing ScopeGuard.
- Fixed the core imports in mem.rs to follow the Rust kernel import style.

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

The changes in v3 are limited to the import style and commit-message
clarification.

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 | 121 +++++++++++++++++++++++++++++++
rust/kernel/serdev.rs | 10 +--
rust/kernel/sync/lock.rs | 5 +-
5 files changed, 144 insertions(+), 13 deletions(-)

--
2.43.0