All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boqun Feng <boqun@kernel.org>
To: Mohamed Osama <mohamed.osama189110@gmail.com>
Cc: ojeda@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: Re: [PATCH 4/4] rust: sync: lock: use DropGuard
Date: Mon, 28 Sep 2026 11:03:19 +0200	[thread overview]
Message-ID: <arotV9Iszgg-Z1aE@MacBook-0RXW5> (raw)
In-Reply-To: <20260927104528.103881-5-mohamed.osama189110@gmail.com>

On Sun, Sep 27, 2026 at 01:45:28PM +0300, Mohamed Osama wrote:
> Replace the ScopeGuard usage in the Rust locking implementation with
> DropGuard.
> 
> The guard preserves the existing scope-exit cleanup behavior while using
> the DropGuard API from the Rust kernel memory module.
> 
> Signed-off-by: Mohamed Osama <mohamed.osama189110@gmail.com>

Reviewed-by: Boqun Feng <boqun@kernel.org>

Regards,
Boqun

> ---
>  rust/kernel/sync/lock.rs | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs
> index 10b6b5e9b024..15f9cbe76c8d 100644
> --- a/rust/kernel/sync/lock.rs
> +++ b/rust/kernel/sync/lock.rs
> @@ -7,8 +7,9 @@
>  
>  use super::LockClassKey;
>  use crate::{
> +    mem::DropGuard,
>      str::{CStr, CStrExt as _},
> -    types::{NotThreadSafe, Opaque, ScopeGuard},
> +    types::{NotThreadSafe, Opaque},
>  };
>  use core::{cell::UnsafeCell, marker::PhantomPinned, pin::Pin};
>  use pin_init::{pin_data, pin_init, PinInit, Wrapper};
> @@ -242,7 +243,7 @@ pub(crate) fn do_unlocked<U>(&mut self, cb: impl FnOnce() -> U) -> U {
>          // SAFETY: The caller owns the lock, so it is safe to unlock it.
>          unsafe { B::unlock(self.lock.state.get(), &self.state) };
>  
> -        let _relock = ScopeGuard::new(||
> +        let _relock = DropGuard::new((), |_|
>                  // SAFETY: The lock was just unlocked above and is being relocked now.
>                  unsafe { B::relock(self.lock.state.get(), &mut self.state) });
>  
> -- 
> 2.43.0
> 

  parent reply	other threads:[~2026-09-28  9:03 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Dch07wH15t-1WtaVQW4vdfmtJuwC_4-JLvrWSB8Pk4vfEHO6mQk1FpYG-tCYBllTB3RbpOXpdyNZp84w4PFl1A==@protonmail.internalid>
2026-09-27 10:45 ` [PATCH v4 0/4] rust: introduce DropGuard Mohamed Osama
2026-09-27 10:45   ` [PATCH 1/4] rust: mem: add DropGuard Mohamed Osama
2026-09-27 10:52     ` sashiko-bot
2026-09-27 10:45   ` [PATCH 2/4] rust: block: gen_disk: use DropGuard Mohamed Osama
2026-09-27 10:51     ` sashiko-bot
2026-09-27 10:45   ` [PATCH 3/4] rust: serdev: " Mohamed Osama
2026-09-27 10:56     ` sashiko-bot
2026-10-10 21:30     ` Markus Probst
2026-09-27 10:45   ` [PATCH 4/4] rust: sync: lock: " Mohamed Osama
2026-09-27 10:51     ` sashiko-bot
2026-09-28  9:03     ` Boqun Feng [this message]
2026-09-28  9:48   ` [PATCH v4 0/4] rust: introduce DropGuard Andreas Hindborg
2026-09-28  9:50     ` Andreas Hindborg

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=arotV9Iszgg-Z1aE@MacBook-0RXW5 \
    --to=boqun@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --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=mohamed.osama189110@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.