diff mbox series

[43/49] iio:proximity:pulsedlight: Switch from CONFIG_PM guards to pm_ptr() / __maybe_unused

Message ID 20211123211019.2271440-44-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:10 p.m. UTC
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Letting the compiler remove these functions when the kernel is built
without CONFIG_PM 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.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Matt Ranostay <matt.ranostay@konsulko.com>
---
 drivers/iio/proximity/pulsedlight-lidar-lite-v2.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

Comments

Matt Ranostay Nov. 23, 2021, 10:22 p.m. UTC | #1
On Tue, Nov 23, 2021 at 1:07 PM 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 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.
>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Cc: Matt Ranostay <matt.ranostay@konsulko.com>

Acked-by: Matt Ranostay <matt.ranostay@konsulko.com>

> ---
>  drivers/iio/proximity/pulsedlight-lidar-lite-v2.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
> index 27026c060ab9..6adc2a0c27cb 100644
> --- a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
> +++ b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
> @@ -338,8 +338,7 @@ static const struct of_device_id lidar_dt_ids[] = {
>  };
>  MODULE_DEVICE_TABLE(of, lidar_dt_ids);
>
> -#ifdef CONFIG_PM
> -static int lidar_pm_runtime_suspend(struct device *dev)
> +static __maybe_unused int lidar_pm_runtime_suspend(struct device *dev)
>  {
>         struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
>         struct lidar_data *data = iio_priv(indio_dev);
> @@ -347,7 +346,7 @@ static int lidar_pm_runtime_suspend(struct device *dev)
>         return lidar_write_power(data, 0x0f);
>  }
>
> -static int lidar_pm_runtime_resume(struct device *dev)
> +static __maybe_unused int lidar_pm_runtime_resume(struct device *dev)
>  {
>         struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
>         struct lidar_data *data = iio_priv(indio_dev);
> @@ -358,9 +357,8 @@ static int lidar_pm_runtime_resume(struct device *dev)
>
>         return ret;
>  }
> -#endif
>
> -static const struct dev_pm_ops lidar_pm_ops = {
> +static __maybe_unused const struct dev_pm_ops lidar_pm_ops = {
>         SET_RUNTIME_PM_OPS(lidar_pm_runtime_suspend,
>                            lidar_pm_runtime_resume, NULL)
>  };
> @@ -369,7 +367,7 @@ static struct i2c_driver lidar_driver = {
>         .driver = {
>                 .name   = LIDAR_DRV_NAME,
>                 .of_match_table = lidar_dt_ids,
> -               .pm     = &lidar_pm_ops,
> +               .pm     = pm_ptr(&lidar_pm_ops),
>         },
>         .probe          = lidar_probe,
>         .remove         = lidar_remove,
> --
> 2.34.0
>
Jonathan Cameron Nov. 28, 2021, 4:44 p.m. UTC | #2
On Tue, 23 Nov 2021 14:22:46 -0800
Matt Ranostay <matt.ranostay@konsulko.com> wrote:

> On Tue, Nov 23, 2021 at 1:07 PM 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 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.
> >
> > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > Cc: Matt Ranostay <matt.ranostay@konsulko.com>  
> 
> Acked-by: Matt Ranostay <matt.ranostay@konsulko.com>
A clang build (without this patch) noted that lidar_write_power() is only used
in these functions (so I got an unused function warning). 

I'll add a maybe_unused to that as well if needed (subject to the
other discussion on how to do this better).

Thanks,

Jonathan

> 
> > ---
> >  drivers/iio/proximity/pulsedlight-lidar-lite-v2.c | 10 ++++------
> >  1 file changed, 4 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
> > index 27026c060ab9..6adc2a0c27cb 100644
> > --- a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
> > +++ b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
> > @@ -338,8 +338,7 @@ static const struct of_device_id lidar_dt_ids[] = {
> >  };
> >  MODULE_DEVICE_TABLE(of, lidar_dt_ids);
> >
> > -#ifdef CONFIG_PM
> > -static int lidar_pm_runtime_suspend(struct device *dev)
> > +static __maybe_unused int lidar_pm_runtime_suspend(struct device *dev)
> >  {
> >         struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
> >         struct lidar_data *data = iio_priv(indio_dev);
> > @@ -347,7 +346,7 @@ static int lidar_pm_runtime_suspend(struct device *dev)
> >         return lidar_write_power(data, 0x0f);
> >  }
> >
> > -static int lidar_pm_runtime_resume(struct device *dev)
> > +static __maybe_unused int lidar_pm_runtime_resume(struct device *dev)
> >  {
> >         struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
> >         struct lidar_data *data = iio_priv(indio_dev);
> > @@ -358,9 +357,8 @@ static int lidar_pm_runtime_resume(struct device *dev)
> >
> >         return ret;
> >  }
> > -#endif
> >
> > -static const struct dev_pm_ops lidar_pm_ops = {
> > +static __maybe_unused const struct dev_pm_ops lidar_pm_ops = {
> >         SET_RUNTIME_PM_OPS(lidar_pm_runtime_suspend,
> >                            lidar_pm_runtime_resume, NULL)
> >  };
> > @@ -369,7 +367,7 @@ static struct i2c_driver lidar_driver = {
> >         .driver = {
> >                 .name   = LIDAR_DRV_NAME,
> >                 .of_match_table = lidar_dt_ids,
> > -               .pm     = &lidar_pm_ops,
> > +               .pm     = pm_ptr(&lidar_pm_ops),
> >         },
> >         .probe          = lidar_probe,
> >         .remove         = lidar_remove,
> > --
> > 2.34.0
> >
diff mbox series

Patch

diff --git a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
index 27026c060ab9..6adc2a0c27cb 100644
--- a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
+++ b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
@@ -338,8 +338,7 @@  static const struct of_device_id lidar_dt_ids[] = {
 };
 MODULE_DEVICE_TABLE(of, lidar_dt_ids);
 
-#ifdef CONFIG_PM
-static int lidar_pm_runtime_suspend(struct device *dev)
+static __maybe_unused int lidar_pm_runtime_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct lidar_data *data = iio_priv(indio_dev);
@@ -347,7 +346,7 @@  static int lidar_pm_runtime_suspend(struct device *dev)
 	return lidar_write_power(data, 0x0f);
 }
 
-static int lidar_pm_runtime_resume(struct device *dev)
+static __maybe_unused int lidar_pm_runtime_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct lidar_data *data = iio_priv(indio_dev);
@@ -358,9 +357,8 @@  static int lidar_pm_runtime_resume(struct device *dev)
 
 	return ret;
 }
-#endif
 
-static const struct dev_pm_ops lidar_pm_ops = {
+static __maybe_unused const struct dev_pm_ops lidar_pm_ops = {
 	SET_RUNTIME_PM_OPS(lidar_pm_runtime_suspend,
 			   lidar_pm_runtime_resume, NULL)
 };
@@ -369,7 +367,7 @@  static struct i2c_driver lidar_driver = {
 	.driver = {
 		.name	= LIDAR_DRV_NAME,
 		.of_match_table	= lidar_dt_ids,
-		.pm	= &lidar_pm_ops,
+		.pm	= pm_ptr(&lidar_pm_ops),
 	},
 	.probe		= lidar_probe,
 	.remove		= lidar_remove,