From nobody Mon Jun 8 08:47:29 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 7CB4648B38C; Wed, 3 Jun 2026 14:25:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780496712; cv=none; b=sPJ8j7KwQyAr6koehuINUZ0/Jvdku2K9IDvC+OOLCkAD1SjhSDZ0nyW8VpyGldCTND2mxGgNgT15jw9WCadUGrpZ/mAgVrVykyrJzttpncEbcNKENvLeD2EcdjOHkpry/LS3R4dvMgHt0fKBTpo2ArY8ZB8nnZfn2ZtzWCd5Z88= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780496712; c=relaxed/simple; bh=+Pez2upMgi4+nQQxomTxpD7L5VVs12KPuyUpAsHockg=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=shuIgxmKmxOj4HzX1ZEcfUhgQ4lrXdNhMhct2j1zf5T7Doy1GnHegAuK/SyFus3hO6hgc1/yl79/HB8isKpSbuRiBI+gUFbWSlTW6Cf2oUut0j2xQIC+LBT92+2w55OU4mykRDBfzCaq0OIVmgcQa4MeE2HyDfVTg693v7EeL4Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=gRlmyXbw; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=gDq15iQe; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="gRlmyXbw"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="gDq15iQe" Date: Wed, 03 Jun 2026 14:25:07 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1780496709; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SbargHZ5EYqHNUuQKBTde24U9RgG92apRLeE/xPzcbk=; b=gRlmyXbwfrJ0DYL6I8OFSqhpuTrHdLy2qbh8x1jnzrVALQ6Dq9RrrngqgvxOs8Xrod9ylO baJ2P58wqtjGR1H/vG7M60Uk1lTqdCg1r/SFqoidOTPfh+yObWLtJ1NkCtP2x6euZ4+BJK aVRwtyw+mh0KoqHF5NlANR+ElNaTtOiczQhAj8E4H9XB4IPXMgeZnVbG0U2tMvylYwUuG2 9H0vNZPqsdwc0TkH5jWlZfoOZ/ODrab55Uu+Sz93oJwZj+I6ZLww9Nx5wi1/EMD8n7RqpL qTrHTeFTV6I1hf221q3EOjZYOmncEF2X6kqVFQh3V75O5t7P9TedghjAq/WKLQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1780496709; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SbargHZ5EYqHNUuQKBTde24U9RgG92apRLeE/xPzcbk=; b=gDq15iQe3YfYbcJ3XndTTaQ1U4g3iMzK9yZ+mmFohmNA3bXKDQfnbsK0L1Eom9TVzlDHsD fi5giOOeqG1N7gAA== From: "tip-bot2 for Dmitry Ilvokhin" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] cleanup: Remove NULL check from unconditional guards Cc: Dmitry Ilvokhin , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <0503a089389b2270c478a873e095cf0a4ff26d24.1780064327.git.d@ilvokhin.com> References: <0503a089389b2270c478a873e095cf0a4ff26d24.1780064327.git.d@ilvokhin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <178049670778.710.17702813837987687303.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the locking/core branch of tip: Commit-ID: a13ab9dd6eb2a89f14b466c3884730ea7969253f Gitweb: https://git.kernel.org/tip/a13ab9dd6eb2a89f14b466c3884730ea7= 969253f Author: Dmitry Ilvokhin AuthorDate: Tue, 02 Jun 2026 07:12:53=20 Committer: Peter Zijlstra CommitterDate: Wed, 03 Jun 2026 11:38:48 +02:00 cleanup: Remove NULL check from unconditional guards The unconditional guard destructors check whether the lock pointer is NULL before unlocking. This check is dead code because unconditional guards guarantee a non-NULL lock pointer at destructor time. DEFINE_GUARD() runs the lock operation unconditionally in the constructor. If the pointer were NULL, the lock operation (e.g. mutex_lock(NULL)) would crash before the constructor returns. The destructor never runs with a NULL pointer. All DEFINE_GUARD() users dereference the pointer in their lock. Verified by auditing every instance found by: git grep -n -A 1 'DEFINE_GUARD('. The only exception is xe_pm_runtime_release_only, whose constructor is a noop, but it has no callers. __DEFINE_UNLOCK_GUARD() has only a few usages outside of include/linux/cleanup.h: tty_port_tty (NULL-checks in its tty_kref_put() call), irqdesc_lock (fixed earlier) and two guards in kernel/sched/sched.h (dereference the pointer unconditionally in their lock constructors). DEFINE_LOCK_GUARD_1() sets .lock from its argument and runs the lock operation in the constructor. Same reasoning applies. All DEFINE_LOCK_GUARD_1() users dereference the pointer in their lock. Also, verified by auditing every match of: git grep -n 'DEFINE_LOCK_GUARD_1('. DEFINE_LOCK_GUARD_0() hardcodes .lock =3D (void *)1 in the constructor, so it is never NULL by construction. Conditional (_try) variants: DEFINE_GUARD_COND() and DEFINE_LOCK_GUARD_1_COND() use EXTEND_CLASS_COND(), whose wrapper destructor returns early when the lock was not acquired, before reaching the base destructor since commit 2deccd5c862a ("cleanup: Optimize guards"): if (_cond) return; class_##_name##_destructor(_T); As compiled by GCC-11 with defconfig on top of the locking/core: Total: Before=3D23889980, After=3D23834334, chg -0.23% Signed-off-by: Dmitry Ilvokhin Signed-off-by: Peter Zijlstra (Intel) Link: https://patch.msgid.link/0503a089389b2270c478a873e095cf0a4ff26d24.178= 0064327.git.d@ilvokhin.com --- include/linux/cleanup.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/cleanup.h b/include/linux/cleanup.h index 4e60d51..6541693 100644 --- a/include/linux/cleanup.h +++ b/include/linux/cleanup.h @@ -398,7 +398,7 @@ static __maybe_unused const bool class_##_name##_is_con= ditional =3D _is_cond =20 #define DEFINE_GUARD(_name, _type, _lock, _unlock) \ static __always_inline __nonnull_args() _type class_##_name##_constructor= (_type _T); \ - DEFINE_CLASS(_name, _type, if (_T) { _unlock; }, ({ _lock; _T; }), _type = _T); \ + DEFINE_CLASS(_name, _type, _unlock, ({ _lock; _T; }), _type _T); \ DEFINE_CLASS_IS_GUARD(_name) =20 #define DEFINE_GUARD_COND_4(_name, _ext, _lock, _cond) \ @@ -492,7 +492,7 @@ typedef struct { \ static __always_inline void class_##_name##_destructor(class_##_name##_t *= _T) \ __no_context_analysis \ { \ - if (_T->lock) { _unlock; } \ + _unlock; \ } \ \ __DEFINE_GUARD_LOCK_PTR(_name, &_T->lock)