From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) (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 0FB2F175A75 for ; Sun, 19 Apr 2026 00:11:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776557508; cv=none; b=FyOGVeeb908duqEGcVHq0URQY5s9O2avjbbI8joZcnXom6VElBHWTuz8RZExYt3NnaYt+5XaYHoqQsZ//pz45aVx23wkzn8uLLyZASxYeB2G5YCk48hdL/Z+vtHqlUOI29HnXseyJGrIvx12N8XAUKAjGgvtlhlQgT+JDUbOsMc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776557508; c=relaxed/simple; bh=Z0wdn4nJ2N0dfCW8ntRd8nkQMY6O1kejdCkZ6jlPQUY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=S2z4FT17NfL6qDSI7mpOPT3PyAAbFchrUdSHTGTBsoZiJ6EN2xB+Zrufyy+2ZtP4JeolI78xVyi+2QV/2bZxW5JYb24KiSCwsVGyujAlPWL8oxxUcWXbhDrNI0GaXL6U3c5DRSpMXuiL3WCucMTWF3Hng76kk2852tiglyi3Fi0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lo06x7Zm; arc=none smtp.client-ip=209.85.160.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lo06x7Zm" Received: by mail-qt1-f177.google.com with SMTP id d75a77b69052e-50d87610513so22573951cf.3 for ; Sat, 18 Apr 2026 17:11:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776557504; x=1777162304; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=uB8jFncCKEiB5ZAD6Q612C23o2c/bEg7RfuQUlFgPu0=; b=lo06x7ZmudcrOotE6JORN6vy5CE4RuJIO80dLZJGGtqzf3wbgcGNeYB1fsjWnMOn9S xRFfnOoh9KLRymVOSgfR7js6+7qbh8k3+YDPYchNzUyyoLL9+J5Il2JqNPqIymqYUfzS xEDdAtr0K7PUJPleA/nBK4We91QXShBBBGdloBP639SPj53RcAc5WAveR/idUDxnIzWB dkDJ1thr+3fdjHFSqBnkIzaAgYEyIZ1j4j3VXa0ngmYG/8ngdNFOlEoeezksgriqXp5V eo9OPRJwsKrikaxrsivWRWtPTdZICK8EgTKUdrz3B5GsetJrS15zycz8tpcjl58y4qlE MlQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776557504; x=1777162304; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=uB8jFncCKEiB5ZAD6Q612C23o2c/bEg7RfuQUlFgPu0=; b=mjR9KxEzTHIh2RA9iwsNBis4QfiMCOUxzuwuM5vuKeUzyYTIyw4Ipg7o5CDxGBN1EE oIsX1NER0x9oqt3ZqgcHxANirmTJ98uaAZFaLsa+pb1TDsXvK95O44b8jAzdFeVMQYD7 9fi/Hqp7RdtIZTZN1fgdkbl53HBA6CwS2HBAi5Pp/cDGeBkO3rLfstd5U694k9wq7GDc wpMEi6+W2Oc6UEicF3wSbfw+8TJA0K6QKDj+kz4kBoQCyHCmk9ZsIj/dLStPoWmZGPh8 KGXHC47nCaVV4jD4FORadDNkKYduVPw8avGf/yO+aLhvFLW92uNqI7OedwcThI4hK92d ke8w== X-Forwarded-Encrypted: i=1; AFNElJ9AGihrxJa5387Ommw5SebObVLLMAdB0CFWjGMrOkhDs41EuNCFN1gchJnVsLXFGVqoAuz0dGDqQ6xBu+w=@vger.kernel.org X-Gm-Message-State: AOJu0YyOmwzin4M6SCoopdVGt7mjtMYJd5VVOPlEwIOYpftCxl63F78h i23LV2bz7nJwv5jicwUB4LOcwF/Ta9QOkcHn3A7Kuwc9FtoFoLjDOl6S X-Gm-Gg: AeBDieuM3DlLfDpjTMeNMy9Zdf7eOTQG3E2xl/3dVuXlzKA+EbBmHIzjn8NAo2KCryO JcpiCrZ6AdbJ/H3atzZIPdROaYV5O6FbbB3Iox/0qsXUz+cR/kYCVdDh7FsK1cZSkW0SXTsWK3+ WwxRvHPxAJe5n5ijdi1NLpUgjXQzcM8BUW1Ra36ocECNlhQaz5g1v7didNhjN5oh+x4mppms/gj clvnB0UgVt1fEHLN9g3BmBTLA3jTwTadAhGbmrq7LcmRRj0esqRFi365M7Lvo1XB5OjgvChZLV4 6lAJ6yHfPrKWFWE+SGe1r/48ZJgjQul1Z+IX6uU1Okp6U0FQENGp3xTS0N1q5OXEIvS/bmRx2kv 6Kqq2NX5NG2kKAa8LrCi8yqp05RPSmfaSms3LLK4FOuY9jX7sLEP1vd9eMcBm9sjyRmf91qfXID FqhjiBsnRo+4cOAgghSj0LNpC8VYHTOGlHh0rv4bEyngyIFQzvj0Fxr4wqcbT6Q7Nb6xDvc++6m as14KziXwwX5F6QaN3Pvw32p2HtJ1SThjuROlE= X-Received: by 2002:a05:622a:429b:b0:50d:8049:2f22 with SMTP id d75a77b69052e-50e36b865f5mr117283941cf.3.1776557503734; Sat, 18 Apr 2026 17:11:43 -0700 (PDT) Received: from TDC4045031631.e0cglfehwr0e5gttmepj3hi3hf.ux.internal.cloudapp.net ([20.63.37.123]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8b02aec3a3bsm43460456d6.49.2026.04.18.17.11.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Apr 2026 17:11:43 -0700 (PDT) From: Ashutosh Desai To: peterz@infradead.org, mingo@redhat.com, will@kernel.org, boqun@kernel.org, ojeda@kernel.org Cc: longman@redhat.com, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Ashutosh Desai Subject: [PATCH] rust: sync: add #[must_use] to GlobalGuard and GlobalLock::try_lock Date: Sun, 19 Apr 2026 00:11:41 +0000 Message-Id: <20260419001141.211935-1-ashutoshdesai993@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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"] #[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