diff mbox series

[v2,39/51] iio:proximity:as3935: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr() etc

Message ID 20220102125617.1259804-40-jic23@kernel.org (mailing list archive)
State Changes Requested
Headers show
Series iio: Tree wide switch from CONFIG_PM* to pm_[sleep]_ptr etc. | expand

Commit Message

Jonathan Cameron Jan. 2, 2022, 12:56 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.

Acked-by: Matt Ranostay <matt.ranostay@konsulko.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 drivers/iio/proximity/as3935.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

Comments

Gwendal Grignou Jan. 4, 2022, 6:41 a.m. UTC | #1
On Sun, Jan 2, 2022 at 4:52 AM 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.
>
> Acked-by: Matt Ranostay <matt.ranostay@konsulko.com>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>

To speed the transition to the new PM_OPS macros, we can use cocci to
automate the process a little. I had to use sed script so cocci can
identify the structure and function names:

find $DIR -type f -name \*.c \ -exec sed -i 's/static
SIMPLE_DEV_PM_OPS(\(.*\), */gg_type \1 = gg_arg(/' {} \+
spatch -sp_file no_SIMPLE_DEV_PM_OPS.cocci -dir $DIR | patch -p 1 -d $DIR
sed -i 's/gg_type \(.*\) = gg_arg(/DEFINE_SIMPLE_DEV_PM_OPS(\1, /'
$(git diff --name-only)

where no_SIMPLE_DEV_PM_OPS.cocci is:
@ Replacement @
identifier operation;
identifier suspend, resume;
@@

gg_type operation = gg_arg(suspend, resume);

@@
identifier Replacement.suspend;
identifier dev;
@@

- __maybe_unused
suspend(struct device* dev ) { ... }

@@
identifier Replacement.resume;
identifier dev;
@@

- __maybe_unused
resume(struct device* dev ) { ... }

@@
identifier Replacement.operation;
@@

- &operation
+ pm_sleep_ptr(&operation)


>  drivers/iio/proximity/as3935.c | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/iio/proximity/as3935.c b/drivers/iio/proximity/as3935.c
> index 51f4f92ae84a..5716048e228c 100644
> --- a/drivers/iio/proximity/as3935.c
> +++ b/drivers/iio/proximity/as3935.c
> @@ -295,7 +295,6 @@ static void calibrate_as3935(struct as3935_state *st)
>         as3935_write(st, AS3935_NFLWDTH, st->nflwdth_reg);
>  }
>
> -#ifdef CONFIG_PM_SLEEP
>  static int as3935_suspend(struct device *dev)
>  {
>         struct iio_dev *indio_dev = dev_get_drvdata(dev);
> @@ -337,12 +336,7 @@ static int as3935_resume(struct device *dev)
>         return ret;
>  }
>
> -static SIMPLE_DEV_PM_OPS(as3935_pm_ops, as3935_suspend, as3935_resume);
> -#define AS3935_PM_OPS (&as3935_pm_ops)
> -
> -#else
> -#define AS3935_PM_OPS NULL
> -#endif
> +DEFINE_SIMPLE_DEV_PM_OPS(as3935_pm_ops, as3935_suspend, as3935_resume);
>
>  static void as3935_stop_work(void *data)
>  {
> @@ -472,7 +466,7 @@ static struct spi_driver as3935_driver = {
>         .driver = {
>                 .name   = "as3935",
>                 .of_match_table = as3935_of_match,
> -               .pm     = AS3935_PM_OPS,
> +               .pm     = pm_sleep_ptr(&as3935_pm_ops),
>         },
>         .probe          = as3935_probe,
>         .id_table       = as3935_id,
> --
> 2.34.1
>
diff mbox series

Patch

diff --git a/drivers/iio/proximity/as3935.c b/drivers/iio/proximity/as3935.c
index 51f4f92ae84a..5716048e228c 100644
--- a/drivers/iio/proximity/as3935.c
+++ b/drivers/iio/proximity/as3935.c
@@ -295,7 +295,6 @@  static void calibrate_as3935(struct as3935_state *st)
 	as3935_write(st, AS3935_NFLWDTH, st->nflwdth_reg);
 }
 
-#ifdef CONFIG_PM_SLEEP
 static int as3935_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
@@ -337,12 +336,7 @@  static int as3935_resume(struct device *dev)
 	return ret;
 }
 
-static SIMPLE_DEV_PM_OPS(as3935_pm_ops, as3935_suspend, as3935_resume);
-#define AS3935_PM_OPS (&as3935_pm_ops)
-
-#else
-#define AS3935_PM_OPS NULL
-#endif
+DEFINE_SIMPLE_DEV_PM_OPS(as3935_pm_ops, as3935_suspend, as3935_resume);
 
 static void as3935_stop_work(void *data)
 {
@@ -472,7 +466,7 @@  static struct spi_driver as3935_driver = {
 	.driver = {
 		.name	= "as3935",
 		.of_match_table = as3935_of_match,
-		.pm	= AS3935_PM_OPS,
+		.pm	= pm_sleep_ptr(&as3935_pm_ops),
 	},
 	.probe		= as3935_probe,
 	.id_table	= as3935_id,