From nobody Tue Dec 2 00:26:26 2025 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3510F30CD95 for ; Mon, 24 Nov 2025 13:58:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763992737; cv=none; b=tkKdShN1HVovutwHiEHntF8/0hPihk9bGs+QcHoEF+tTw0dF25hSItYLXHZnRx/Onxk85+vbaSFDEV1u7UEX+mKGQbQ44edjVT8q0S6tzh1+IknPkEmPtNXa73kMlm3zO8xFD6eH4xu5qNl0ljJ9mGoctVWCPc+Map5hOUFC5vw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763992737; c=relaxed/simple; bh=zrVghukoUK1AK2ATuqnxW3//M7lS4awlRULLX45Scv4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=thBBNX07SK6oCggLXNazmKlsuc73jngF6v/B+Rdig9RaneXKVYb7d+7i/Z6J004AXpqASG0wDV+aIcHhCMPV6DTfp4KPbDSafrv6DuvKBvF490A/rQLX3cB06mSI8SXdcTprkLS/ZqCaCLcQ6bQAj4L6BfCe5ckgTFGFu/7mlsM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=IvVzSbvy; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="IvVzSbvy" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:In-Reply-To:References; bh=/WYYYpz387CFFfjGN9nUyeTOzgG1490tliK7z9gYns0=; b=IvVzSbvyKPhyb4106U2HECShb1 Wu5QwqlSALRg3xf8gvYGfX35kD3PGIxsgkyjtLwLcxQrydMgFWdWs+kq3uhjuNtAai5S0nk21eUGC zpUJupnZgvtWwQcmNmiNp0nrTVkVg1OwKZaYnxOd5mq4cJjbbeAzJnZ+7Zjfih8zGGvVlHy5CXniu p1Nl04aZdfpCKPy+uVzurjGuKaNgSSQlNPXB9aLAdH5Kov3zIEpQfGIVvss7frx+7aZH7YhvVqFX7 aM8TW9YJw3/vMUPfVMtiy3RMEMcPEj7ZjN5tFynLttFy7Vn/F+9UV25tW6wFPmk/Y0B8GjLpV1IY9 7yhzQBgw==; Received: from 2a02-8389-2341-5b80-d601-7564-c2e0-491c.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:d601:7564:c2e0:491c] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vNX5h-0000000BnQ9-16MP; Mon, 24 Nov 2025 13:58:53 +0000 From: Christoph Hellwig To: akpm@linux-foundation.org Cc: torvalds@linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH] lockref: add a __cond_lock annotation for lockref_put_or_lock Date: Mon, 24 Nov 2025 14:58:21 +0100 Message-ID: <20251124135849.902631-1-hch@lst.de> X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Content-Type: text/plain; charset="utf-8" Add a cond_lock annotation for lockref_put_or_lock to make sparse happy with using it. Note that for this the return value has to be double-inverted as the return value convention of lockref_put_or_lock is inverted compared to _trylock conventions expected by __cond_lock, as lockref_put_or_lock returns true when it did not need to take the lock. Signed-off-by: Christoph Hellwig --- I still prefer the version with the _-prefix, but this works as well and Linus like it. So let's go with it. include/linux/lockref.h | 2 ++ lib/lockref.c | 1 + 2 files changed, 3 insertions(+) diff --git a/include/linux/lockref.h b/include/linux/lockref.h index 676721ee878d..815d871fadfc 100644 --- a/include/linux/lockref.h +++ b/include/linux/lockref.h @@ -50,6 +50,8 @@ void lockref_get(struct lockref *lockref); int lockref_put_return(struct lockref *lockref); bool lockref_get_not_zero(struct lockref *lockref); bool lockref_put_or_lock(struct lockref *lockref); +#define lockref_put_or_lock(_lockref) \ + (!__cond_lock((_lockref)->lock, !lockref_put_or_lock(_lockref))) =20 void lockref_mark_dead(struct lockref *lockref); bool lockref_get_not_dead(struct lockref *lockref); diff --git a/lib/lockref.c b/lib/lockref.c index 5d8e3ef3860e..9210fc6ae714 100644 --- a/lib/lockref.c +++ b/lib/lockref.c @@ -105,6 +105,7 @@ EXPORT_SYMBOL(lockref_put_return); * @lockref: pointer to lockref structure * Return: 1 if count updated successfully or 0 if count <=3D 1 and lock t= aken */ +#undef lockref_put_or_lock bool lockref_put_or_lock(struct lockref *lockref) { CMPXCHG_LOOP( --=20 2.47.3