diff mbox series

[1/4] watchdog: at91rm9200: Remove #ifdef guards for PM related functions

Message ID 20221020185047.1001522-2-paul@crapouillou.net (mailing list archive)
State New, archived
Headers show
Series [1/4] watchdog: at91rm9200: Remove #ifdef guards for PM related functions | expand

Commit Message

Paul Cercueil Oct. 20, 2022, 6:50 p.m. UTC
Use the pm_ptr() macro to handle the .suspend/.resume callbacks.

This macro allows the suspend and resume functions to be automatically
dropped by the compiler when CONFIG_SUSPEND is disabled, without having
to use #ifdef guards. Not using #ifdef guards means that the code is
always compiled independently of any Kconfig option, and thanks to that
bugs and regressions are easier to catch.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
Cc: Nicolas Ferre <nicolas.ferre@microchip.com>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Claudiu Beznea <claudiu.beznea@microchip.com>
Cc: linux-arm-kernel@lists.infradead.org

 drivers/watchdog/at91rm9200_wdt.c | 11 ++---------
 drivers/watchdog/db8500_wdt.c     |  9 ++-------
 2 files changed, 4 insertions(+), 16 deletions(-)

Comments

Guenter Roeck Oct. 20, 2022, 9:59 p.m. UTC | #1
On Thu, Oct 20, 2022 at 07:50:44PM +0100, Paul Cercueil wrote:
> Use the pm_ptr() macro to handle the .suspend/.resume callbacks.
> 
> This macro allows the suspend and resume functions to be automatically
> dropped by the compiler when CONFIG_SUSPEND is disabled, without having
> to use #ifdef guards. Not using #ifdef guards means that the code is
> always compiled independently of any Kconfig option, and thanks to that
> bugs and regressions are easier to catch.
> 
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
> Cc: Nicolas Ferre <nicolas.ferre@microchip.com>
> Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
> Cc: Claudiu Beznea <claudiu.beznea@microchip.com>
> Cc: linux-arm-kernel@lists.infradead.org
> 
>  drivers/watchdog/at91rm9200_wdt.c | 11 ++---------
>  drivers/watchdog/db8500_wdt.c     |  9 ++-------
>  2 files changed, 4 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/watchdog/at91rm9200_wdt.c b/drivers/watchdog/at91rm9200_wdt.c
> index 6d751eb8191d..5126454bb861 100644
> --- a/drivers/watchdog/at91rm9200_wdt.c
> +++ b/drivers/watchdog/at91rm9200_wdt.c
> @@ -278,8 +278,6 @@ static void at91wdt_shutdown(struct platform_device *pdev)
>  	at91_wdt_stop();
>  }
>  
> -#ifdef CONFIG_PM
> -
>  static int at91wdt_suspend(struct platform_device *pdev, pm_message_t message)
>  {
>  	at91_wdt_stop();
> @@ -293,11 +291,6 @@ static int at91wdt_resume(struct platform_device *pdev)
>  	return 0;
>  }
>  
> -#else
> -#define at91wdt_suspend NULL
> -#define at91wdt_resume	NULL
> -#endif
> -
>  static const struct of_device_id at91_wdt_dt_ids[] = {
>  	{ .compatible = "atmel,at91rm9200-wdt" },
>  	{ /* sentinel */ }
> @@ -308,8 +301,8 @@ static struct platform_driver at91wdt_driver = {
>  	.probe		= at91wdt_probe,
>  	.remove		= at91wdt_remove,
>  	.shutdown	= at91wdt_shutdown,
> -	.suspend	= at91wdt_suspend,
> -	.resume		= at91wdt_resume,
> +	.suspend	= pm_ptr(at91wdt_suspend),
> +	.resume		= pm_ptr(at91wdt_resume),
>  	.driver		= {
>  		.name	= "atmel_st_watchdog",
>  		.of_match_table = at91_wdt_dt_ids,
> diff --git a/drivers/watchdog/db8500_wdt.c b/drivers/watchdog/db8500_wdt.c
> index 6ed8b63d310d..97148ac0aa54 100644
> --- a/drivers/watchdog/db8500_wdt.c
> +++ b/drivers/watchdog/db8500_wdt.c
> @@ -105,7 +105,6 @@ static int db8500_wdt_probe(struct platform_device *pdev)
>  	return 0;
>  }
>  
> -#ifdef CONFIG_PM
>  static int db8500_wdt_suspend(struct platform_device *pdev,
>  			     pm_message_t state)
>  {
> @@ -130,15 +129,11 @@ static int db8500_wdt_resume(struct platform_device *pdev)
>  	}
>  	return 0;
>  }
> -#else
> -#define db8500_wdt_suspend NULL
> -#define db8500_wdt_resume NULL
> -#endif
>  
>  static struct platform_driver db8500_wdt_driver = {
>  	.probe		= db8500_wdt_probe,
> -	.suspend	= db8500_wdt_suspend,
> -	.resume		= db8500_wdt_resume,
> +	.suspend	= pm_ptr(db8500_wdt_suspend),
> +	.resume		= pm_ptr(db8500_wdt_resume),
>  	.driver		= {
>  		.name	= "db8500_wdt",
>  	},
> -- 
> 2.35.1
>
Claudiu Beznea Oct. 21, 2022, 7:21 a.m. UTC | #2
On 20.10.2022 21:50, Paul Cercueil wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> Use the pm_ptr() macro to handle the .suspend/.resume callbacks.
> 
> This macro allows the suspend and resume functions to be automatically
> dropped by the compiler when CONFIG_SUSPEND is disabled, without having
> to use #ifdef guards. Not using #ifdef guards means that the code is
> always compiled independently of any Kconfig option, and thanks to that
> bugs and regressions are easier to catch.
> 
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> ---
> Cc: Nicolas Ferre <nicolas.ferre@microchip.com>
> Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
> Cc: Claudiu Beznea <claudiu.beznea@microchip.com>
> Cc: linux-arm-kernel@lists.infradead.org

Reviewed-by: Claudiu Beznea <claudiu.beznea@microchip.com>


> 
>  drivers/watchdog/at91rm9200_wdt.c | 11 ++---------
>  drivers/watchdog/db8500_wdt.c     |  9 ++-------
>  2 files changed, 4 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/watchdog/at91rm9200_wdt.c b/drivers/watchdog/at91rm9200_wdt.c
> index 6d751eb8191d..5126454bb861 100644
> --- a/drivers/watchdog/at91rm9200_wdt.c
> +++ b/drivers/watchdog/at91rm9200_wdt.c
> @@ -278,8 +278,6 @@ static void at91wdt_shutdown(struct platform_device *pdev)
>         at91_wdt_stop();
>  }
> 
> -#ifdef CONFIG_PM
> -
>  static int at91wdt_suspend(struct platform_device *pdev, pm_message_t message)
>  {
>         at91_wdt_stop();
> @@ -293,11 +291,6 @@ static int at91wdt_resume(struct platform_device *pdev)
>         return 0;
>  }
> 
> -#else
> -#define at91wdt_suspend NULL
> -#define at91wdt_resume NULL
> -#endif
> -
>  static const struct of_device_id at91_wdt_dt_ids[] = {
>         { .compatible = "atmel,at91rm9200-wdt" },
>         { /* sentinel */ }
> @@ -308,8 +301,8 @@ static struct platform_driver at91wdt_driver = {
>         .probe          = at91wdt_probe,
>         .remove         = at91wdt_remove,
>         .shutdown       = at91wdt_shutdown,
> -       .suspend        = at91wdt_suspend,
> -       .resume         = at91wdt_resume,
> +       .suspend        = pm_ptr(at91wdt_suspend),
> +       .resume         = pm_ptr(at91wdt_resume),
>         .driver         = {
>                 .name   = "atmel_st_watchdog",
>                 .of_match_table = at91_wdt_dt_ids,
> diff --git a/drivers/watchdog/db8500_wdt.c b/drivers/watchdog/db8500_wdt.c
> index 6ed8b63d310d..97148ac0aa54 100644
> --- a/drivers/watchdog/db8500_wdt.c
> +++ b/drivers/watchdog/db8500_wdt.c
> @@ -105,7 +105,6 @@ static int db8500_wdt_probe(struct platform_device *pdev)
>         return 0;
>  }
> 
> -#ifdef CONFIG_PM
>  static int db8500_wdt_suspend(struct platform_device *pdev,
>                              pm_message_t state)
>  {
> @@ -130,15 +129,11 @@ static int db8500_wdt_resume(struct platform_device *pdev)
>         }
>         return 0;
>  }
> -#else
> -#define db8500_wdt_suspend NULL
> -#define db8500_wdt_resume NULL
> -#endif
> 
>  static struct platform_driver db8500_wdt_driver = {
>         .probe          = db8500_wdt_probe,
> -       .suspend        = db8500_wdt_suspend,
> -       .resume         = db8500_wdt_resume,
> +       .suspend        = pm_ptr(db8500_wdt_suspend),
> +       .resume         = pm_ptr(db8500_wdt_resume),
>         .driver         = {
>                 .name   = "db8500_wdt",
>         },
> --
> 2.35.1
>
diff mbox series

Patch

diff --git a/drivers/watchdog/at91rm9200_wdt.c b/drivers/watchdog/at91rm9200_wdt.c
index 6d751eb8191d..5126454bb861 100644
--- a/drivers/watchdog/at91rm9200_wdt.c
+++ b/drivers/watchdog/at91rm9200_wdt.c
@@ -278,8 +278,6 @@  static void at91wdt_shutdown(struct platform_device *pdev)
 	at91_wdt_stop();
 }
 
-#ifdef CONFIG_PM
-
 static int at91wdt_suspend(struct platform_device *pdev, pm_message_t message)
 {
 	at91_wdt_stop();
@@ -293,11 +291,6 @@  static int at91wdt_resume(struct platform_device *pdev)
 	return 0;
 }
 
-#else
-#define at91wdt_suspend NULL
-#define at91wdt_resume	NULL
-#endif
-
 static const struct of_device_id at91_wdt_dt_ids[] = {
 	{ .compatible = "atmel,at91rm9200-wdt" },
 	{ /* sentinel */ }
@@ -308,8 +301,8 @@  static struct platform_driver at91wdt_driver = {
 	.probe		= at91wdt_probe,
 	.remove		= at91wdt_remove,
 	.shutdown	= at91wdt_shutdown,
-	.suspend	= at91wdt_suspend,
-	.resume		= at91wdt_resume,
+	.suspend	= pm_ptr(at91wdt_suspend),
+	.resume		= pm_ptr(at91wdt_resume),
 	.driver		= {
 		.name	= "atmel_st_watchdog",
 		.of_match_table = at91_wdt_dt_ids,
diff --git a/drivers/watchdog/db8500_wdt.c b/drivers/watchdog/db8500_wdt.c
index 6ed8b63d310d..97148ac0aa54 100644
--- a/drivers/watchdog/db8500_wdt.c
+++ b/drivers/watchdog/db8500_wdt.c
@@ -105,7 +105,6 @@  static int db8500_wdt_probe(struct platform_device *pdev)
 	return 0;
 }
 
-#ifdef CONFIG_PM
 static int db8500_wdt_suspend(struct platform_device *pdev,
 			     pm_message_t state)
 {
@@ -130,15 +129,11 @@  static int db8500_wdt_resume(struct platform_device *pdev)
 	}
 	return 0;
 }
-#else
-#define db8500_wdt_suspend NULL
-#define db8500_wdt_resume NULL
-#endif
 
 static struct platform_driver db8500_wdt_driver = {
 	.probe		= db8500_wdt_probe,
-	.suspend	= db8500_wdt_suspend,
-	.resume		= db8500_wdt_resume,
+	.suspend	= pm_ptr(db8500_wdt_suspend),
+	.resume		= pm_ptr(db8500_wdt_resume),
 	.driver		= {
 		.name	= "db8500_wdt",
 	},