From nobody Sun May 24 21:36:40 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 7B456349B0D for ; Thu, 21 May 2026 07:18:22 +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=1779347905; cv=none; b=Hx7YbfEYLmaOBP+tt0N8lM7tuiRQ4X4E8THp392AP/d/I72rkJ3+1qHc9HdvVuxUYNIgc1GdFqz9aZXJ7b+8wp+oQTiJBfy2xmiYn9GynZ+QXqIFY9pS1x2EnNbUjoxElmZgNLQ+1pmmeyvK6qwFbzPXBjGuF2FFG0Y4eeCVQD4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779347905; c=relaxed/simple; bh=yd6KVH6vUWWUGg3sDMJlbIEWN9cPpXA4s/gaVmF7Auo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cPsJicH8e7x8nX54TNhh4XzeARt+5FIHmKHlh0ttCik+EAWASwG9El3P84VLF7fMrdtVHJIFvnSDKAXuXmfdVQ301LaxHWmj2M3qBbEzX9OCEpbg7kGSKIK1OQdtlS5X97z//QLPTm5HYvMD2GmLjLBsbr3iR4BhK2JBz+Cbqbw= 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=nfCJgFXK; 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="nfCJgFXK" Received: from localhost.localdomain (shell.ilvokhin.com [138.68.190.75]) (Authenticated sender: d@ilvokhin.com) by mail.ilvokhin.com (Postfix) with ESMTPSA id AB5FFD0926; Thu, 21 May 2026 07:18:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ilvokhin.com; s=mail; t=1779347900; bh=AUiMwLPfpXogrlps4hAMsldk7b0PjeII3oCxeSA5XjU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=nfCJgFXKThvMlVfobGHCKnep/wprKEp3k0Djg2QHgMi8kJQMDGP9pAQ+kTrjAqEd4 R8O927B73xTHAZyykoiViMyRIYkdEDodj5XzUW1cv/zADJSvhBU/EzajYdrrk6lYQf mexHnZt3e1t807eH/ceFSr7vod7GS4ZfH244GmCU= 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 v4 1/4] nvdimm: Convert nvdimm_bus guard to class Date: Thu, 21 May 2026 07:18:01 +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 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 Sun May 24 21:36:40 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 C54E034EEF7 for ; Thu, 21 May 2026 07:18:22 +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=1779347904; cv=none; b=aOiRkUaCkzf3lGvod5Nkv5K/opOunU+kZg7ykgxRL2wCnRAXCl7v5PN1nbtm10IhovF0rfv3oE0krz10RVynOhr6b/BPet9VxIoMNKfo0Bv0ce2B0Fb7fSX7JQiZldMkOKZapQcJ++GcgUMyQnnhq9FiXhQfNB4GGDYZ5jjF0V4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779347904; c=relaxed/simple; bh=rDf3nABXNo8vMeXp5HldaYDR5skbzeT8SXMZO6GsOxo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rzGW3C6rC7QTAd7NchpWyeLh9T6qtrurAXPe9A+cwMYkGb8EqZC9Sd6PwPT7HWzPvX/QntjgpZL5jstzMQCmShOhYNwiXvC1bDhckmY81pA1PdgSitCNRZTfFJfueGlE4N/V85IxU7BFXZkk66OpYaXKWg9JyAYDLjpmnO30WTQ= 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=etH6b9Zu; 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="etH6b9Zu" Received: from localhost.localdomain (shell.ilvokhin.com [138.68.190.75]) (Authenticated sender: d@ilvokhin.com) by mail.ilvokhin.com (Postfix) with ESMTPSA id 04328D092B; Thu, 21 May 2026 07:18:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ilvokhin.com; s=mail; t=1779347901; bh=lDIPRhu4eC69IHX//CJMd4ihavt8RgvIqQIf1iXGap8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=etH6b9ZuDhqX5Sc5pXZJL0mvSO27yOgyFftApBQDRLpChk0d76J/dnjr9Me92J7s/ ZJKGaD44Ap9wM7bVcPGgw4E281DFuplUA3GHeDd8MZtjlQNmb8BgD1KF11wYyDYbZJ iR8eQxFuk+u4YlwUZ/kmzMnnQhVm73DDT+RmYKNA= 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 v4 2/4] genirq: Move NULL check into irqdesc_lock guard unlock expression Date: Thu, 21 May 2026 07:18:02 +0000 Message-ID: <2b4e1f690f12c8fb58f286846037c0f6d9656c46.1779286416.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 Sun May 24 21:36:40 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 14BFD377EBF for ; Thu, 21 May 2026 07:18:23 +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=1779347904; cv=none; b=F4sndlLKfpxFtoYadtespcQr7+J3EUBqbphJhBudfo/2yLcQUcyxadgkjGdylaHchxjgH3R4lmlY/gGArNUSnm8269h9JFD4J0HyjR7X3etReI6SjsiJiO8fRswGhoetzj+Otokv6n33benqeNLOMK3NmfbKaBVeisjt6uoj3PA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779347904; c=relaxed/simple; bh=/B5HMV10BlZCudz8MDHeJBUBcrR5exaW2uy8l9BUG3Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TWgOXgSP5nWPA6XKJ51kpOJiGjkCU9DoZiW8XxAQVfZggGST486cP3ZI2+ot8MQrc36XHrS2xORsCUv4+8f6ctcOjxHy5BenrsbQv9Jps5CftedNxZN0FmR2lHa8xNaGTD/mJrQGBE5ZDhb+yR8sbwMrdlBvvGtjQDv5GKeNFUs= 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=0BhumtCI; 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="0BhumtCI" Received: from localhost.localdomain (shell.ilvokhin.com [138.68.190.75]) (Authenticated sender: d@ilvokhin.com) by mail.ilvokhin.com (Postfix) with ESMTPSA id 4FE9DD0930; Thu, 21 May 2026 07:18:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ilvokhin.com; s=mail; t=1779347901; bh=3PMlovbl5QDd8E52nk+/Gka5Rv5cUQE0QYmiAeICQTo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=0BhumtCI3qt/nu8cGcm5GhsrGynk+LBJqztZWuBaRC6ZU7E3w2/aFMfW3XWci4t0v +WKKnawSUSNlXv4McrTVCMJDXWM7Q4XyokhEhZhLyFTx5Ja7s8P+2G6vW536CZ9o5T 6+Nd9cVrtY2tOdDJls1rqKmQ/uWjk/vjDc2oYFa4= 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 v4 3/4] cleanup: Annotate guard constructors with __nonnull() Date: Thu, 21 May 2026 07:18:03 +0000 Message-ID: <0ab092c41e18e6a7db703547d87e6b632d6f79b2.1779286416.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 warns when NULL is statically known to be 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). 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..10a1410eb3e2 100644 --- a/include/linux/compiler_attributes.h +++ b/include/linux/compiler_attributes.h @@ -230,6 +230,12 @@ */ #define noinline __attribute__((__noinline__)) =20 +/* + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Attributes.html#index-= nonnull + * clang: https://clang.llvm.org/docs/AttributeReference.html#nonnull + */ +#define __nonnull(x...) __attribute__((__nonnull__(x))) + /* * Optional: only supported since gcc >=3D 8 * Optional: not supported by clang --=20 2.53.0-Meta From nobody Sun May 24 21:36:40 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 7D4FE394EA6 for ; Thu, 21 May 2026 07:18:23 +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=1779347905; cv=none; b=JSdMde8VAGBk/QqTOECRPul9oBUmPCCgbrqv0eDh1FGQucUkS6G0qIQIfMF8pmWxYwCnLalSwwDPHjxQVS9zityLxxg0ctoKJHMs+xBCNhjmGeG9GuskZZL1dEpYBqaC1+wwylw0DI+ibTL5HqWzsXmkU3ga4wuExqFI7Yxc/mM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779347905; c=relaxed/simple; bh=U46C/BpM2vEnvjIIsJtWek75An3X80SCFk7DqgK5MC4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jOrfWUjU26nlVmxM+t4evb2dZhRVQvoafJsTdoHOAIAAbgyDnygEJpfkYdMc7dre98HRuDCIX5q55/GZogvcqFQo6rx2Lt17ZIDq0uCe8PAekCOy19crqnb5lNlTmAAzGOJFoZFYuz9grW9zdqtLghvB4XA5s41hpJHqhRC/MDU= 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=QDgkMVRC; 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="QDgkMVRC" Received: from localhost.localdomain (shell.ilvokhin.com [138.68.190.75]) (Authenticated sender: d@ilvokhin.com) by mail.ilvokhin.com (Postfix) with ESMTPSA id 99B23D0933; Thu, 21 May 2026 07:18:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ilvokhin.com; s=mail; t=1779347901; bh=H0ERgf6l48k7n+RO+vxMZwZ2/ZJGp5WzvOOMr4YqH/g=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=QDgkMVRC6D/FPdZ5WacGD82YKZlOl29ltsen1a2bEaz+6Ll9g1Sos7hVApnDdCCg8 SyASYXwzIEunoEHTG+aOlGAEee0EXIDdnPQQM/OejdZ7z5I2e9QmfvI0kyCVyCHeBB l7KLHqPTrAcIosRjOtUm0GtePnWbPgIeAreHbj0g= 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 v4 4/4] cleanup: Remove NULL check from unconditional guards Date: Thu, 21 May 2026 07:18:04 +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