Re: [PATCH] PM: Add EXPORT macros for exporting PM functions
From: Rafael J. Wysocki
Date: Mon Feb 13 2023 - 10:44:14 EST
On Mon, Feb 13, 2023 at 2:20 PM Richard Fitzgerald
<rf@xxxxxxxxxxxxxxxxxxxxx> wrote:
>
> Add a set of macros for exporting functions only if CONFIG_PM
> is enabled.
>
> The naming follows the style of the standard EXPORT_SYMBOL_*()
> macros that they replace.
>
> Sometimes a module wants to export PM functions directly to other
> drivers, not a complete struct dev_pm_ops. A typical example is
> where a core library exports the generic (shared) implementation
> and calling code wraps one or more of these in custom code.
>
> Signed-off-by: Richard Fitzgerald <rf@xxxxxxxxxxxxxxxxxxxxx>
> ---
> include/linux/pm.h | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/include/linux/pm.h b/include/linux/pm.h
> index 93cd34f00822..21618f7087f8 100644
> --- a/include/linux/pm.h
> +++ b/include/linux/pm.h
> @@ -379,9 +379,17 @@ const struct dev_pm_ops name = { \
> const struct dev_pm_ops name; \
> __EXPORT_SYMBOL(name, sec, ns); \
> const struct dev_pm_ops name
> +#define EXPORT_PM_FN(name) EXPORT_SYMBOL(name)
> +#define EXPORT_PM_FN_GPL(name) EXPORT_SYMBOL_GPL(name)
> +#define EXPORT_PM_FN_NS(name, ns) EXPORT_SYMBOL_NS(name, ns)
> +#define EXPORT_PM_FN_NS_GPL(name, ns) EXPORT_SYMBOL_NS_GPL(name, ns)
Why are the non-GPL variants needed?
> #else
> #define _EXPORT_DEV_PM_OPS(name, sec, ns) \
> static __maybe_unused const struct dev_pm_ops __static_##name
> +#define EXPORT_PM_FN(name)
> +#define EXPORT_PM_FN_GPL(name)
> +#define EXPORT_PM_FN_NS(name, ns)
> +#define EXPORT_PM_FN_NS_GPL(name, ns)
> #endif
>
> #define EXPORT_DEV_PM_OPS(name) _EXPORT_DEV_PM_OPS(name, "", "")
> --
> 2.30.2
>