From: Mohamed Osama <mohamed.osama189110@gmail.com>
To: ojeda@kernel.org
Cc: boqun@kernel.org, gary@garyguo.net, bjorn3_gh@protonmail.com,
lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com,
tmgross@umich.edu, dakr@kernel.org, daniel.almeida@collabora.com,
tamird@kernel.org, acourbot@nvidia.com, work@onurozkan.dev,
longman@redhat.com, lyude@redhat.com,
linux-block@vger.kernel.org, linux-serial@vger.kernel.org,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v3 3/5] rust: block: gen_disk: use DropGuard
Date: Sat, 26 Sep 2026 20:33:13 +0300 [thread overview]
Message-ID: <20260926173315.56772-4-mohamed.osama189110@gmail.com> (raw)
In-Reply-To: <20260926173315.56772-1-mohamed.osama189110@gmail.com>
Replace the ScopeGuard instances in the Rust block layer generic disk
implementation with DropGuard.
DropGuard provides the same scope-exit cleanup behavior while using the
new Rust kernel memory API.
Signed-off-by: Mohamed Osama <mohamed.osama189110@gmail.com>
---
rust/kernel/block/mq/gen_disk.rs | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/rust/kernel/block/mq/gen_disk.rs b/rust/kernel/block/mq/gen_disk.rs
index fc97dd873974..d9019fbbb361 100644
--- a/rust/kernel/block/mq/gen_disk.rs
+++ b/rust/kernel/block/mq/gen_disk.rs
@@ -10,11 +10,12 @@
block::mq::{Operations, TagSet},
error::{self, from_err_ptr, Result},
fmt::{self, Write},
+ mem::DropGuard,
prelude::*,
static_lock_class,
str::NullTerminatedFormatter,
sync::Arc,
- types::{ForeignOwnable, ScopeGuard},
+ types::ForeignOwnable,
};
/// A builder for [`GenDisk`].
@@ -102,7 +103,7 @@ pub fn build<T: Operations>(
queue_data: T::QueueData,
) -> Result<GenDisk<T>> {
let data = queue_data.into_foreign();
- let recover_data = ScopeGuard::new(|| {
+ let recover_data = DropGuard::new((), |_| {
// SAFETY: T::QueueData was created by the call to `into_foreign()` above
drop(unsafe { T::QueueData::from_foreign(data) });
});
@@ -150,7 +151,7 @@ pub fn build<T: Operations>(
// SAFETY: `gendisk` is a valid pointer as we initialized it above
unsafe { (*gendisk).fops = &TABLE };
- let cleanup_failure = ScopeGuard::new_with_data((gendisk, data), |(gendisk, data)| {
+ let cleanup_failure = DropGuard::new((gendisk, data), |(gendisk, data)| {
// SAFETY: `gendisk` came from `__blk_mq_alloc_disk()` above and
// has not been added to the VFS on this cleanup path.
unsafe { bindings::put_disk(gendisk) };
@@ -161,7 +162,7 @@ pub fn build<T: Operations>(
// The failure guard now owns both pieces of cleanup; the early guard
// must not run on this path anymore.
- recover_data.dismiss();
+ DropGuard::dismiss(recover_data);
let mut writer = NullTerminatedFormatter::new(
// SAFETY: `gendisk` points to a valid and initialized instance. We
@@ -185,7 +186,7 @@ pub fn build<T: Operations>(
},
)?;
- cleanup_failure.dismiss();
+ DropGuard::dismiss(cleanup_failure);
// INVARIANT: `gendisk` was initialized above.
// INVARIANT: `gendisk` was added to the VFS via `device_add_disk` above.
--
2.43.0
next prev parent reply other threads:[~2026-09-26 17:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-26 17:33 [PATCH v3 0/5] rust: add DropGuard Mohamed Osama
2026-09-26 17:33 ` [PATCH v3 1/5] rust: add DropGuard KUnit test configuration Mohamed Osama
2026-09-26 17:33 ` [PATCH v3 2/5] rust: mem: add DropGuard Mohamed Osama
2026-09-26 23:53 ` Gary Guo
2026-09-26 17:33 ` Mohamed Osama [this message]
2026-09-26 17:33 ` [PATCH v3 4/5] rust: serdev: use DropGuard Mohamed Osama
2026-09-26 17:33 ` [PATCH v3 5/5] rust: sync: lock: " Mohamed Osama
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260926173315.56772-4-mohamed.osama189110@gmail.com \
--to=mohamed.osama189110@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=longman@redhat.com \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®