diff mbox series

[15/49] iio:adc:palmas_gpadc: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

Message ID 20211123211019.2271440-16-jic23@kernel.org (mailing list archive)
State Superseded
Headers show
Series iio: Tree wide switch from CONFIG_PM* to __maybe_unused etc. | expand

Commit Message

Jonathan Cameron Nov. 23, 2021, 9:09 p.m. UTC
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Letting the compiler remove these functions when the kernel is built
without CONFIG_PM_SLEEP support is simpler and less error prone than the
use of #ifdef based config guards.

Removing instances of this approach from IIO also stops them being
copied into new drivers.

The pm_ptr() macro only removes the reference if CONFIG_PM is not
set. It is possible for CONFIG_PM=y without CONFIG_SLEEP, so this
will not always remove the pm_ops structure.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 drivers/iio/adc/palmas_gpadc.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

Comments

Jonathan Cameron Jan. 1, 2022, 4:38 p.m. UTC | #1
On Tue, 23 Nov 2021 21:09:45 +0000
Jonathan Cameron <jic23@kernel.org> wrote:

> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> 
> Letting the compiler remove these functions when the kernel is built
> without CONFIG_PM_SLEEP support is simpler and less error prone than the
> use of #ifdef based config guards.
> 
> Removing instances of this approach from IIO also stops them being
> copied into new drivers.
> 
> The pm_ptr() macro only removes the reference if CONFIG_PM is not
> set. It is possible for CONFIG_PM=y without CONFIG_SLEEP, so this
> will not always remove the pm_ops structure.
> 
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  drivers/iio/adc/palmas_gpadc.c | 14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c
> index f9c8385c72d3..98d7764e0662 100644
> --- a/drivers/iio/adc/palmas_gpadc.c
> +++ b/drivers/iio/adc/palmas_gpadc.c
> @@ -653,8 +653,7 @@ static int palmas_gpadc_remove(struct platform_device *pdev)
>  	return 0;
>  }
>  
> -#ifdef CONFIG_PM_SLEEP
> -static int palmas_adc_wakeup_configure(struct palmas_gpadc *adc)
> +static __maybe_unused int palmas_adc_wakeup_configure(struct palmas_gpadc *adc)
>  {
>  	int adc_period, conv;
>  	int i;
> @@ -759,7 +758,7 @@ static int palmas_adc_wakeup_configure(struct palmas_gpadc *adc)
>  	return ret;
>  }
>  
> -static int palmas_adc_wakeup_reset(struct palmas_gpadc *adc)
> +static __maybe_unused int palmas_adc_wakeup_reset(struct palmas_gpadc *adc)
>  {
>  	int ret;
>  
> @@ -777,7 +776,7 @@ static int palmas_adc_wakeup_reset(struct palmas_gpadc *adc)
>  	return ret;
>  }
>  
> -static int palmas_gpadc_suspend(struct device *dev)
> +static __maybe_unused int palmas_gpadc_suspend(struct device *dev)
>  {
>  	struct iio_dev *indio_dev = dev_get_drvdata(dev);
>  	struct palmas_gpadc *adc = iio_priv(indio_dev);
> @@ -800,7 +799,7 @@ static int palmas_gpadc_suspend(struct device *dev)
>  	return 0;
>  }
>  
> -static int palmas_gpadc_resume(struct device *dev)
> +static __maybe_unused int palmas_gpadc_resume(struct device *dev)
>  {
>  	struct iio_dev *indio_dev = dev_get_drvdata(dev);
>  	struct palmas_gpadc *adc = iio_priv(indio_dev);
> @@ -822,9 +821,8 @@ static int palmas_gpadc_resume(struct device *dev)
>  
>  	return 0;
>  };
> -#endif
>  
> -static const struct dev_pm_ops palmas_pm_ops = {
> +static __maybe_unused const struct dev_pm_ops palmas_pm_ops = {
>  	SET_SYSTEM_SLEEP_PM_OPS(palmas_gpadc_suspend,
>  				palmas_gpadc_resume)
>  };
I missed that this could have been SIMPLE_DEV_PM_OPS - in v2 that
will be the new DEFINE_SIMPLE_DEV_PM_OPS()

> @@ -840,7 +838,7 @@ static struct platform_driver palmas_gpadc_driver = {
>  	.remove = palmas_gpadc_remove,
>  	.driver = {
>  		.name = MOD_NAME,
> -		.pm = &palmas_pm_ops,
> +		.pm = pm_ptr(&palmas_pm_ops),
>  		.of_match_table = of_palmas_gpadc_match_tbl,
>  	},
>  };
diff mbox series

Patch

diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c
index f9c8385c72d3..98d7764e0662 100644
--- a/drivers/iio/adc/palmas_gpadc.c
+++ b/drivers/iio/adc/palmas_gpadc.c
@@ -653,8 +653,7 @@  static int palmas_gpadc_remove(struct platform_device *pdev)
 	return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int palmas_adc_wakeup_configure(struct palmas_gpadc *adc)
+static __maybe_unused int palmas_adc_wakeup_configure(struct palmas_gpadc *adc)
 {
 	int adc_period, conv;
 	int i;
@@ -759,7 +758,7 @@  static int palmas_adc_wakeup_configure(struct palmas_gpadc *adc)
 	return ret;
 }
 
-static int palmas_adc_wakeup_reset(struct palmas_gpadc *adc)
+static __maybe_unused int palmas_adc_wakeup_reset(struct palmas_gpadc *adc)
 {
 	int ret;
 
@@ -777,7 +776,7 @@  static int palmas_adc_wakeup_reset(struct palmas_gpadc *adc)
 	return ret;
 }
 
-static int palmas_gpadc_suspend(struct device *dev)
+static __maybe_unused int palmas_gpadc_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct palmas_gpadc *adc = iio_priv(indio_dev);
@@ -800,7 +799,7 @@  static int palmas_gpadc_suspend(struct device *dev)
 	return 0;
 }
 
-static int palmas_gpadc_resume(struct device *dev)
+static __maybe_unused int palmas_gpadc_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct palmas_gpadc *adc = iio_priv(indio_dev);
@@ -822,9 +821,8 @@  static int palmas_gpadc_resume(struct device *dev)
 
 	return 0;
 };
-#endif
 
-static const struct dev_pm_ops palmas_pm_ops = {
+static __maybe_unused const struct dev_pm_ops palmas_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(palmas_gpadc_suspend,
 				palmas_gpadc_resume)
 };
@@ -840,7 +838,7 @@  static struct platform_driver palmas_gpadc_driver = {
 	.remove = palmas_gpadc_remove,
 	.driver = {
 		.name = MOD_NAME,
-		.pm = &palmas_pm_ops,
+		.pm = pm_ptr(&palmas_pm_ops),
 		.of_match_table = of_palmas_gpadc_match_tbl,
 	},
 };