From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: dan.j.williams@intel.com
Cc: dave.jiang@intel.com, linux-kernel@vger.kernel.org,
linux-cxl@vger.kernel.org, Nathan Chancellor <nathan@kernel.org>,
"Peter Zijlstra (Intel)" <peterz@infradead.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
David Lechner <dlechner@baylibre.com>,
Jonathan Cameron <jonathan.cameron@huawei.com>
Subject: Re: [PATCH] cleanup: Fix unused guard error function with DEFINE_CLASS_IS_COND_GUARD
Date: Wed, 13 Aug 2025 16:46:50 +0300 [thread overview]
Message-ID: <aJyXSrgZCU8r4bJ8@smile.fi.intel.com> (raw)
In-Reply-To: <689a750ad41b2_50ce10064@dwillia2-xfh.jf.intel.com.notmuch>
On Mon, Aug 11, 2025 at 03:56:10PM -0700, dan.j.williams@intel.com wrote:
> Andy Shevchenko wrote:
> > On Mon, Aug 04, 2025 at 03:09:54PM -0700, Dan Williams wrote:
> > > 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.
> >
> > Hmm... It seems fixes the timer case, but left others still fail:
> >
> > drivers/pwm/core.c:54:1: error: unused function 'class_pwmchip_lock_err' [-Werror,-Wunused-function]
> > 54 | DEFINE_GUARD(pwmchip, struct pwm_chip *, pwmchip_lock(_T), pwmchip_unlock(_T))
> > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > include/linux/cleanup.h:380:2: note: expanded from macro 'DEFINE_GUARD'
> > 380 | DEFINE_CLASS_IS_GUARD(_name)
> > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > include/linux/cleanup.h:372:2: note: expanded from macro 'DEFINE_CLASS_IS_GUARD'
> > 372 | __DEFINE_GUARD_LOCK_PTR(_name, _T)
> > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > include/linux/cleanup.h:358:20: note: expanded from macro '__DEFINE_GUARD_LOCK_PTR'
> > 358 | static inline int class_##_name##_lock_err(class_##_name##_t *_T) \
> > | ^~~~~~~~~~~~~~~~~~~~~~~~
> > <scratch space>:81:1: note: expanded from here
> > 81 | class_pwmchip_lock_err
> > | ^~~~~~~~~~~~~~~~~~~~~~
> > 1 error generated.
>
> Ok, so in these cases where the guard is unconditional, the _lock_err()
> method can be safely ignored. Here is a quick patch (below), only gcc
> compile tested, that tries to quiet the warning for unconditional
> guards, but keep the warning for conditional guards.
>
> If you have some time to try it out, great, otherwise I will circle back
> with a clang W=1 compile test before submitting the formal patch:
I have applied it on top of the previous (incomplete) solution and tried on two
branches, one is based on v6.17-rc1 and the other on Linux Next. I do not see
problem anymore.
Tested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2025-08-13 13:46 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aJyXSrgZCU8r4bJ8@smile.fi.intel.com \
--to=andriy.shevchenko@intel.com \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=dlechner@baylibre.com \
--cc=jonathan.cameron@huawei.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nathan@kernel.org \
--cc=peterz@infradead.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.