Linux CXL
 help / color / mirror / Atom feed
* [PATCH] cleanup: Fix unused guard error function with DEFINE_CLASS_IS_COND_GUARD
@ 2025-08-04 22:09 Dan Williams
  2025-08-05 22:38 ` Andy Shevchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Dan Williams @ 2025-08-04 22:09 UTC (permalink / raw)
  To: dave.jiang
  Cc: linux-kernel, linux-cxl, Nathan Chancellor,
	Peter Zijlstra (Intel), Linus Torvalds, David Lechner,
	Jonathan Cameron, Andy Shevchenko

Andy reports that the "lock_timer" scheme in kernel/time/posix-timers.c,
with its custom usage of DEFINE_CLASS_IS_COND_GUARD(), results in:

kernel/time/posix-timers.c:89:1: error: unused function 'class_lock_timer_lock_err' [-Werror,-Wunused-function]
   89 | DEFINE_CLASS_IS_COND_GUARD(lock_timer);

...with a clang W=1 build. Per Nathan, clang catches unused "static inline"
functions in C files since commit 6863f5643dd7 ("kbuild: allow Clang to
find unused static inline functions for W=1 build").

There are 2 ways to solve this, either mark the class_##_lock_err()
function as __maybe_unused, or make sure class_##_lock_err() *is* used /
gets called to disposition the lock status.

At present __lock_timer() only indicates failure with a NULL __guard_ptr().
However, one could imagine that __lock_timer(), or some other custom
conditional locking primitive, wants to pass an ERR_PTR() to indicate the
reason for the lock acquisition failure.

Update __scoped_cond_guard() to check for ERR_PTR() in addition to NULL
@scope values. This allows __lock_timer(), or another open coded
DEFINE_CLASS_IS_COND_GUARD() user, to switch to passing an ERR_PTR() in the
future. In the meantime, this just silences the warning.

Cc: Nathan Chancellor <nathan@kernel.org>
Cc: "Peter Zijlstra (Intel)" <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: David Lechner <dlechner@baylibre.com>
Cc: Jonathan Cameron <jonathan.cameron@huawei.com>
Reported-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Closes: http://lore.kernel.org/aIo18KZpmKuR4hVZ@black.igk.intel.com
Fixes: 857d18f23ab1 ("cleanup: Introduce ACQUIRE() and ACQUIRE_ERR() for conditional locks")
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
Dave, I am sending this to you to take upstream since the warning came
in through the CXL tree. If anyone else wants to take it just holler.

 include/linux/cleanup.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/linux/cleanup.h b/include/linux/cleanup.h
index 4eb83dd71cfe..d8e7d1e5561b 100644
--- a/include/linux/cleanup.h
+++ b/include/linux/cleanup.h
@@ -423,7 +423,8 @@ _label:									\
 
 #define __scoped_cond_guard(_name, _fail, _label, args...)		\
 	for (CLASS(_name, scope)(args); true; ({ goto _label; }))	\
-		if (!__guard_ptr(_name)(&scope)) {			\
+		if (!__guard_ptr(_name)(&scope) ||			\
+		     __guard_err(_name)(&scope)) {			\
 			BUILD_BUG_ON(!__is_cond_ptr(_name));		\
 			_fail;						\
 _label:									\

base-commit: 857d18f23ab17284d1b6de6f61f4e74958596376
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-08-13 21:45 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-04 22:09 [PATCH] cleanup: Fix unused guard error function with DEFINE_CLASS_IS_COND_GUARD Dan Williams
2025-08-05 22:38 ` Andy Shevchenko
2025-08-11 22:56   ` dan.j.williams
2025-08-13 13:46     ` Andy Shevchenko
2025-08-09  9:46 ` Andy Shevchenko
2025-08-13 14:13 ` Peter Zijlstra
2025-08-13 15:14   ` Linus Torvalds
2025-08-13 15:21     ` Peter Zijlstra
2025-08-13 15:27       ` Linus Torvalds
2025-08-13 21:45     ` Andy Shevchenko
2025-08-13 18:57   ` dan.j.williams

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox