From nobody Thu Dec 18 01:19:08 2025 Received: from verein.lst.de (verein.lst.de [213.95.11.211]) (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 37006223DD4 for ; Tue, 9 Dec 2025 08:19:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.95.11.211 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765268344; cv=none; b=mpFJWRRkMSsEvlgt4zeaczqsAU5gierEtxn7a8KlHo104brVa/lam7IR5smP24xRM1sjv/Bp219ZbRAcN9MW9T7fE0Y7hTwPaWrCEesJwLXEwPCuQFjiIN9okL9FoCpzI9I6x797VypxONd+0CUk29r0/wipCF9g9cyuJuQrVUM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765268344; c=relaxed/simple; bh=r/uqBMYDJa/fas1EwBxrd/A4yvVhhn7Ef3IeJ1TXd9U=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=g+lSRj71lB6TD6dRFQigH5cDkuwASt2v36GakehETK9dpzSNHXEWq4gLaaD31C2jzajC1EL8Xx7Pk4Ya0WX+wK2ASImr4OUes1kpGQ59B8IPsLu8LDFX+WihQkTaWgkv2/vjv5od9vaZ7b6fUl5JH2nJqbIpWh+r/IPOmSbi8zs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lst.de; spf=pass smtp.mailfrom=lst.de; arc=none smtp.client-ip=213.95.11.211 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lst.de Received: by verein.lst.de (Postfix, from userid 2407) id 54DD2227A87; Tue, 9 Dec 2025 09:18:57 +0100 (CET) Date: Tue, 9 Dec 2025 09:18:57 +0100 From: Christoph Hellwig To: Andrew Morton , Linus Torvalds Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2, resend] lockref: add a __cond_lock annotation for lockref_put_or_lock Message-ID: <20251209081857.GA4290@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.17 (2007-11-01) Content-Transfer-Encoding: quoted-printable 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 --- 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