From: "tip-bot2 for Alice Ryhl" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Alice Ryhl <aliceryhl@google.com>, Fiona Behrens <me@kloenk.dev>,
Boqun Feng <boqun.feng@gmail.com>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: locking/core] rust: sync: Add accessor for the lock behind a given guard
Date: Mon, 03 Mar 2025 18:51:56 -0000 [thread overview]
Message-ID: <174102791612.14745.8505844030900098070.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20250205-guard-get-lock-v2-1-ba32a8c1d5b7@google.com>
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 36dbde71fcece19699cef0d01bd2123a6d3142f4
Gitweb: https://git.kernel.org/tip/36dbde71fcece19699cef0d01bd2123a6d3142f4
Author: Alice Ryhl <aliceryhl@google.com>
AuthorDate: Wed, 05 Feb 2025 10:54:50
Committer: Boqun Feng <boqun.feng@gmail.com>
CommitterDate: Sun, 23 Feb 2025 18:24:46 -08:00
rust: sync: Add accessor for the lock behind a given guard
In order to assert a particular `Guard` is associated with a particular
`Lock`, add an accessor to obtain a reference to the underlying `Lock`
of a `Guard`.
Binder needs this assertion to ensure unsafe list operations are done
with the correct lock held.
[Boqun: Capitalize the title and reword the commit log]
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Fiona Behrens <me@kloenk.dev>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250205-guard-get-lock-v2-1-ba32a8c1d5b7@google.com
---
rust/kernel/sync/lock.rs | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs
index eb80048..8e7e6d5 100644
--- a/rust/kernel/sync/lock.rs
+++ b/rust/kernel/sync/lock.rs
@@ -199,7 +199,12 @@ pub struct Guard<'a, T: ?Sized, B: Backend> {
// SAFETY: `Guard` is sync when the data protected by the lock is also sync.
unsafe impl<T: Sync + ?Sized, B: Backend> Sync for Guard<'_, T, B> {}
-impl<T: ?Sized, B: Backend> Guard<'_, T, B> {
+impl<'a, T: ?Sized, B: Backend> Guard<'a, T, B> {
+ /// Returns the lock that this guard originates from.
+ pub fn lock_ref(&self) -> &'a Lock<T, B> {
+ self.lock
+ }
+
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) };
next prev parent reply other threads:[~2025-03-03 18:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-05 10:54 [PATCH v2] rust: sync: add " Alice Ryhl
2025-02-05 18:52 ` Fiona Behrens
2025-02-10 6:03 ` Boqun Feng
2025-03-03 18:51 ` tip-bot2 for Alice Ryhl [this message]
2025-03-07 23:26 [PATCH locking 07/11] rust: sync: Add " Boqun Feng
2025-03-08 0:08 ` [tip: locking/core] " tip-bot2 for Alice Ryhl
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=174102791612.14745.8505844030900098070.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=aliceryhl@google.com \
--cc=boqun.feng@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=me@kloenk.dev \
--cc=x86@kernel.org \
/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®