From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.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 3F0CC37B413 for ; Mon, 27 Apr 2026 07:29:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777274992; cv=none; b=aPpTiXCjRVHQNj4eq1EpTeo0w6tvrdAqpCWs85qYBT4k6Z/Jvg1eM0P2xeR5krYHZCYSHw/Vxjd2+9sP4RuqTg16KsobTmpw3ws3+iVqhqSQLb55cS5M5jeQR37PD11CFEwqzDC6Qi9E1Dj/FzbPVZ4HkgA74mIwAupgpDSsFds= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777274992; c=relaxed/simple; bh=kcWOBHhL0Othr4/xH2jWnmqZsEXqPSqzzLk+87ou4mU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=eRUqgIq6FhsOaILJQqN4oDTqN0EapxsOclo/TaRbgI+BSWO34oRbvspo0KjlMob+NmM75Ffm2u+S7o3Ickl01kO37Gg9q/ZMcb9JUooqcLiUjTc3UCGCgirSvVDCuJer9Du7+8JiUeNh6FndJSCSYUH82D6/xk1BAUGXhAPVkYg= 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=V1PJ9/1C; arc=none smtp.client-ip=209.85.221.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="V1PJ9/1C" Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-43d7757463eso6348948f8f.0 for ; Mon, 27 Apr 2026 00:29:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777274990; x=1777879790; 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=qb64gpRNptFvwSlo8JtSZZqe+KrTXpxUtsAcslpaJoU=; b=V1PJ9/1CKidHEUfDSJNM4+BwyZLnvzqKQwttAJNpwm055u1XR7H/PkoRFPN/y2ADL+ 08EH7gg+JrUNoQSKe5TAjzZsKPaaoOcA33UoCItSjrrG0oZOfOOuohe7OnaGbjSCKyzQ 0A7xJ34j4Y3PiVVmR6wRHzcc2REFYcWN7zECa4sudyLbsvABD46BE1Le/Jg0ikmi3fkU ODzCUPp4NZWjTo2ORKHY+7htTySFQkToWvB9yZ30O7jNAuZC2HQ8BR46fuK41i5jT8Nx ZB7t7LRI2mFRnkmaolREtI+NK9QsgwhkRgxNYFjsP/wC+IF4O+Rk0vXSjxSKg556EmFa I2sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777274990; x=1777879790; 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=qb64gpRNptFvwSlo8JtSZZqe+KrTXpxUtsAcslpaJoU=; b=VmH8mIL8H3+P41utiax6irvNcJKbi/YATX6yuNyUefesWJzu/eg+qdW9URGS2PSL05 Fz0yPGFAaqouA7SP1To+0oElB18qpFxJcGSYB72E5WMqe3xRX1cPfLk3Ei5d1G1RsAsf 9x4bFcN7Ymi2ZfjbpH1KXIrLp9nezDM4EOcgTfFIK8SqAMiFjoQI4gJ6eYcmyn4TYvNb Xee7/O48f0dqzfNro0/A+ctoDDmXJ9vfUcCQP6nVT4PhYhkHiMATQP1/cwt1loIwflm9 SGZ2Nbe0xTZtaQzaYoNg3Aho3+Akq8tnEj//vXQfueG7zlnrdNPyzcjw2wFW8qe6BSqA H62g== X-Forwarded-Encrypted: i=1; AFNElJ+xCVOMSewquu6NIdyxdV/KE19b46NhXBXgACD/SUdv1Ln1ylFGnq08CV9gEsBNLVmGsWzDJD/SvDhRris=@vger.kernel.org X-Gm-Message-State: AOJu0YxBOOo3p+wbKK15nWsX7xcyoUHCFD9yGKDoK8lRXkMLoWGzt7uY 1qLqe9T3QtTQWS7+V8q6TaWSu8n5ECc6piTsNjcQes6ZDhukDjdn//Rod62ss0RrlO43IK7fw6d Ux8SXSxloMZzH5jMo8w== X-Received: from wraz11.prod.google.com ([2002:a05:6000:468b:b0:43d:65d8:7edf]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a5d:6f14:0:b0:43d:7086:b03 with SMTP id ffacd0b85a97d-43fe4032b76mr53236111f8f.1.1777274989556; Mon, 27 Apr 2026 00:29:49 -0700 (PDT) Date: Mon, 27 Apr 2026 07:29:48 +0000 In-Reply-To: <20260419001141.211935-1-ashutoshdesai993@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260419001141.211935-1-ashutoshdesai993@gmail.com> Message-ID: Subject: Re: [PATCH] rust: sync: add #[must_use] to GlobalGuard and GlobalLock::try_lock From: Alice Ryhl To: Ashutosh Desai Cc: peterz@infradead.org, mingo@redhat.com, will@kernel.org, boqun@kernel.org, ojeda@kernel.org, longman@redhat.com, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, tmgross@umich.edu, dakr@kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Content-Type: text/plain; charset="utf-8" On Sun, Apr 19, 2026 at 12:11:41AM +0000, Ashutosh Desai wrote: > Guard is marked #[must_use] since dropping it releases the lock. GlobalGuard > wraps Guard with identical semantics but was missing the annotation, so > discarding it would silently compile without warning. > > Similarly, GlobalLock::try_lock was missing #[must_use]. Option does not > propagate #[must_use] from T, so the attribute needs to be on the function > directly - same reason Lock::try_lock has it. Add the explanatory comment > there too. > > Signed-off-by: Ashutosh Desai > --- > rust/kernel/sync/lock/global.rs | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/rust/kernel/sync/lock/global.rs b/rust/kernel/sync/lock/global.rs > index aecbdc34738f..7067bdcca9c2 100644 > --- a/rust/kernel/sync/lock/global.rs > +++ b/rust/kernel/sync/lock/global.rs > @@ -85,6 +85,8 @@ pub fn lock(&'static self) -> GlobalGuard { > } > > /// Try to lock this global lock. > + // `Option` is not `#[must_use]` even if `T` is, thus the attribute is needed here. > + #[must_use = "if unused, the lock will be immediately unlocked"] I don't think there's any need for this comment. Otherwise LGTM. Reviewed-by: Alice Ryhl > #[inline] > pub fn try_lock(&'static self) -> Option> { > Some(GlobalGuard { > @@ -96,6 +98,7 @@ pub fn try_lock(&'static self) -> Option> { > /// A guard for a [`GlobalLock`]. > /// > /// See [`global_lock!`] for examples. > +#[must_use = "the lock unlocks immediately when the guard is unused"] > pub struct GlobalGuard { > inner: Guard<'static, B::Item, B::Backend>, > } > -- > 2.34.1 >