linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/3] PM: introduce pm_ptr() macro
@ 2020-04-13 12:32 Paul Cercueil
  2020-04-13 12:32 ` [PATCH v2 2/3] PM: Make *_DEV_PM_OPS macros use __maybe_unused Paul Cercueil
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Paul Cercueil @ 2020-04-13 12:32 UTC (permalink / raw)
  To: Ulf Hansson, Rafael J . Wysocki, Pavel Machek, Len Brown
  Cc: od, linux-mmc, linux-kernel, linux-pm, Paul Cercueil

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 <paul@crapouillou.net>
---

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


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

* [PATCH v2 2/3] PM: Make *_DEV_PM_OPS macros use __maybe_unused
  2020-04-13 12:32 [PATCH v2 1/3] PM: introduce pm_ptr() macro Paul Cercueil
@ 2020-04-13 12:32 ` Paul Cercueil
  2020-04-13 12:32 ` [PATCH v2 3/3] mmc: jz4740: Use pm_ptr() macro Paul Cercueil
  2020-04-26 15:40 ` [PATCH v2 1/3] PM: introduce " Rafael J. Wysocki
  2 siblings, 0 replies; 6+ messages in thread
From: Paul Cercueil @ 2020-04-13 12:32 UTC (permalink / raw)
  To: Ulf Hansson, Rafael J . Wysocki, Pavel Machek, Len Brown
  Cc: od, linux-mmc, linux-kernel, linux-pm, Paul Cercueil

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 <paul@crapouillou.net>
---

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


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

* [PATCH v2 3/3] mmc: jz4740: Use pm_ptr() macro
  2020-04-13 12:32 [PATCH v2 1/3] PM: introduce pm_ptr() macro Paul Cercueil
  2020-04-13 12:32 ` [PATCH v2 2/3] PM: Make *_DEV_PM_OPS macros use __maybe_unused Paul Cercueil
@ 2020-04-13 12:32 ` Paul Cercueil
  2020-04-21 10:39   ` Ulf Hansson
  2020-04-26 15:40 ` [PATCH v2 1/3] PM: introduce " Rafael J. Wysocki
  2 siblings, 1 reply; 6+ messages in thread
From: Paul Cercueil @ 2020-04-13 12:32 UTC (permalink / raw)
  To: Ulf Hansson, Rafael J . Wysocki, Pavel Machek, Len Brown
  Cc: od, linux-mmc, linux-kernel, linux-pm, Paul Cercueil

Use the newly introduced pm_ptr() macro to simplify the code.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---

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


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

* Re: [PATCH v2 3/3] mmc: jz4740: Use pm_ptr() macro
  2020-04-13 12:32 ` [PATCH v2 3/3] mmc: jz4740: Use pm_ptr() macro Paul Cercueil
@ 2020-04-21 10:39   ` Ulf Hansson
  0 siblings, 0 replies; 6+ messages in thread
From: Ulf Hansson @ 2020-04-21 10:39 UTC (permalink / raw)
  To: Paul Cercueil, Rafael J . Wysocki
  Cc: Pavel Machek, Len Brown, od, linux-mmc,
	Linux Kernel Mailing List, Linux PM

On Mon, 13 Apr 2020 at 14:32, Paul Cercueil <paul@crapouillou.net> wrote:
>
> Use the newly introduced pm_ptr() macro to simplify the code.
>
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>

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 <ulf.hansson@linaro.org>

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
>

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

* Re: [PATCH v2 1/3] PM: introduce pm_ptr() macro
  2020-04-13 12:32 [PATCH v2 1/3] PM: introduce pm_ptr() macro Paul Cercueil
  2020-04-13 12:32 ` [PATCH v2 2/3] PM: Make *_DEV_PM_OPS macros use __maybe_unused Paul Cercueil
  2020-04-13 12:32 ` [PATCH v2 3/3] mmc: jz4740: Use pm_ptr() macro Paul Cercueil
@ 2020-04-26 15:40 ` Rafael J. Wysocki
  2020-04-26 17:06   ` Paul Cercueil
  2 siblings, 1 reply; 6+ messages in thread
From: Rafael J. Wysocki @ 2020-04-26 15:40 UTC (permalink / raw)
  To: Paul Cercueil
  Cc: Ulf Hansson, Pavel Machek, Len Brown, od, linux-mmc,
	linux-kernel, linux-pm

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 <paul@crapouillou.net>
> ---
> 
> 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
>   *
> 





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

* Re: [PATCH v2 1/3] PM: introduce pm_ptr() macro
  2020-04-26 15:40 ` [PATCH v2 1/3] PM: introduce " Rafael J. Wysocki
@ 2020-04-26 17:06   ` Paul Cercueil
  0 siblings, 0 replies; 6+ messages in thread
From: Paul Cercueil @ 2020-04-26 17:06 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Ulf Hansson, Pavel Machek, Len Brown, od, linux-mmc,
	linux-kernel, linux-pm

Hi Rafael,

Le dim. 26 avril 2020 à 17:40, Rafael J. Wysocki <rjw@rjwysocki.net> 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 <paul@crapouillou.net>
>>  ---
>> 
>>  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
>>    *
>> 
> 
> 
> 
> 



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

end of thread, other threads:[~2020-04-26 17:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-13 12:32 [PATCH v2 1/3] PM: introduce pm_ptr() macro Paul Cercueil
2020-04-13 12:32 ` [PATCH v2 2/3] PM: Make *_DEV_PM_OPS macros use __maybe_unused Paul Cercueil
2020-04-13 12:32 ` [PATCH v2 3/3] mmc: jz4740: Use pm_ptr() macro Paul Cercueil
2020-04-21 10:39   ` Ulf Hansson
2020-04-26 15:40 ` [PATCH v2 1/3] PM: introduce " Rafael J. Wysocki
2020-04-26 17:06   ` Paul Cercueil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).