Re: [PATCH v2] rust: sync: export lock::do_unlocked

From: Alice Ryhl

Date: Mon Jun 08 2026 - 03:33:23 EST


On Fri, Jun 05, 2026 at 02:57:07PM +0200, Andreas Hindborg wrote:
> Export lock::do_unlocked publicly. Add documentation for the method.
>
> Reviewed-by: Benno Lossin <lossin@xxxxxxxxxx>
> Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>

Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>

> 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 10b6b5e9b024..9c549e469785 100644
> --- a/rust/kernel/sync/lock.rs
> +++ b/rust/kernel/sync/lock.rs
> @@ -238,7 +238,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;

I think the prelude is imported automatically.

Alice