public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alice Ryhl <aliceryhl@google.com>
To: Andreas Hindborg <a.hindborg@kernel.org>
Cc: "Benno Lossin" <lossin@kernel.org>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Ingo Molnar" <mingo@redhat.com>, "Will Deacon" <will@kernel.org>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Waiman Long" <longman@redhat.com>,
	"Miguel Ojeda" <ojeda@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH] rust: sync: export lock::do_unlocked
Date: Mon, 16 Feb 2026 08:54:00 +0000	[thread overview]
Message-ID: <aZLbKPym_VxwZ6-I@google.com> (raw)
In-Reply-To: <87bjhpdusd.fsf@t14s.mail-host-address-is-not-set>

On Mon, Feb 16, 2026 at 08:14:42AM +0100, Andreas Hindborg wrote:
> "Benno Lossin" <lossin@kernel.org> writes:
> 
> > On Sun Feb 15, 2026 at 9:15 PM CET, Andreas Hindborg wrote:
> >> Export lock::do_unlocked publicly. Add documentation for the method.
> >>
> >> Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
> >
> > Reviewed-by: Benno Lossin <lossin@kernel.org>
> >
> >> ---
> >>  rust/kernel/sync/lock.rs | 26 +++++++++++++++++++++++++-
> >>  1 file changed, 25 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs
> >> index 46a57d1fc309d..f390cd7ba0762 100644
> >> --- a/rust/kernel/sync/lock.rs
> >> +++ b/rust/kernel/sync/lock.rs
> >> @@ -235,7 +235,31 @@ pub fn lock_ref(&self) -> &'a Lock<T, B> {
> >>          self.lock
> >>      }
> >>
> >> -    pub(crate) fn do_unlocked<U>(&mut self, cb: impl FnOnce() -> U) -> U {
> >> +    /// Temporarily unlock the lock to execute the given closure.
> >> +    ///
> >> +    /// This method unlocks the lock before calling the closure `cb`, and re-locks it afterwards.
> >> +    /// This is useful when you need to perform operations that are not allowed while holding
> >> +    /// certain locks, such as allocating memory (which is prohibited while holding a spinlock).
> >> +    ///
> >> +    /// # Examples
> >> +    ///
> >> +    /// ```
> >> +    /// # use kernel::{new_spinlock, prelude::*};
> >> +    /// # use pin_init::stack_pin_init;
> >> +    ///

This will show up as a spurious newline in docs. I would just not hide
the imports, but if you do, then don't have a newline after them.

> >> +    /// stack_pin_init!{
> >> +    ///     let lock = new_spinlock!(())
> >> +    /// }
> >> +    ///
> >> +    /// let mut guard = lock.lock();
> >> +    /// let mut buffer = KVec::new();
> >> +    /// // Temporarily unlock to allocate memory, which should not be done while holding a spinlock.
> >> +    ///  guard.do_unlocked(|| {
> >            ^
> > Spurious space.
> 
> Thanks. Code formatting in comments is a problem in my setup. `rustfmt`
> is not much help.

Unfortunately there's not much helper to get there

Alice

      reply	other threads:[~2026-02-16  8:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-15 20:15 [PATCH] rust: sync: export lock::do_unlocked Andreas Hindborg
2026-02-15 23:24 ` Benno Lossin
2026-02-16  7:14   ` Andreas Hindborg
2026-02-16  8:54     ` Alice Ryhl [this message]

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=aZLbKPym_VxwZ6-I@google.com \
    --to=aliceryhl@google.com \
    --cc=a.hindborg@kernel.org \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=lossin@kernel.org \
    --cc=mingo@redhat.com \
    --cc=ojeda@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    --cc=will@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