diff mbox series

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

Message ID 20211123211019.2271440-13-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/ad7606.c     | 8 ++------
 drivers/iio/adc/ad7606.h     | 5 -----
 drivers/iio/adc/ad7606_par.c | 2 +-
 drivers/iio/adc/ad7606_spi.c | 2 +-
 4 files changed, 4 insertions(+), 13 deletions(-)

Comments

Jonathan Cameron Jan. 1, 2022, 4:27 p.m. UTC | #1
On Tue, 23 Nov 2021 21:09:42 +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>
I'll comment here as this patch won't exist in v2.

Given the structure is exported from one module to others, the
compiler can't remove it automatically.  Hence this one really does
need the CONFIG_PM_SLEEP guards.

Not sure what I was thinking when I wrote this!

Jonathan

> ---
>  drivers/iio/adc/ad7606.c     | 8 ++------
>  drivers/iio/adc/ad7606.h     | 5 -----
>  drivers/iio/adc/ad7606_par.c | 2 +-
>  drivers/iio/adc/ad7606_spi.c | 2 +-
>  4 files changed, 4 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
> index 0a60ecc69d38..16a013aad20f 100644
> --- a/drivers/iio/adc/ad7606.c
> +++ b/drivers/iio/adc/ad7606.c
> @@ -695,9 +695,7 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
>  }
>  EXPORT_SYMBOL_GPL(ad7606_probe);
>  
> -#ifdef CONFIG_PM_SLEEP
> -
> -static int ad7606_suspend(struct device *dev)
> +static __maybe_unused int ad7606_suspend(struct device *dev)
>  {
>  	struct iio_dev *indio_dev = dev_get_drvdata(dev);
>  	struct ad7606_state *st = iio_priv(indio_dev);
> @@ -710,7 +708,7 @@ static int ad7606_suspend(struct device *dev)
>  	return 0;
>  }
>  
> -static int ad7606_resume(struct device *dev)
> +static __maybe_unused int ad7606_resume(struct device *dev)
>  {
>  	struct iio_dev *indio_dev = dev_get_drvdata(dev);
>  	struct ad7606_state *st = iio_priv(indio_dev);
> @@ -727,8 +725,6 @@ static int ad7606_resume(struct device *dev)
>  SIMPLE_DEV_PM_OPS(ad7606_pm_ops, ad7606_suspend, ad7606_resume);
>  EXPORT_SYMBOL_GPL(ad7606_pm_ops);
>  
> -#endif
> -
>  MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
>  MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
>  MODULE_LICENSE("GPL v2");
> diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h
> index 9350ef1f63b5..fd545836790e 100644
> --- a/drivers/iio/adc/ad7606.h
> +++ b/drivers/iio/adc/ad7606.h
> @@ -162,11 +162,6 @@ enum ad7606_supported_device_ids {
>  	ID_AD7616,
>  };
>  
> -#ifdef CONFIG_PM_SLEEP
>  extern const struct dev_pm_ops ad7606_pm_ops;
> -#define AD7606_PM_OPS (&ad7606_pm_ops)
> -#else
> -#define AD7606_PM_OPS NULL
> -#endif
>  
>  #endif /* IIO_ADC_AD7606_H_ */
> diff --git a/drivers/iio/adc/ad7606_par.c b/drivers/iio/adc/ad7606_par.c
> index f732b3ac7878..60be3fb4ae39 100644
> --- a/drivers/iio/adc/ad7606_par.c
> +++ b/drivers/iio/adc/ad7606_par.c
> @@ -92,7 +92,7 @@ static struct platform_driver ad7606_driver = {
>  	.id_table = ad7606_driver_ids,
>  	.driver = {
>  		.name = "ad7606",
> -		.pm = AD7606_PM_OPS,
> +		.pm = pm_ptr(&ad7606_pm_ops),
>  		.of_match_table = ad7606_of_match,
>  	},
>  };
> diff --git a/drivers/iio/adc/ad7606_spi.c b/drivers/iio/adc/ad7606_spi.c
> index 29945ad07dca..8cc525b4b960 100644
> --- a/drivers/iio/adc/ad7606_spi.c
> +++ b/drivers/iio/adc/ad7606_spi.c
> @@ -352,7 +352,7 @@ static struct spi_driver ad7606_driver = {
>  	.driver = {
>  		.name = "ad7606",
>  		.of_match_table = ad7606_of_match,
> -		.pm = AD7606_PM_OPS,
> +		.pm = pm_ptr(&ad7606_pm_ops),
>  	},
>  	.probe = ad7606_spi_probe,
>  	.id_table = ad7606_id_table,
diff mbox series

Patch

diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
index 0a60ecc69d38..16a013aad20f 100644
--- a/drivers/iio/adc/ad7606.c
+++ b/drivers/iio/adc/ad7606.c
@@ -695,9 +695,7 @@  int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
 }
 EXPORT_SYMBOL_GPL(ad7606_probe);
 
-#ifdef CONFIG_PM_SLEEP
-
-static int ad7606_suspend(struct device *dev)
+static __maybe_unused int ad7606_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct ad7606_state *st = iio_priv(indio_dev);
@@ -710,7 +708,7 @@  static int ad7606_suspend(struct device *dev)
 	return 0;
 }
 
-static int ad7606_resume(struct device *dev)
+static __maybe_unused int ad7606_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct ad7606_state *st = iio_priv(indio_dev);
@@ -727,8 +725,6 @@  static int ad7606_resume(struct device *dev)
 SIMPLE_DEV_PM_OPS(ad7606_pm_ops, ad7606_suspend, ad7606_resume);
 EXPORT_SYMBOL_GPL(ad7606_pm_ops);
 
-#endif
-
 MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
 MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
 MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h
index 9350ef1f63b5..fd545836790e 100644
--- a/drivers/iio/adc/ad7606.h
+++ b/drivers/iio/adc/ad7606.h
@@ -162,11 +162,6 @@  enum ad7606_supported_device_ids {
 	ID_AD7616,
 };
 
-#ifdef CONFIG_PM_SLEEP
 extern const struct dev_pm_ops ad7606_pm_ops;
-#define AD7606_PM_OPS (&ad7606_pm_ops)
-#else
-#define AD7606_PM_OPS NULL
-#endif
 
 #endif /* IIO_ADC_AD7606_H_ */
diff --git a/drivers/iio/adc/ad7606_par.c b/drivers/iio/adc/ad7606_par.c
index f732b3ac7878..60be3fb4ae39 100644
--- a/drivers/iio/adc/ad7606_par.c
+++ b/drivers/iio/adc/ad7606_par.c
@@ -92,7 +92,7 @@  static struct platform_driver ad7606_driver = {
 	.id_table = ad7606_driver_ids,
 	.driver = {
 		.name = "ad7606",
-		.pm = AD7606_PM_OPS,
+		.pm = pm_ptr(&ad7606_pm_ops),
 		.of_match_table = ad7606_of_match,
 	},
 };
diff --git a/drivers/iio/adc/ad7606_spi.c b/drivers/iio/adc/ad7606_spi.c
index 29945ad07dca..8cc525b4b960 100644
--- a/drivers/iio/adc/ad7606_spi.c
+++ b/drivers/iio/adc/ad7606_spi.c
@@ -352,7 +352,7 @@  static struct spi_driver ad7606_driver = {
 	.driver = {
 		.name = "ad7606",
 		.of_match_table = ad7606_of_match,
-		.pm = AD7606_PM_OPS,
+		.pm = pm_ptr(&ad7606_pm_ops),
 	},
 	.probe = ad7606_spi_probe,
 	.id_table = ad7606_id_table,