From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B6ACD2773D4 for ; Mon, 16 Feb 2026 08:54:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771232045; cv=none; b=MqA76OanCmNMyKAcqvBGjsexoD/zXOSbqUSbYesq+l0akd5HA4Ah4hJVeSQGT7CHdKTdnGzjMoT/TRO6TkMcGYDvZJkw0UgEMO63Ts9KFodhagjqeBhpXUMM2+WzfaSYRetLephth06HNOAzsFWZwG9L3nrV+vplylqHIu62XI4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771232045; c=relaxed/simple; bh=7rey5aOxAQx/0LrCuq/8cm8rXfoQtIpMUaEE3HnXh64=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=h8dHjEyZ8vBg8liPJkV1vLvbK4BnuPpfwjJHfRoqMkBQW/BEtqx+KmZORYFXEoIoMxfF3oqj4OkFQeLiS8CRoq1/pQ6TMxYCE4a0x/pUBLlXaCvovI571YB6tdaEeblPZToGL2Yr8P9y1JJ0+WJjTqRLtRjQ191tbDwi9CjODU8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=RQmTJY6p; arc=none smtp.client-ip=209.85.208.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="RQmTJY6p" Received: by mail-ed1-f73.google.com with SMTP id 4fb4d7f45d1cf-65a408f232eso3194150a12.0 for ; Mon, 16 Feb 2026 00:54:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1771232042; x=1771836842; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=zS4jfvZRcJonWqgB+wt0EbsUJ/SxDBZm7B6KVfmZmxY=; b=RQmTJY6pFSb4QzX5/irt93zvsciZCMF9cebFvhL1Y2xpTqwPKAz4rhb9xeNGFnP7rI TUs/eDQlnoQunw775FSTQlXobvjZPYZWdSTjiyp9iUNGTYUzRUhuKxjLv+eO7nFP/eAN EGQwJQZuAWtn3R/Ywq7NrsrAyiOw9B6ZzmTSk+HlACD1z+2r1Pl/hgprAgrNAled7VIy Y8asyyQeYcKb6VL7T4jdukiKoVu/VE6Auc3KIn6qZp8gFNpInLh6kByNxLXOwlt7n2tH 8+FJ14ktKLfBOM0wOBja8LhHDku4pGqPonxmzKv42wD46daCFDz5BdJwJbEnw3AbDsFV qdxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771232042; x=1771836842; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zS4jfvZRcJonWqgB+wt0EbsUJ/SxDBZm7B6KVfmZmxY=; b=hRwSVVBgRzlOkPjb6AyVbPOO517IsG/C2g5VeyHXobC/Tua4W7ORdZq8kJOeqvrN9W nVWvVnh9EDTU/mxJcIJwAmHgC8EGl5o1Ask4RPKT3BBTSTFBt6InaSievt4tfNZgJWMq PD8UsW+zyM8ilujlgTwRyYBxPxXHYEqRBVHgqM4M2br70myinJuLI851at8FWwebOgh8 dtYdOUNovvgSb9mYL3TizzruO2PG4NJ7QsGJdeS0PCTRvT2UoNPBckxRQ8xJKVwPv6Dc 9CEvMtkpqjikCm1aP+M3BYKPfMk/FtiNaloGsYn9TmI84SrIFjZOQeirkxzbdeO/7qfd wFyA== X-Forwarded-Encrypted: i=1; AJvYcCWQF5MYRiPfbF0Ckl44Cg8dHprZKNdCra8X0Sys4yhskVa1N619eO7l3dRQfloQtVjhClrnsXRNDoUnuxI=@vger.kernel.org X-Gm-Message-State: AOJu0YzXvAxJTxZUvMMhjdi1ItYJV6GXAVavH7zHKBJtFTx5EzP3tgsX cwH35rpRxIIesA6XxOoQnm/5rg6iizZwemYAFEbRBKQgvfat9O1Cf+r95ZziR12tM9cKzhMdGsW yRf5BF0r0FXVzuVRskw== X-Received: from eduw19.prod.google.com ([2002:aa7:dcd3:0:b0:659:314c:bcf2]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6402:50c9:b0:659:428f:a6c0 with SMTP id 4fb4d7f45d1cf-65bb129c72amr4699972a12.20.1771232041734; Mon, 16 Feb 2026 00:54:01 -0800 (PST) Date: Mon, 16 Feb 2026 08:54:00 +0000 In-Reply-To: <87bjhpdusd.fsf@t14s.mail-host-address-is-not-set> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260215-export-do-unlocked-v1-1-f5cd2203b20f@kernel.org> <87bjhpdusd.fsf@t14s.mail-host-address-is-not-set> Message-ID: Subject: Re: [PATCH] rust: sync: export lock::do_unlocked From: Alice Ryhl To: Andreas Hindborg Cc: Benno Lossin , Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng , Waiman Long , Miguel Ojeda , Gary Guo , "=?utf-8?B?QmrDtnJu?= Roy Baron" , Trevor Gross , Danilo Krummrich , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Content-Type: text/plain; charset="utf-8" On Mon, Feb 16, 2026 at 08:14:42AM +0100, Andreas Hindborg wrote: > "Benno Lossin" 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 > > > > Reviewed-by: Benno Lossin > > > >> --- > >> 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 { > >> self.lock > >> } > >> > >> - pub(crate) fn do_unlocked(&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