Re: [PATCH v1] PM: Discard runtime_xx() handles using pm_ptr()
From: Paul Cercueil
Date: Thu Feb 20 2025 - 07:23:44 EST
Hi Raag,
Le jeudi 20 février 2025 à 13:33 +0530, Raag Jadav a écrit :
> Discard runtime_xx() handles in RUNTIME_PM_OPS() using pm_ptr() macro
> and drop unnecessary CONFIG_PM ifdeffery.
So the RUNTIME_PM_OPS() is newer and people should use that, but we're
not yet at the point where the older SET_RUNTIME_PM_OPS() macro can be
dropped.
The difference is that in the !CONFIG_PM case, the former will
reference the suspend/resume functions, but they will be detected as
dead code; on the other hand, the latter macro won't reference them at
all. Many drivers still wrap their suspend/resume functions in a #ifdef
CONFIG_PM to avoid warnings about unused static functions. Therefore if
you unconditionally force the use of the first macro everywhere, many
drivers will fail to compile in the !CONFIG_PM case.
As for adding pm_ptr() inside RUNTIME_PM_OPS(), it is unnecesary, as
the whole pm_ops struct should be referenced through pm_ptr() or
pm_sleep_ptr() anyway, which means that the whole struct and the
callback functions will be garbage-collected if PM is disabled.
Cheers,
-Paul
> Signed-off-by: Raag Jadav <raag.jadav@xxxxxxxxx>
> ---
> PS: I'm not very confident about this but thought I'd give it a try.
>
> include/linux/pm.h | 10 +++-------
> 1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/include/linux/pm.h b/include/linux/pm.h
> index 78855d794342..416561c60e81 100644
> --- a/include/linux/pm.h
> +++ b/include/linux/pm.h
> @@ -334,9 +334,9 @@ struct dev_pm_ops {
> .restore_noirq = pm_sleep_ptr(resume_fn),
>
> #define RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
> - .runtime_suspend = suspend_fn, \
> - .runtime_resume = resume_fn, \
> - .runtime_idle = idle_fn,
> + .runtime_suspend = pm_ptr(suspend_fn), \
> + .runtime_resume = pm_ptr(resume_fn), \
> + .runtime_idle = pm_ptr(idle_fn),
>
> #ifdef CONFIG_PM_SLEEP
> #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
> @@ -359,12 +359,8 @@ struct dev_pm_ops {
> #define SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn)
> #endif
>
> -#ifdef CONFIG_PM
> #define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
> RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn)
> -#else
> -#define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn)
> -#endif
>
> #define _DEFINE_DEV_PM_OPS(name, \
> suspend_fn, resume_fn, \