This macro is analogous to the infamous of_match_ptr(). If CONFIG_PM
is enabled, this macro will resolve to its argument, otherwise to NULL.
Signed-off-by: Paul Cercueil <[email protected]>
---
Notes:
v2: Remove pm_sleep_ptr() macro
include/linux/pm.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/include/linux/pm.h b/include/linux/pm.h
index e057d1fa2469..1c0eec06905d 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -374,6 +374,12 @@ const struct dev_pm_ops name = { \
SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
}
+#ifdef CONFIG_PM
+#define pm_ptr(_ptr) (_ptr)
+#else
+#define pm_ptr(_ptr) NULL
+#endif
+
/*
* PM_EVENT_ messages
*
--
2.25.1
Use the newly introduced pm_ptr() macro to simplify the code.
Signed-off-by: Paul Cercueil <[email protected]>
---
Notes:
v2: Use pm_ptr() macro instead of pm_sleep_ptr()
drivers/mmc/host/jz4740_mmc.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/drivers/mmc/host/jz4740_mmc.c b/drivers/mmc/host/jz4740_mmc.c
index fbae87d1f017..2d41e7e5ec43 100644
--- a/drivers/mmc/host/jz4740_mmc.c
+++ b/drivers/mmc/host/jz4740_mmc.c
@@ -1099,24 +1099,18 @@ static int jz4740_mmc_remove(struct platform_device *pdev)
return 0;
}
-#ifdef CONFIG_PM_SLEEP
-
-static int jz4740_mmc_suspend(struct device *dev)
+static int __maybe_unused jz4740_mmc_suspend(struct device *dev)
{
return pinctrl_pm_select_sleep_state(dev);
}
-static int jz4740_mmc_resume(struct device *dev)
+static int __maybe_unused jz4740_mmc_resume(struct device *dev)
{
return pinctrl_select_default_state(dev);
}
static SIMPLE_DEV_PM_OPS(jz4740_mmc_pm_ops, jz4740_mmc_suspend,
jz4740_mmc_resume);
-#define JZ4740_MMC_PM_OPS (&jz4740_mmc_pm_ops)
-#else
-#define JZ4740_MMC_PM_OPS NULL
-#endif
static struct platform_driver jz4740_mmc_driver = {
.probe = jz4740_mmc_probe,
@@ -1124,7 +1118,7 @@ static struct platform_driver jz4740_mmc_driver = {
.driver = {
.name = "jz4740-mmc",
.of_match_table = of_match_ptr(jz4740_mmc_of_match),
- .pm = JZ4740_MMC_PM_OPS,
+ .pm = pm_ptr(&jz4740_mmc_pm_ops),
},
};
--
2.25.1
This way, when the dev_pm_ops instance is not referenced anywhere, it
will simply be dropped by the compiler without a warning.
Signed-off-by: Paul Cercueil <[email protected]>
---
Notes:
v2: No change
include/linux/pm.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/linux/pm.h b/include/linux/pm.h
index 1c0eec06905d..5c9760f32d4f 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -351,7 +351,7 @@ struct dev_pm_ops {
* to RAM and hibernation.
*/
#define SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
-const struct dev_pm_ops name = { \
+const struct dev_pm_ops __maybe_unused name = { \
SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
}
@@ -369,7 +369,7 @@ const struct dev_pm_ops name = { \
* .runtime_resume(), respectively (and analogously for hibernation).
*/
#define UNIVERSAL_DEV_PM_OPS(name, suspend_fn, resume_fn, idle_fn) \
-const struct dev_pm_ops name = { \
+const struct dev_pm_ops __maybe_unused name = { \
SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
}
--
2.25.1
On Mon, 13 Apr 2020 at 14:32, Paul Cercueil <[email protected]> wrote:
>
> Use the newly introduced pm_ptr() macro to simplify the code.
>
> Signed-off-by: Paul Cercueil <[email protected]>
To me, the series is a step in the right direction. Perhaps there is a
better name than "pm_ptr", but that's just a nitpick.
That said, feel free to add (for all three patches in the series):
Reviewed-by: Ulf Hansson <[email protected]>
Let's see what Rafael thinks about this.
Kind regards
Uffe
> ---
>
> Notes:
> v2: Use pm_ptr() macro instead of pm_sleep_ptr()
>
> drivers/mmc/host/jz4740_mmc.c | 12 +++---------
> 1 file changed, 3 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/mmc/host/jz4740_mmc.c b/drivers/mmc/host/jz4740_mmc.c
> index fbae87d1f017..2d41e7e5ec43 100644
> --- a/drivers/mmc/host/jz4740_mmc.c
> +++ b/drivers/mmc/host/jz4740_mmc.c
> @@ -1099,24 +1099,18 @@ static int jz4740_mmc_remove(struct platform_device *pdev)
> return 0;
> }
>
> -#ifdef CONFIG_PM_SLEEP
> -
> -static int jz4740_mmc_suspend(struct device *dev)
> +static int __maybe_unused jz4740_mmc_suspend(struct device *dev)
> {
> return pinctrl_pm_select_sleep_state(dev);
> }
>
> -static int jz4740_mmc_resume(struct device *dev)
> +static int __maybe_unused jz4740_mmc_resume(struct device *dev)
> {
> return pinctrl_select_default_state(dev);
> }
>
> static SIMPLE_DEV_PM_OPS(jz4740_mmc_pm_ops, jz4740_mmc_suspend,
> jz4740_mmc_resume);
> -#define JZ4740_MMC_PM_OPS (&jz4740_mmc_pm_ops)
> -#else
> -#define JZ4740_MMC_PM_OPS NULL
> -#endif
>
> static struct platform_driver jz4740_mmc_driver = {
> .probe = jz4740_mmc_probe,
> @@ -1124,7 +1118,7 @@ static struct platform_driver jz4740_mmc_driver = {
> .driver = {
> .name = "jz4740-mmc",
> .of_match_table = of_match_ptr(jz4740_mmc_of_match),
> - .pm = JZ4740_MMC_PM_OPS,
> + .pm = pm_ptr(&jz4740_mmc_pm_ops),
> },
> };
>
> --
> 2.25.1
>
On Monday, April 13, 2020 2:32:05 PM CEST Paul Cercueil wrote:
> This macro is analogous to the infamous of_match_ptr(). If CONFIG_PM
> is enabled, this macro will resolve to its argument, otherwise to NULL.
Well, this is going to result in quite a bit of unused code being
added to the kernels built with CONFIG_PM unset.
Is there any way to avoid that somehow?
> Signed-off-by: Paul Cercueil <[email protected]>
> ---
>
> Notes:
> v2: Remove pm_sleep_ptr() macro
>
> include/linux/pm.h | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/include/linux/pm.h b/include/linux/pm.h
> index e057d1fa2469..1c0eec06905d 100644
> --- a/include/linux/pm.h
> +++ b/include/linux/pm.h
> @@ -374,6 +374,12 @@ const struct dev_pm_ops name = { \
> SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
> }
>
> +#ifdef CONFIG_PM
> +#define pm_ptr(_ptr) (_ptr)
> +#else
> +#define pm_ptr(_ptr) NULL
> +#endif
> +
> /*
> * PM_EVENT_ messages
> *
>
Hi Rafael,
Le dim. 26 avril 2020 ? 17:40, Rafael J. Wysocki <[email protected]> a
?crit :
> On Monday, April 13, 2020 2:32:05 PM CEST Paul Cercueil wrote:
>> This macro is analogous to the infamous of_match_ptr(). If CONFIG_PM
>> is enabled, this macro will resolve to its argument, otherwise to
>> NULL.
>
> Well, this is going to result in quite a bit of unused code being
> added to the kernels built with CONFIG_PM unset.
>
> Is there any way to avoid that somehow?
Using __maybe_unused on the dev_pm_ops struct and the callbacks, as
long as they are static, they should be dropped by the compiler when
CONFIG_PM is not set.
-Paul
>
>> Signed-off-by: Paul Cercueil <[email protected]>
>> ---
>>
>> Notes:
>> v2: Remove pm_sleep_ptr() macro
>>
>> include/linux/pm.h | 6 ++++++
>> 1 file changed, 6 insertions(+)
>>
>> diff --git a/include/linux/pm.h b/include/linux/pm.h
>> index e057d1fa2469..1c0eec06905d 100644
>> --- a/include/linux/pm.h
>> +++ b/include/linux/pm.h
>> @@ -374,6 +374,12 @@ const struct dev_pm_ops name = { \
>> SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
>> }
>>
>> +#ifdef CONFIG_PM
>> +#define pm_ptr(_ptr) (_ptr)
>> +#else
>> +#define pm_ptr(_ptr) NULL
>> +#endif
>> +
>> /*
>> * PM_EVENT_ messages
>> *
>>
>
>
>
>