From nobody Mon May 25 05:12:10 2026 Received: from mail.ilvokhin.com (mail.ilvokhin.com [178.62.254.231]) (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 39160303CAE for ; Mon, 18 May 2026 15:21:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.62.254.231 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779117718; cv=none; b=hjw8x/YdCfOW3UmEUK+W/xdmzWX2wEACnDxANdunwBe3N6q0h4t+ShGkmEHq6ZZoGF+6+L0A+GxRV35d/HT8emrRIJbT8y9qKNwvv//sSnHmdU17WWZSksR0/SYm52aaAZGWYZy3Z2yA3pUtgE9tHZpxuud/g2/2/kIHp7ejbAM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779117718; c=relaxed/simple; bh=zcHp3n63a3QsoIUutd2eye1a+SLKUE2Vcpi8JETNKyo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uw7WTeNXUt7EXnvpmAO1EzeFMryxgu0L77oNdbsZfvhdTFs8F1yfwKc1orMjfpmtqLiIMi2/vfVMCJjSemKVFeO4fyml0vFwQOZU9dZ1B3ZRjTl0IJKe5vHHrOntr9CY3CPYvf37bXgeBZa4rDixDvxqZJN6Y9wu8bH/u8CJEIg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ilvokhin.com; spf=pass smtp.mailfrom=ilvokhin.com; dkim=pass (1024-bit key) header.d=ilvokhin.com header.i=@ilvokhin.com header.b=zPA0jU0R; arc=none smtp.client-ip=178.62.254.231 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ilvokhin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ilvokhin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ilvokhin.com header.i=@ilvokhin.com header.b="zPA0jU0R" Received: from localhost.localdomain (shell.ilvokhin.com [138.68.190.75]) (Authenticated sender: d@ilvokhin.com) by mail.ilvokhin.com (Postfix) with ESMTPSA id 19B50D073D; Mon, 18 May 2026 15:21:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ilvokhin.com; s=mail; t=1779117709; bh=tmv/EHoh0GLlM8m0HYlN08j4c0ckx3H1OLOI21Bitic=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=zPA0jU0R/m+ol8oLMrRer/bHnOl9a2bstPnmlU+1e0MAPDzqw/JxKdoHjc36juMHE kf9RwbsFiX5QzNE4ZSSnsRgDCJpTfiTtRSHN0zh5aJeH0OdMjVlIWemixl1BMLSR7h dTIChYA8rng8OBhmSaRffT3gMzKBp0q5Y00eFCe8= From: Dmitry Ilvokhin To: Peter Zijlstra , Dan Williams , Vishal Verma , Dave Jiang , Ira Weiny , Miguel Ojeda , Thomas Gleixner , Christian Brauner , Marco Elver , "H. Peter Anvin" , Andrew Morton Cc: nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kernel-team@meta.com, Dmitry Ilvokhin Subject: [PATCH v3 1/4] nvdimm: Convert nvdimm_bus guard to class Date: Mon, 18 May 2026 15:21:27 +0000 Message-ID: <9857a934214db3460bf55a56e152dedfa1d8bd01.1779116497.git.d@ilvokhin.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: References: 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 Content-Type: text/plain; charset="utf-8" The nvdimm_bus guard accepts NULL and skips locking when NULL is passed. Convert from DEFINE_GUARD() to DEFINE_CLASS() + DEFINE_CLASS_IS_GUARD(). This is a preparatory change for making DEFINE_GUARD() constructors __nonnull(). nvdimm_bus legitimately passes NULL, so it must be adjusted to avoid a compile error. No functional change. Signed-off-by: Dmitry Ilvokhin Reviewed-by: Dave Jiang --- drivers/nvdimm/nd.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/nvdimm/nd.h b/drivers/nvdimm/nd.h index b199eea3260e..18b64559664b 100644 --- a/drivers/nvdimm/nd.h +++ b/drivers/nvdimm/nd.h @@ -632,8 +632,11 @@ u64 nd_region_interleave_set_cookie(struct nd_region *= nd_region, u64 nd_region_interleave_set_altcookie(struct nd_region *nd_region); void nvdimm_bus_lock(struct device *dev); void nvdimm_bus_unlock(struct device *dev); -DEFINE_GUARD(nvdimm_bus, struct device *, - if (_T) nvdimm_bus_lock(_T), if (_T) nvdimm_bus_unlock(_T)); +DEFINE_CLASS(nvdimm_bus, struct device *, + if (_T) nvdimm_bus_unlock(_T), + ({ if (_T) nvdimm_bus_lock(_T); _T; }), + struct device *_T); +DEFINE_CLASS_IS_GUARD(nvdimm_bus); =20 bool is_nvdimm_bus_locked(struct device *dev); void nvdimm_check_and_set_ro(struct gendisk *disk); --=20 2.53.0-Meta From nobody Mon May 25 05:12:10 2026 Received: from mail.ilvokhin.com (mail.ilvokhin.com [178.62.254.231]) (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 F06B1378818 for ; Mon, 18 May 2026 15:21:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.62.254.231 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779117718; cv=none; b=uJuOVu5O9bCNlUOhMgc7MkHt6tq97qY9ad4L0+KbrkdseQZg8GCVwCIAZ7khclxRsUPlXQuHcubjuMAzMAWhdAUvFKFWBLA0w+SItpo0SIE3TKT8D/LrnAoR2AX5s1XlO4C1c8hU6Rb9QsvqJKObNVmg7Zi13bfKw4wilX+zW30= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779117718; c=relaxed/simple; bh=rDf3nABXNo8vMeXp5HldaYDR5skbzeT8SXMZO6GsOxo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GtbXohN2w1YEWYJryxPoOMoiq5q4EG6UU9DsOg9U6OXxCnQuUVdQmI0bp6bdWuIguB8UNbf3tkwbo7b5gD/5wUFvL8e+F73pD2k4xmgz/yoBsqTMpkqDUH6VXMIpJWwVP9mPjLM3rFh6JL1qnaNqEdyOz4vIAvVe6Q6oXrfgAaI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ilvokhin.com; spf=pass smtp.mailfrom=ilvokhin.com; dkim=pass (1024-bit key) header.d=ilvokhin.com header.i=@ilvokhin.com header.b=FoPfZBRK; arc=none smtp.client-ip=178.62.254.231 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ilvokhin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ilvokhin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ilvokhin.com header.i=@ilvokhin.com header.b="FoPfZBRK" Received: from localhost.localdomain (shell.ilvokhin.com [138.68.190.75]) (Authenticated sender: d@ilvokhin.com) by mail.ilvokhin.com (Postfix) with ESMTPSA id 594EAD0741; Mon, 18 May 2026 15:21:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ilvokhin.com; s=mail; t=1779117709; bh=lDIPRhu4eC69IHX//CJMd4ihavt8RgvIqQIf1iXGap8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=FoPfZBRKk/Xz6V2KhS51m8PYmgYq3qDvs9vficc4yQIspPA0e0U7tT1/2OmDpkxI4 pkcxEeDdybg+5nIzUt1Hi9g9qW0BfPg1IsGMUxnB6PAiNHQQXYqnLlwqBI9/Hyfpg0 D8IosIIvyZzxJJs78s2F/el3VNxnwtsjo43I0MM4= From: Dmitry Ilvokhin To: Peter Zijlstra , Dan Williams , Vishal Verma , Dave Jiang , Ira Weiny , Miguel Ojeda , Thomas Gleixner , Christian Brauner , Marco Elver , "H. Peter Anvin" , Andrew Morton Cc: nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kernel-team@meta.com, Dmitry Ilvokhin Subject: [PATCH v3 2/4] genirq: Move NULL check into irqdesc_lock guard unlock expression Date: Mon, 18 May 2026 15:21:28 +0000 Message-ID: <7509b85e0f75cf4388d2fd89b6e7fc8ff5e1b01f.1779116497.git.d@ilvokhin.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: References: 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 Content-Type: text/plain; charset="utf-8" irqdesc_lock uses __DEFINE_UNLOCK_GUARD() directly with a custom constructor that can set .lock to NULL. In preparation for removing the NULL check from __DEFINE_UNLOCK_GUARD(), move the NULL check into the irqdesc_lock unlock expression, making the NULL handling explicit at the call site. No functional change. Signed-off-by: Dmitry Ilvokhin --- kernel/irq/internals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h index 9412e57056f5..347cb333b9fe 100644 --- a/kernel/irq/internals.h +++ b/kernel/irq/internals.h @@ -171,7 +171,7 @@ void __irq_put_desc_unlock(struct irq_desc *desc, unsig= ned long flags, bool bus) =20 __DEFINE_CLASS_IS_CONDITIONAL(irqdesc_lock, true); __DEFINE_UNLOCK_GUARD(irqdesc_lock, struct irq_desc, - __irq_put_desc_unlock(_T->lock, _T->flags, _T->bus), + if (_T->lock) __irq_put_desc_unlock(_T->lock, _T->flags, _T->bus), unsigned long flags; bool bus); =20 static inline class_irqdesc_lock_t class_irqdesc_lock_constructor(unsigned= int irq, bool bus, --=20 2.53.0-Meta From nobody Mon May 25 05:12:10 2026 Received: from mail.ilvokhin.com (mail.ilvokhin.com [178.62.254.231]) (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 F33EB378821 for ; Mon, 18 May 2026 15:21:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.62.254.231 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779117718; cv=none; b=f7UlFBrt8DzmnnRd8/yb1gt4oxfTKRbZT9AylqRlz4NnocInGTMF5vCV8v2Rg8O1youagI8AEJv7q7opGuF+CP/h0kzu8Pqs84hrYcgUjKnp6RBtM1sYO4WJW3biYknC7drf6jl9Jv0V+XF8dsg596Oai30bVV5Q1nK1SihlDPg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779117718; c=relaxed/simple; bh=V4q/SYkOeuRKvJr2ZtDhjkO/nACQTKyR+XkRLC8de9o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jJ+bGTdIEwdWQp9xmmNH19NisPIAWS2PaDksYPpAUArdCUqxt5ICvigwpusvE62Pxrs+6rnO65dDnvz++78SNC4sv7avXAJlCZEWEX6MlFseU/dJyZ4xlecUkc01yZJi+JSgGzqmCs2l9RMJmlh/t272DF70Dijdm6UyHR4zviM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ilvokhin.com; spf=pass smtp.mailfrom=ilvokhin.com; dkim=pass (1024-bit key) header.d=ilvokhin.com header.i=@ilvokhin.com header.b=dLKjMx8C; arc=none smtp.client-ip=178.62.254.231 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ilvokhin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ilvokhin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ilvokhin.com header.i=@ilvokhin.com header.b="dLKjMx8C" Received: from localhost.localdomain (shell.ilvokhin.com [138.68.190.75]) (Authenticated sender: d@ilvokhin.com) by mail.ilvokhin.com (Postfix) with ESMTPSA id 929F3D0744; Mon, 18 May 2026 15:21:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ilvokhin.com; s=mail; t=1779117709; bh=N2a1OThy1n23ro/uvU4wqNdlrb58ANUh0JllmehKuio=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=dLKjMx8CbTCWtm9Ls3ZrjaABN5yHjxKv24qBFc5UFxy7eEghdKxMmwNR/ANgjGpXi MtLGmS9zBmTEto3IvSda78JmGobDL6sOgyzZep83eBougy+06BJgW0Li/fjFK1cdS9 VxLkBQZM8W0AxAizx9BNEWYQFu47RUXGMYuNuqlE= From: Dmitry Ilvokhin To: Peter Zijlstra , Dan Williams , Vishal Verma , Dave Jiang , Ira Weiny , Miguel Ojeda , Thomas Gleixner , Christian Brauner , Marco Elver , "H. Peter Anvin" , Andrew Morton Cc: nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kernel-team@meta.com, Dmitry Ilvokhin Subject: [PATCH v3 3/4] cleanup: Annotate guard constructors with __nonnull() Date: Mon, 18 May 2026 15:21:29 +0000 Message-ID: <1854fc006c03647a3201a442743a1c22b13b404d.1779116497.git.d@ilvokhin.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: References: 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 Content-Type: text/plain; charset="utf-8" Add __nonnull() to unconditional guard constructors so the compiler verifies at each call site that NULL is never passed: - DEFINE_GUARD(): re-declare the constructor with __nonnull(). - __DEFINE_LOCK_GUARD_1(): annotate the constructor directly. DEFINE_LOCK_GUARD_0() needs no annotation: its constructor takes no pointer arguments (.lock is hardcoded to (void *)1). This provides automated, compiler-enforced verification that no unconditional guard constructor receives NULL. Define the __nonnull() macro in compiler_attributes.h, following the existing convention for attribute wrappers. Signed-off-by: Dmitry Ilvokhin Acked-by: Miguel Ojeda --- include/linux/cleanup.h | 4 +++- include/linux/compiler_attributes.h | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/linux/cleanup.h b/include/linux/cleanup.h index ea95ca4bc11c..8f8d588b5595 100644 --- a/include/linux/cleanup.h +++ b/include/linux/cleanup.h @@ -397,6 +397,7 @@ static __maybe_unused const bool class_##_name##_is_con= ditional =3D _is_cond __DEFINE_GUARD_LOCK_PTR(_name, _T) =20 #define DEFINE_GUARD(_name, _type, _lock, _unlock) \ + static __always_inline __nonnull() _type class_##_name##_constructor(_typ= e _T); \ DEFINE_CLASS(_name, _type, if (_T) { _unlock; }, ({ _lock; _T; }), _type = _T); \ DEFINE_CLASS_IS_GUARD(_name) =20 @@ -497,7 +498,8 @@ static __always_inline void class_##_name##_destructor(= class_##_name##_t *_T) \ __DEFINE_GUARD_LOCK_PTR(_name, &_T->lock) =20 #define __DEFINE_LOCK_GUARD_1(_name, _type, ...) \ -static __always_inline class_##_name##_t class_##_name##_constructor(_type= *l) \ +static __always_inline __nonnull() \ +class_##_name##_t class_##_name##_constructor(_type *l) \ __no_context_analysis \ { \ class_##_name##_t _t =3D { .lock =3D l }, *_T =3D &_t; \ diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_a= ttributes.h index c16d4199bf92..85f08d6137a2 100644 --- a/include/linux/compiler_attributes.h +++ b/include/linux/compiler_attributes.h @@ -176,6 +176,12 @@ */ #define __mode(x) __attribute__((__mode__(x))) =20 +/* + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.ht= ml#index-nonnull-function-attribute + * clang: https://clang.llvm.org/docs/AttributeReference.html#nonnull + */ +#define __nonnull(x...) __attribute__((__nonnull__(x))) + /* * Optional: only supported since gcc >=3D 7 * --=20 2.53.0-Meta From nobody Mon May 25 05:12:10 2026 Received: from mail.ilvokhin.com (mail.ilvokhin.com [178.62.254.231]) (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 EE6D33783A8 for ; Mon, 18 May 2026 15:21:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.62.254.231 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779117718; cv=none; b=XpWcYT27KLF/evF/Fkk0hNupX57dRVf/gpDSBCxkKdXRZOa5o17brGNP58RkLdQr54/KTTqCn74d/BbnLyHCEXIKMSOhActorv64qNVJy/B+3W4arZzVggtuBbMdTKV2IDQ8ml2vcSa0iB5Ma3gjciw0RfFEpqyjn9hnHyEx5Wk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779117718; c=relaxed/simple; bh=U46C/BpM2vEnvjIIsJtWek75An3X80SCFk7DqgK5MC4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RYEjLT6bqyPHdbOJINqm1RreAGUd2GfzrReyQVbN9yiYqPhW14JbvnAmxiFER/HbtvpauEZs6moeyAvopq5zqlKqAnd2OicvBxroBAvxPvoj1lprzcgTnkf+pW+s/MK7QZpgwCRpjKN1u2feFENvqKtQ51eGeiZ+QkPI9hpKf3A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ilvokhin.com; spf=pass smtp.mailfrom=ilvokhin.com; dkim=pass (1024-bit key) header.d=ilvokhin.com header.i=@ilvokhin.com header.b=yhlEb+F3; arc=none smtp.client-ip=178.62.254.231 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=ilvokhin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ilvokhin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ilvokhin.com header.i=@ilvokhin.com header.b="yhlEb+F3" Received: from localhost.localdomain (shell.ilvokhin.com [138.68.190.75]) (Authenticated sender: d@ilvokhin.com) by mail.ilvokhin.com (Postfix) with ESMTPSA id CEEA5D0748; Mon, 18 May 2026 15:21:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ilvokhin.com; s=mail; t=1779117710; bh=H0ERgf6l48k7n+RO+vxMZwZ2/ZJGp5WzvOOMr4YqH/g=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=yhlEb+F3dkiBTEdGUmXOrLopbvO2vdxDXaIMh60I5Zs+WRbdQf6tiMg/lbqqujfQQ wh+OnH7kP11vAxgLRybOnRiYFjQoY5oftKGKTT5Wgd71k0uw5lBn5masXTlEmXuV2N hvUIKvvZ6T27GzOlkuGV9cYLDVa+awY/E/yx16WY= From: Dmitry Ilvokhin To: Peter Zijlstra , Dan Williams , Vishal Verma , Dave Jiang , Ira Weiny , Miguel Ojeda , Thomas Gleixner , Christian Brauner , Marco Elver , "H. Peter Anvin" , Andrew Morton Cc: nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kernel-team@meta.com, Dmitry Ilvokhin Subject: [PATCH v3 4/4] cleanup: Remove NULL check from unconditional guards Date: Mon, 18 May 2026 15:21:30 +0000 Message-ID: X-Mailer: git-send-email 2.54.0 In-Reply-To: References: 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 Content-Type: text/plain; charset="utf-8" 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 --- 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 8f8d588b5595..1f6d1a97617a 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() _type class_##_name##_constructor(_typ= e _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) --=20 2.53.0-Meta