Skip to contentSkip to conversation

iio: Tree wide switch from CONFIG_PM* to __maybe_unused etc.

PATCH Superseded Jonathan Cameron 12 participants 83 messages Nov 23, 2021 – Jan 1, 2022

Subsystems (12)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jonathan Cameron

author maintainer
#0 lore raw

cover iio: Tree wide switch from CONFIG_PM* to __maybe_unused etc.

From: Jonathan Cameron <[email protected]>

Note this series includes many drivers that are quite old and I'm not sure have active maintainers. Hence if anyone has time to look at some of these beyond their own drivers and sanity check them it would be much appreciated!

Two motivations behind this set.
1 - General code reduction and improvement in readability in these drivers. 2 - Reduce change I'll have to ask people to change how they do this in
future patches.

Mostly this is just a case of letting the compiler work out it can remove the PM related functions rather than using #ifdefs in the code to do so.

The __maybe_unused markings make it clear we are intentionally building functions that the compiler can see are unused and remove in some build configurations.

The new pm_ptr() macro is rather convenient to got futher than many of the drivers were and when CONFIG_PM is not define ensure that the struct dev_pm_ops can also be removed. Note there is a subtlty in that we only remove that whe CONFIG_PM is not defined whereas a few of these drivers were using CONFIG_PM_SLEEP which is a tighter condition (will remove the structure in more configurations). I think that's a small price to pay for the convenience this macro brings.

I did this set as one patch per driver, as personally I prefer that option for all but the most trivial patches because it makes backports that cross with this series simpler and also avoid the complex tag giving we get for sets touching code from many authors.

All comments welcome.

Cc Alexandre Belloni <[email protected]>
Cc Anson Huang <[email protected]>
Cc Brian Masney <[email protected]>
Cc Fabrice Gasnier <[email protected]>
Cc Hans de Goede <[email protected]>
Cc Heiko Stuebner <[email protected]>
Cc Icenowy Zheng <[email protected]>
Cc Jonathan Albrieux <[email protected]>
Cc Krzysztof Kozlowski <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Luca Weiss <[email protected]>
Cc Ludovic Desroches <[email protected]>
Cc Manivannan Sadhasivam <[email protected]>
Cc Martijn Braam <[email protected]>
Cc Maslov Dmitry <[email protected]>
Cc Matt Ranostay <[email protected]
Cc Olivier Moysan <[email protected]>
Cc Stefan-Gabriel Mirea <[email protected]>
Cc Vaishnav M A <[email protected]>

Jonathan Cameron (49):
iio:accel:da311: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:accel:da280: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:accel:dmard06: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:accel:dmard10: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:accel:mc3230: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:accel:mma7660: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:accel:mma9551: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:accel:mma9553: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:accel:stk8ba50: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:accel:kxsd9: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:adc:ab8500: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:adc:ad7606: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:adc:at91-adc: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:adc:exynos_adc: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:adc:palmas_gpadc: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:adc:stm32:Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:adc:rcar: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:adc:rockchip: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:adc:twl6030: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:adc:vf610: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:common:ssp: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:dac:vf610: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:apds9300: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:bh1780: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:light:cm3232: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:isl29018: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:isl29125: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:jsa1212: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:ltr501: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:stk3310: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:tcs3414: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:tcs3472: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:tsl2563: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:tsl4531: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:us5182: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:magn:ak8975: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:magn:hmc5843: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:magn:mag3110: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:magn:mmc35240: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:pressure:mpl3115: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:pressure:bmp280: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:proximity:as3935: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:proximity:pulsedlight: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:proximity:rfd77492: Switch from CONFIG_PM_SLEEP guards to pm_ptr()
/ __maybe_unused
iio:proximity:sx9500: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:temperature:tmp006: Switch from CONFIG_PM_SLEEP guards to pm_ptr()
/ __maybe_unused
iio:temperature:tmp007: Switch from CONFIG_PM_SLEEP guards to pm_ptr()
/ __maybe_unused
iio:gyro:mpu3050: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:chemical:atlas: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused

 drivers/iio/accel/da280.c                        |  6 ++----
 drivers/iio/accel/da311.c                        |  8 +++-----
 drivers/iio/accel/dmard06.c                      | 12 ++++--------
 drivers/iio/accel/dmard10.c                      |  9 ++++-----
 drivers/iio/accel/kxsd9-i2c.c                    |  2 +-
 drivers/iio/accel/kxsd9-spi.c                    |  2 +-
 drivers/iio/accel/kxsd9.c                        |  8 +++-----
 drivers/iio/accel/mc3230.c                       |  8 +++-----
 drivers/iio/accel/mma7660.c                      | 12 +++---------
 drivers/iio/accel/mma9551.c                      | 16 ++++++----------
 drivers/iio/accel/mma9553.c                      | 16 ++++++----------
 drivers/iio/accel/stk8ba50.c                     | 12 +++---------
 drivers/iio/adc/ab8500-gpadc.c                   | 10 ++++------
 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 +-
 drivers/iio/adc/at91_adc.c                       |  8 +++-----
 drivers/iio/adc/exynos_adc.c                     |  8 +++-----
 drivers/iio/adc/palmas_gpadc.c                   | 14 ++++++--------
 drivers/iio/adc/rcar-gyroadc.c                   | 10 ++++------
 drivers/iio/adc/rockchip_saradc.c                |  8 +++-----
 drivers/iio/adc/stm32-adc-core.c                 | 12 +++++-------
 drivers/iio/adc/stm32-adc.c                      | 16 ++++++----------
 drivers/iio/adc/twl6030-gpadc.c                  |  8 +++-----
 drivers/iio/adc/vf610_adc.c                      |  8 +++-----
 drivers/iio/chemical/atlas-sensor.c              | 10 ++++------
 drivers/iio/common/ssp_sensors/ssp_dev.c         | 12 ++++--------
 drivers/iio/dac/vf610_dac.c                      |  8 +++-----
 drivers/iio/gyro/mpu3050-core.c                  |  8 +++-----
 drivers/iio/gyro/mpu3050-i2c.c                   |  2 +-
 drivers/iio/light/apds9300.c                     | 11 +++--------
 drivers/iio/light/bh1780.c                       | 10 ++++------
 drivers/iio/light/cm3232.c                       | 13 ++++---------
 drivers/iio/light/isl29018.c                     | 11 +++--------
 drivers/iio/light/isl29125.c                     |  8 +++-----
 drivers/iio/light/jsa1212.c                      | 12 +++---------
 drivers/iio/light/ltr501.c                       |  8 +++-----
 drivers/iio/light/stk3310.c                      | 12 +++---------
 drivers/iio/light/tcs3414.c                      |  8 +++-----
 drivers/iio/light/tcs3472.c                      |  8 +++-----
 drivers/iio/light/tsl2563.c                      | 11 +++--------
 drivers/iio/light/tsl4531.c                      | 11 +++--------
 drivers/iio/light/us5182d.c                      | 10 ++++------
 drivers/iio/magnetometer/ak8975.c                | 10 ++++------
 drivers/iio/magnetometer/hmc5843.h               |  5 -----
 drivers/iio/magnetometer/hmc5843_i2c.c           |  2 +-
 drivers/iio/magnetometer/hmc5843_spi.c           |  2 +-
 drivers/iio/magnetometer/mag3110.c               | 11 +++--------
 drivers/iio/magnetometer/mmc35240.c              | 12 ++++--------
 drivers/iio/pressure/bmp280-core.c               |  6 ++----
 drivers/iio/pressure/bmp280-i2c.c                |  2 +-
 drivers/iio/pressure/bmp280-spi.c                |  2 +-
 drivers/iio/pressure/mpl3115.c                   | 11 +++--------
 drivers/iio/proximity/as3935.c                   | 12 +++---------
 .../iio/proximity/pulsedlight-lidar-lite-v2.c    | 10 ++++------
 drivers/iio/proximity/rfd77402.c                 |  8 +++-----
 drivers/iio/proximity/sx9500.c                   | 12 ++++--------
 drivers/iio/temperature/tmp006.c                 |  8 +++-----
 drivers/iio/temperature/tmp007.c                 |  8 +++-----
 60 files changed, 180 insertions(+), 344 deletions(-)
Signature · 1 line
2.34.0
author maintainer
#1 lore raw

PATCH 1/49 iio:accel:da311: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/accel/da311.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/iio/accel/da311.c +3 -5
index 04e13487e706..b65f47dc4945 100644
@@ -256,17 +256,15 @@ static int da311_probe(struct i2c_client *client,
 	return devm_iio_device_register(&client->dev, indio_dev);
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int da311_suspend(struct device *dev)
+static __maybe_unused int da311_suspend(struct device *dev)
 {
 	return da311_enable(to_i2c_client(dev), false);
 }
 
-static int da311_resume(struct device *dev)
+static __maybe_unused int da311_resume(struct device *dev)
 {
 	return da311_enable(to_i2c_client(dev), true);
 }
-#endif
 
 static SIMPLE_DEV_PM_OPS(da311_pm_ops, da311_suspend, da311_resume);
 
@@ -279,7 +277,7 @@ MODULE_DEVICE_TABLE(i2c, da311_i2c_id);
 static struct i2c_driver da311_driver = {
 	.driver = {
 		.name = "da311",
-		.pm = &da311_pm_ops,
+		.pm = pm_ptr(&da311_pm_ops),
 	},
 	.probe		= da311_probe,
 	.id_table	= da311_i2c_id,
Signature · 1 line
2.34.0
author maintainer
#2 lore raw

PATCH 2/49 iio:accel:da280: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/accel/da280.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/iio/accel/da280.c +2 -4
index 9633bdae5fd4..91ac478891ce 100644
@@ -153,17 +153,15 @@ static int da280_probe(struct i2c_client *client,
 	return devm_iio_device_register(&client->dev, indio_dev);
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int da280_suspend(struct device *dev)
+static __maybe_unused int da280_suspend(struct device *dev)
 {
 	return da280_enable(to_i2c_client(dev), false);
 }
 
-static int da280_resume(struct device *dev)
+static __maybe_unused int da280_resume(struct device *dev)
 {
 	return da280_enable(to_i2c_client(dev), true);
 }
-#endif
 
 static SIMPLE_DEV_PM_OPS(da280_pm_ops, da280_suspend, da280_resume);
 
Signature · 1 line
2.34.0
author maintainer
#5 lore raw

PATCH 3/49 iio:accel:dmard06: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/accel/dmard06.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/iio/accel/dmard06.c +4 -8
index de2868c28d95..a0e8d0ab700b 100644
@@ -7,6 +7,7 @@
 
 #include <linux/module.h>
 #include <linux/mod_devicetable.h>
+#include <linux/compiler.h>
 #include <linux/i2c.h>
 #include <linux/iio/iio.h>
 
@@ -170,8 +171,7 @@ static int dmard06_probe(struct i2c_client *client,
 	return devm_iio_device_register(&client->dev, indio_dev);
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int dmard06_suspend(struct device *dev)
+static __maybe_unused int dmard06_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct dmard06_data *dmard06 = iio_priv(indio_dev);
@@ -185,7 +185,7 @@ static int dmard06_suspend(struct device *dev)
 	return 0;
 }
 
-static int dmard06_resume(struct device *dev)
+static __maybe_unused int dmard06_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct dmard06_data *dmard06 = iio_priv(indio_dev);
@@ -200,10 +200,6 @@ static int dmard06_resume(struct device *dev)
 }
 
 static SIMPLE_DEV_PM_OPS(dmard06_pm_ops, dmard06_suspend, dmard06_resume);
-#define DMARD06_PM_OPS (&dmard06_pm_ops)
-#else
-#define DMARD06_PM_OPS NULL
-#endif
 
 static const struct i2c_device_id dmard06_id[] = {
 	{ "dmard05", 0 },
@@ -227,7 +223,7 @@ static struct i2c_driver dmard06_driver = {
 	.driver = {
 		.name = DMARD06_DRV_NAME,
 		.of_match_table = dmard06_of_match,
-		.pm = DMARD06_PM_OPS,
+		.pm = pm_ptr(&dmard06_pm_ops),
 	},
 };
 module_i2c_driver(dmard06_driver);
Signature · 1 line
2.34.0
author maintainer
#7 lore raw

PATCH 5/49 iio:accel:mc3230: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/accel/mc3230.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/iio/accel/mc3230.c +3 -5
index 735002b716f3..139c7f6839df 100644
@@ -160,8 +160,7 @@ static int mc3230_remove(struct i2c_client *client)
 	return mc3230_set_opcon(iio_priv(indio_dev), MC3230_MODE_OPCON_STANDBY);
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int mc3230_suspend(struct device *dev)
+static __maybe_unused int mc3230_suspend(struct device *dev)
 {
 	struct mc3230_data *data;
 
@@ -170,7 +169,7 @@ static int mc3230_suspend(struct device *dev)
 	return mc3230_set_opcon(data, MC3230_MODE_OPCON_STANDBY);
 }
 
-static int mc3230_resume(struct device *dev)
+static __maybe_unused int mc3230_resume(struct device *dev)
 {
 	struct mc3230_data *data;
 
@@ -178,7 +177,6 @@ static int mc3230_resume(struct device *dev)
 
 	return mc3230_set_opcon(data, MC3230_MODE_OPCON_WAKE);
 }
-#endif
 
 static SIMPLE_DEV_PM_OPS(mc3230_pm_ops, mc3230_suspend, mc3230_resume);
 
@@ -191,7 +189,7 @@ MODULE_DEVICE_TABLE(i2c, mc3230_i2c_id);
 static struct i2c_driver mc3230_driver = {
 	.driver = {
 		.name = "mc3230",
-		.pm = &mc3230_pm_ops,
+		.pm = pm_ptr(&mc3230_pm_ops),
 	},
 	.probe		= mc3230_probe,
 	.remove		= mc3230_remove,
Signature · 1 line
2.34.0
author maintainer
#6 lore raw

PATCH 4/49 iio:accel:dmard10: Switch from CONFIG_PM guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

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.

---
 drivers/iio/accel/dmard10.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/iio/accel/dmard10.c +4 -5
index f9f173eec202..7ad3349ad60f 100644
@@ -7,6 +7,7 @@
  */
 
 #include <linux/module.h>
+#include <linux/compiler.h>
 #include <linux/i2c.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
@@ -218,17 +219,15 @@ static int dmard10_probe(struct i2c_client *client,
 	return devm_iio_device_register(&client->dev, indio_dev);
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int dmard10_suspend(struct device *dev)
+static int __maybe_unused dmard10_suspend(struct device *dev)
 {
 	return dmard10_shutdown(to_i2c_client(dev));
 }
 
-static int dmard10_resume(struct device *dev)
+static int __maybe_unused dmard10_resume(struct device *dev)
 {
 	return dmard10_reset(to_i2c_client(dev));
 }
-#endif
 
 static SIMPLE_DEV_PM_OPS(dmard10_pm_ops, dmard10_suspend, dmard10_resume);
 
@@ -241,7 +240,7 @@ MODULE_DEVICE_TABLE(i2c, dmard10_i2c_id);
 static struct i2c_driver dmard10_driver = {
 	.driver = {
 		.name = "dmard10",
-		.pm = &dmard10_pm_ops,
+		.pm = pm_ptr(&dmard10_pm_ops),
 	},
 	.probe		= dmard10_probe,
 	.id_table	= dmard10_i2c_id,
Signature · 1 line
2.34.0
author maintainer
#9 lore raw

PATCH 6/49 iio:accel:mma7660: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/accel/mma7660.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/iio/accel/mma7660.c +3 -9
index 24b83ccdb950..e90463b88b91 100644
@@ -222,8 +222,7 @@ static int mma7660_remove(struct i2c_client *client)
 	return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int mma7660_suspend(struct device *dev)
+static __maybe_unused int mma7660_suspend(struct device *dev)
 {
 	struct mma7660_data *data;
 
@@ -232,7 +231,7 @@ static int mma7660_suspend(struct device *dev)
 	return mma7660_set_mode(data, MMA7660_MODE_STANDBY);
 }
 
-static int mma7660_resume(struct device *dev)
+static __maybe_unused int mma7660_resume(struct device *dev)
 {
 	struct mma7660_data *data;
 
@@ -243,11 +242,6 @@ static int mma7660_resume(struct device *dev)
 
 static SIMPLE_DEV_PM_OPS(mma7660_pm_ops, mma7660_suspend, mma7660_resume);
 
-#define MMA7660_PM_OPS (&mma7660_pm_ops)
-#else
-#define MMA7660_PM_OPS NULL
-#endif
-
 static const struct i2c_device_id mma7660_i2c_id[] = {
 	{"mma7660", 0},
 	{}
@@ -270,7 +264,7 @@ MODULE_DEVICE_TABLE(acpi, mma7660_acpi_id);
 static struct i2c_driver mma7660_driver = {
 	.driver = {
 		.name = "mma7660",
-		.pm = MMA7660_PM_OPS,
+		.pm = pm_ptr(&mma7660_pm_ops),
 		.of_match_table = mma7660_of_match,
 		.acpi_match_table = ACPI_PTR(mma7660_acpi_id),
 	},
Signature · 1 line
2.34.0
author maintainer
#10 lore raw

PATCH 7/49 iio:accel:mma9551: Switch from CONFIG_PM guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/accel/mma9551.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
drivers/iio/accel/mma9551.c +6 -10
index 4c359fb05480..67fdd53b811f 100644
@@ -523,8 +523,7 @@ static int mma9551_remove(struct i2c_client *client)
 	return 0;
 }
 
-#ifdef CONFIG_PM
-static int mma9551_runtime_suspend(struct device *dev)
+static __maybe_unused int mma9551_runtime_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct mma9551_data *data = iio_priv(indio_dev);
@@ -541,7 +540,7 @@ static int mma9551_runtime_suspend(struct device *dev)
 	return 0;
 }
 
-static int mma9551_runtime_resume(struct device *dev)
+static __maybe_unused int mma9551_runtime_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct mma9551_data *data = iio_priv(indio_dev);
@@ -555,10 +554,8 @@ static int mma9551_runtime_resume(struct device *dev)
 
 	return 0;
 }
-#endif
 
-#ifdef CONFIG_PM_SLEEP
-static int mma9551_suspend(struct device *dev)
+static __maybe_unused int mma9551_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct mma9551_data *data = iio_priv(indio_dev);
@@ -571,7 +568,7 @@ static int mma9551_suspend(struct device *dev)
 	return ret;
 }
 
-static int mma9551_resume(struct device *dev)
+static __maybe_unused int mma9551_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct mma9551_data *data = iio_priv(indio_dev);
@@ -583,9 +580,8 @@ static int mma9551_resume(struct device *dev)
 
 	return ret;
 }
-#endif
 
-static const struct dev_pm_ops mma9551_pm_ops = {
+static __maybe_unused const struct dev_pm_ops mma9551_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(mma9551_suspend, mma9551_resume)
 	SET_RUNTIME_PM_OPS(mma9551_runtime_suspend,
 			   mma9551_runtime_resume, NULL)
@@ -609,7 +605,7 @@ static struct i2c_driver mma9551_driver = {
 	.driver = {
 		   .name = MMA9551_DRV_NAME,
 		   .acpi_match_table = ACPI_PTR(mma9551_acpi_match),
-		   .pm = &mma9551_pm_ops,
+		   .pm = pm_ptr(&mma9551_pm_ops),
 		   },
 	.probe = mma9551_probe,
 	.remove = mma9551_remove,
Signature · 1 line
2.34.0
author maintainer
#11 lore raw

PATCH 8/49 iio:accel:mma9553: Switch from CONFIG_PM guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/accel/mma9553.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
drivers/iio/accel/mma9553.c +6 -10
index ba3ecb3b57dc..1597806229f4 100644
@@ -1162,8 +1162,7 @@ static int mma9553_remove(struct i2c_client *client)
 	return 0;
 }
 
-#ifdef CONFIG_PM
-static int mma9553_runtime_suspend(struct device *dev)
+static __maybe_unused int mma9553_runtime_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct mma9553_data *data = iio_priv(indio_dev);
@@ -1180,7 +1179,7 @@ static int mma9553_runtime_suspend(struct device *dev)
 	return 0;
 }
 
-static int mma9553_runtime_resume(struct device *dev)
+static __maybe_unused int mma9553_runtime_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct mma9553_data *data = iio_priv(indio_dev);
@@ -1194,10 +1193,8 @@ static int mma9553_runtime_resume(struct device *dev)
 
 	return 0;
 }
-#endif
 
-#ifdef CONFIG_PM_SLEEP
-static int mma9553_suspend(struct device *dev)
+static __maybe_unused int mma9553_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct mma9553_data *data = iio_priv(indio_dev);
@@ -1210,7 +1207,7 @@ static int mma9553_suspend(struct device *dev)
 	return ret;
 }
 
-static int mma9553_resume(struct device *dev)
+static __maybe_unused int mma9553_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct mma9553_data *data = iio_priv(indio_dev);
@@ -1222,9 +1219,8 @@ static int mma9553_resume(struct device *dev)
 
 	return ret;
 }
-#endif
 
-static const struct dev_pm_ops mma9553_pm_ops = {
+static __maybe_unused const struct dev_pm_ops mma9553_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(mma9553_suspend, mma9553_resume)
 	SET_RUNTIME_PM_OPS(mma9553_runtime_suspend,
 			   mma9553_runtime_resume, NULL)
@@ -1248,7 +1244,7 @@ static struct i2c_driver mma9553_driver = {
 	.driver = {
 		   .name = MMA9553_DRV_NAME,
 		   .acpi_match_table = ACPI_PTR(mma9553_acpi_match),
-		   .pm = &mma9553_pm_ops,
+		   .pm = pm_ptr(&mma9553_pm_ops),
 		   },
 	.probe = mma9553_probe,
 	.remove = mma9553_remove,
Signature · 1 line
2.34.0
author maintainer
#12 lore raw

PATCH 9/49 iio:accel:stk8ba50: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/accel/stk8ba50.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/iio/accel/stk8ba50.c +3 -9
index 517c57ed9e94..88506a5e9402 100644
@@ -504,8 +504,7 @@ static int stk8ba50_remove(struct i2c_client *client)
 	return stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND);
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int stk8ba50_suspend(struct device *dev)
+static __maybe_unused int stk8ba50_suspend(struct device *dev)
 {
 	struct stk8ba50_data *data;
 
@@ -514,7 +513,7 @@ static int stk8ba50_suspend(struct device *dev)
 	return stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND);
 }
 
-static int stk8ba50_resume(struct device *dev)
+static __maybe_unused int stk8ba50_resume(struct device *dev)
 {
 	struct stk8ba50_data *data;
 
@@ -525,11 +524,6 @@ static int stk8ba50_resume(struct device *dev)
 
 static SIMPLE_DEV_PM_OPS(stk8ba50_pm_ops, stk8ba50_suspend, stk8ba50_resume);
 
-#define STK8BA50_PM_OPS (&stk8ba50_pm_ops)
-#else
-#define STK8BA50_PM_OPS NULL
-#endif
-
 static const struct i2c_device_id stk8ba50_i2c_id[] = {
 	{"stk8ba50", 0},
 	{}
@@ -546,7 +540,7 @@ MODULE_DEVICE_TABLE(acpi, stk8ba50_acpi_id);
 static struct i2c_driver stk8ba50_driver = {
 	.driver = {
 		.name = "stk8ba50",
-		.pm = STK8BA50_PM_OPS,
+		.pm = pm_ptr(&stk8ba50_pm_ops),
 		.acpi_match_table = ACPI_PTR(stk8ba50_acpi_id),
 	},
 	.probe =            stk8ba50_probe,
Signature · 1 line
2.34.0
author maintainer
#13 lore raw

PATCH 10/49 iio:accel:kxsd9: Switch from CONFIG_PM guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/accel/kxsd9-i2c.c | 2 +-
 drivers/iio/accel/kxsd9-spi.c | 2 +-
 drivers/iio/accel/kxsd9.c     | 8 +++-----
 3 files changed, 5 insertions(+), 7 deletions(-)
drivers/iio/accel/kxsd9-i2c.c +1 -1
index 274b41a6e603..ffe8066b4025 100644
@@ -55,7 +55,7 @@ static struct i2c_driver kxsd9_i2c_driver = {
 	.driver = {
 		.name	= "kxsd9",
 		.of_match_table = kxsd9_of_match,
-		.pm = &kxsd9_dev_pm_ops,
+		.pm = pm_ptr(&kxsd9_dev_pm_ops),
 	},
 	.probe		= kxsd9_i2c_probe,
 	.remove		= kxsd9_i2c_remove,
drivers/iio/accel/kxsd9-spi.c +1 -1
index 441e6b764281..44edf39fc5ff 100644
@@ -54,7 +54,7 @@ MODULE_DEVICE_TABLE(of, kxsd9_of_match);
 static struct spi_driver kxsd9_spi_driver = {
 	.driver = {
 		.name = "kxsd9",
-		.pm = &kxsd9_dev_pm_ops,
+		.pm = pm_ptr(&kxsd9_dev_pm_ops),
 		.of_match_table = kxsd9_of_match,
 	},
 	.probe = kxsd9_spi_probe,
drivers/iio/accel/kxsd9.c +3 -5
index 2faf85ca996e..f9954288914b 100644
@@ -492,8 +492,7 @@ void kxsd9_common_remove(struct device *dev)
 }
 EXPORT_SYMBOL(kxsd9_common_remove);
 
-#ifdef CONFIG_PM
-static int kxsd9_runtime_suspend(struct device *dev)
+static __maybe_unused int kxsd9_runtime_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct kxsd9_state *st = iio_priv(indio_dev);
@@ -501,16 +500,15 @@ static int kxsd9_runtime_suspend(struct device *dev)
 	return kxsd9_power_down(st);
 }
 
-static int kxsd9_runtime_resume(struct device *dev)
+static __maybe_unused int kxsd9_runtime_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct kxsd9_state *st = iio_priv(indio_dev);
 
 	return kxsd9_power_up(st);
 }
-#endif /* CONFIG_PM */
 
-const struct dev_pm_ops kxsd9_dev_pm_ops = {
+const __maybe_unused struct dev_pm_ops kxsd9_dev_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
 				pm_runtime_force_resume)
 	SET_RUNTIME_PM_OPS(kxsd9_runtime_suspend,
Signature · 1 line
2.34.0
author maintainer
#14 lore raw

PATCH 11/49 iio:adc:ab8500: Switch from CONFIG_PM guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/adc/ab8500-gpadc.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/iio/adc/ab8500-gpadc.c +4 -6
index 4c46a201d4ef..3905213e1bfa 100644
@@ -942,8 +942,7 @@ static const struct iio_info ab8500_gpadc_info = {
 	.read_raw = ab8500_gpadc_read_raw,
 };
 
-#ifdef CONFIG_PM
-static int ab8500_gpadc_runtime_suspend(struct device *dev)
+static __maybe_unused int ab8500_gpadc_runtime_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct ab8500_gpadc *gpadc = iio_priv(indio_dev);
@@ -953,7 +952,7 @@ static int ab8500_gpadc_runtime_suspend(struct device *dev)
 	return 0;
 }
 
-static int ab8500_gpadc_runtime_resume(struct device *dev)
+static __maybe_unused int ab8500_gpadc_runtime_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct ab8500_gpadc *gpadc = iio_priv(indio_dev);
@@ -965,7 +964,6 @@ static int ab8500_gpadc_runtime_resume(struct device *dev)
 
 	return ret;
 }
-#endif
 
 /**
  * ab8500_gpadc_parse_channel() - process devicetree channel configuration
@@ -1199,7 +1197,7 @@ static int ab8500_gpadc_remove(struct platform_device *pdev)
 	return 0;
 }
 
-static const struct dev_pm_ops ab8500_gpadc_pm_ops = {
+static __maybe_unused const struct dev_pm_ops ab8500_gpadc_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
 				pm_runtime_force_resume)
 	SET_RUNTIME_PM_OPS(ab8500_gpadc_runtime_suspend,
@@ -1212,7 +1210,7 @@ static struct platform_driver ab8500_gpadc_driver = {
 	.remove = ab8500_gpadc_remove,
 	.driver = {
 		.name = "ab8500-gpadc",
-		.pm = &ab8500_gpadc_pm_ops,
+		.pm = pm_ptr(&ab8500_gpadc_pm_ops),
 	},
 };
 builtin_platform_driver(ab8500_gpadc_driver);
Signature · 1 line
2.34.0
author maintainer
#16 lore raw

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

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 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(-)
drivers/iio/adc/ad7606.c +2 -6
index 0a60ecc69d38..16a013aad20f 100644
@@ -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 <[email protected]>");
 MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
 MODULE_LICENSE("GPL v2");
drivers/iio/adc/ad7606.h +0 -5
index 9350ef1f63b5..fd545836790e 100644
@@ -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_ */
drivers/iio/adc/ad7606_par.c +1 -1
index f732b3ac7878..60be3fb4ae39 100644
@@ -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,
 	},
 };
drivers/iio/adc/ad7606_spi.c +1 -1
index 29945ad07dca..8cc525b4b960 100644
@@ -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,
Signature · 1 line
2.34.0
author maintainer
#18 lore raw

PATCH 13/49 iio:adc:at91-adc: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

Cc Alexandre Belloni <[email protected]>
Cc Ludovic Desroches <[email protected]>
---
 drivers/iio/adc/at91_adc.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/iio/adc/at91_adc.c +3 -5
index 5a7d3a3a5fa8..14a4735d72b5 100644
@@ -1234,8 +1234,7 @@ static int at91_adc_remove(struct platform_device *pdev)
 	return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int at91_adc_suspend(struct device *dev)
+static __maybe_unused int at91_adc_suspend(struct device *dev)
 {
 	struct iio_dev *idev = dev_get_drvdata(dev);
 	struct at91_adc_state *st = iio_priv(idev);
@@ -1246,7 +1245,7 @@ static int at91_adc_suspend(struct device *dev)
 	return 0;
 }
 
-static int at91_adc_resume(struct device *dev)
+static __maybe_unused int at91_adc_resume(struct device *dev)
 {
 	struct iio_dev *idev = dev_get_drvdata(dev);
 	struct at91_adc_state *st = iio_priv(idev);
@@ -1256,7 +1255,6 @@ static int at91_adc_resume(struct device *dev)
 
 	return 0;
 }
-#endif
 
 static SIMPLE_DEV_PM_OPS(at91_adc_pm_ops, at91_adc_suspend, at91_adc_resume);
 
@@ -1386,7 +1384,7 @@ static struct platform_driver at91_adc_driver = {
 	.driver = {
 		   .name = DRIVER_NAME,
 		   .of_match_table = at91_adc_dt_ids,
-		   .pm = &at91_adc_pm_ops,
+		   .pm = pm_ptr(&at91_adc_pm_ops),
 	},
 };
 
Signature · 1 line
2.34.0
author maintainer
#20 lore raw

PATCH 14/49 iio:adc:exynos_adc: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

Cc Krzysztof Kozlowski <[email protected]>
---
 drivers/iio/adc/exynos_adc.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/iio/adc/exynos_adc.c +3 -5
index 3b3868aa2533..01a801d325a9 100644
@@ -968,8 +968,7 @@ static int exynos_adc_remove(struct platform_device *pdev)
 	return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int exynos_adc_suspend(struct device *dev)
+static __maybe_unused int exynos_adc_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct exynos_adc *info = iio_priv(indio_dev);
@@ -982,7 +981,7 @@ static int exynos_adc_suspend(struct device *dev)
 	return 0;
 }
 
-static int exynos_adc_resume(struct device *dev)
+static __maybe_unused int exynos_adc_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct exynos_adc *info = iio_priv(indio_dev);
@@ -1001,7 +1000,6 @@ static int exynos_adc_resume(struct device *dev)
 
 	return 0;
 }
-#endif
 
 static SIMPLE_DEV_PM_OPS(exynos_adc_pm_ops,
 			exynos_adc_suspend,
@@ -1013,7 +1011,7 @@ static struct platform_driver exynos_adc_driver = {
 	.driver		= {
 		.name	= "exynos-adc",
 		.of_match_table = exynos_adc_match,
-		.pm	= &exynos_adc_pm_ops,
+		.pm	= pm_ptr(&exynos_adc_pm_ops),
 	},
 };
 
Signature · 1 line
2.34.0
author maintainer
#22 lore raw

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

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/adc/palmas_gpadc.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/iio/adc/palmas_gpadc.c +6 -8
index f9c8385c72d3..98d7764e0662 100644
@@ -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,
 	},
 };
Signature · 1 line
2.34.0
author maintainer
#24 lore raw

PATCH 16/49 iio:adc:stm32:Switch from CONFIG_PM guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

Cc Fabrice Gasnier <[email protected]>
Cc Olivier Moysan <[email protected]>
---
 drivers/iio/adc/stm32-adc-core.c | 12 +++++-------
 drivers/iio/adc/stm32-adc.c      | 16 ++++++----------
 2 files changed, 11 insertions(+), 17 deletions(-)
drivers/iio/adc/stm32-adc-core.c +5 -7
index b6e18eb101f7..316ae84ab961 100644
@@ -763,28 +763,26 @@ static int stm32_adc_remove(struct platform_device *pdev)
 	return 0;
 }
 
-#if defined(CONFIG_PM)
-static int stm32_adc_core_runtime_suspend(struct device *dev)
+static __maybe_unused int stm32_adc_core_runtime_suspend(struct device *dev)
 {
 	stm32_adc_core_hw_stop(dev);
 
 	return 0;
 }
 
-static int stm32_adc_core_runtime_resume(struct device *dev)
+static __maybe_unused int stm32_adc_core_runtime_resume(struct device *dev)
 {
 	return stm32_adc_core_hw_start(dev);
 }
 
-static int stm32_adc_core_runtime_idle(struct device *dev)
+static __maybe_unused int stm32_adc_core_runtime_idle(struct device *dev)
 {
 	pm_runtime_mark_last_busy(dev);
 
 	return 0;
 }
-#endif
 
-static const struct dev_pm_ops stm32_adc_core_pm_ops = {
+static __maybe_unused const struct dev_pm_ops stm32_adc_core_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
 				pm_runtime_force_resume)
 	SET_RUNTIME_PM_OPS(stm32_adc_core_runtime_suspend,
@@ -836,7 +834,7 @@ static struct platform_driver stm32_adc_driver = {
 	.driver = {
 		.name = "stm32-adc-core",
 		.of_match_table = stm32_adc_of_match,
-		.pm = &stm32_adc_core_pm_ops,
+		.pm = pm_ptr(&stm32_adc_core_pm_ops),
 	},
 };
 module_platform_driver(stm32_adc_driver);
drivers/iio/adc/stm32-adc.c +6 -10
index 7f1fb36c747c..2d94de6de848 100644
@@ -2351,8 +2351,7 @@ static int stm32_adc_remove(struct platform_device *pdev)
 	return 0;
 }
 
-#if defined(CONFIG_PM_SLEEP)
-static int stm32_adc_suspend(struct device *dev)
+static __maybe_unused int stm32_adc_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 
@@ -2362,7 +2361,7 @@ static int stm32_adc_suspend(struct device *dev)
 	return pm_runtime_force_suspend(dev);
 }
 
-static int stm32_adc_resume(struct device *dev)
+static __maybe_unused int stm32_adc_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	int ret;
@@ -2381,21 +2380,18 @@ static int stm32_adc_resume(struct device *dev)
 
 	return stm32_adc_buffer_postenable(indio_dev);
 }
-#endif
 
-#if defined(CONFIG_PM)
-static int stm32_adc_runtime_suspend(struct device *dev)
+static __maybe_unused int stm32_adc_runtime_suspend(struct device *dev)
 {
 	return stm32_adc_hw_stop(dev);
 }
 
-static int stm32_adc_runtime_resume(struct device *dev)
+static __maybe_unused int stm32_adc_runtime_resume(struct device *dev)
 {
 	return stm32_adc_hw_start(dev);
 }
-#endif
 
-static const struct dev_pm_ops stm32_adc_pm_ops = {
+static __maybe_unused const struct dev_pm_ops stm32_adc_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(stm32_adc_suspend, stm32_adc_resume)
 	SET_RUNTIME_PM_OPS(stm32_adc_runtime_suspend, stm32_adc_runtime_resume,
 			   NULL)
@@ -2452,7 +2448,7 @@ static struct platform_driver stm32_adc_driver = {
 	.driver = {
 		.name = "stm32-adc",
 		.of_match_table = stm32_adc_of_match,
-		.pm = &stm32_adc_pm_ops,
+		.pm = pm_ptr(&stm32_adc_pm_ops),
 	},
 };
 module_platform_driver(stm32_adc_driver);
Signature · 1 line
2.34.0
author maintainer
#26 lore raw

PATCH 17/49 iio:adc:rcar: Switch from CONFIG_PM guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/adc/rcar-gyroadc.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/iio/adc/rcar-gyroadc.c +4 -6
index a48895046408..947d72457066 100644
@@ -578,8 +578,7 @@ static int rcar_gyroadc_remove(struct platform_device *pdev)
 	return 0;
 }
 
-#if defined(CONFIG_PM)
-static int rcar_gyroadc_suspend(struct device *dev)
+static __maybe_unused int rcar_gyroadc_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct rcar_gyroadc *priv = iio_priv(indio_dev);
@@ -589,7 +588,7 @@ static int rcar_gyroadc_suspend(struct device *dev)
 	return 0;
 }
 
-static int rcar_gyroadc_resume(struct device *dev)
+static __maybe_unused int rcar_gyroadc_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct rcar_gyroadc *priv = iio_priv(indio_dev);
@@ -598,9 +597,8 @@ static int rcar_gyroadc_resume(struct device *dev)
 
 	return 0;
 }
-#endif
 
-static const struct dev_pm_ops rcar_gyroadc_pm_ops = {
+static __maybe_unused  const struct dev_pm_ops rcar_gyroadc_pm_ops = {
 	SET_RUNTIME_PM_OPS(rcar_gyroadc_suspend, rcar_gyroadc_resume, NULL)
 };
 
@@ -610,7 +608,7 @@ static struct platform_driver rcar_gyroadc_driver = {
 	.driver         = {
 		.name		= DRIVER_NAME,
 		.of_match_table	= rcar_gyroadc_match,
-		.pm		= &rcar_gyroadc_pm_ops,
+		.pm		= pm_ptr(&rcar_gyroadc_pm_ops),
 	},
 };
 
Signature · 1 line
2.34.0
author maintainer
#27 lore raw

PATCH 18/49 iio:adc:rockchip: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/adc/rockchip_saradc.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/iio/adc/rockchip_saradc.c +3 -5
index 14b8df4ca9c8..fb3b59d76a97 100644
@@ -481,8 +481,7 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
 	return devm_iio_device_register(&pdev->dev, indio_dev);
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int rockchip_saradc_suspend(struct device *dev)
+static __maybe_unused int rockchip_saradc_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct rockchip_saradc *info = iio_priv(indio_dev);
@@ -494,7 +493,7 @@ static int rockchip_saradc_suspend(struct device *dev)
 	return 0;
 }
 
-static int rockchip_saradc_resume(struct device *dev)
+static __maybe_unused int rockchip_saradc_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct rockchip_saradc *info = iio_priv(indio_dev);
@@ -514,7 +513,6 @@ static int rockchip_saradc_resume(struct device *dev)
 
 	return ret;
 }
-#endif
 
 static SIMPLE_DEV_PM_OPS(rockchip_saradc_pm_ops,
 			 rockchip_saradc_suspend, rockchip_saradc_resume);
@@ -524,7 +522,7 @@ static struct platform_driver rockchip_saradc_driver = {
 	.driver		= {
 		.name	= "rockchip-saradc",
 		.of_match_table = rockchip_saradc_match,
-		.pm	= &rockchip_saradc_pm_ops,
+		.pm	= pm_ptr(&rockchip_saradc_pm_ops),
 	},
 };
 
Signature · 1 line
2.34.0
author maintainer
#28 lore raw

PATCH 19/49 iio:adc:twl6030: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/adc/twl6030-gpadc.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/iio/adc/twl6030-gpadc.c +3 -5
index afdb59e0b526..cf8e4ed749d1 100644
@@ -944,8 +944,7 @@ static int twl6030_gpadc_remove(struct platform_device *pdev)
 	return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int twl6030_gpadc_suspend(struct device *pdev)
+static __maybe_unused int twl6030_gpadc_suspend(struct device *pdev)
 {
 	int ret;
 
@@ -957,7 +956,7 @@ static int twl6030_gpadc_suspend(struct device *pdev)
 	return 0;
 };
 
-static int twl6030_gpadc_resume(struct device *pdev)
+static __maybe_unused int twl6030_gpadc_resume(struct device *pdev)
 {
 	int ret;
 
@@ -968,7 +967,6 @@ static int twl6030_gpadc_resume(struct device *pdev)
 
 	return 0;
 };
-#endif
 
 static SIMPLE_DEV_PM_OPS(twl6030_gpadc_pm_ops, twl6030_gpadc_suspend,
 					twl6030_gpadc_resume);
@@ -978,7 +976,7 @@ static struct platform_driver twl6030_gpadc_driver = {
 	.remove		= twl6030_gpadc_remove,
 	.driver		= {
 		.name	= DRIVER_NAME,
-		.pm	= &twl6030_gpadc_pm_ops,
+		.pm	= pm_ptr(&twl6030_gpadc_pm_ops),
 		.of_match_table = of_twl6030_match_tbl,
 	},
 };
Signature · 1 line
2.34.0
author maintainer
#29 lore raw

PATCH 20/49 iio:adc:vf610: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

Cc Stefan-Gabriel Mirea <[email protected]>
---
 drivers/iio/adc/vf610_adc.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/iio/adc/vf610_adc.c +3 -5
index fd57fc43e8e5..c05ef6d85093 100644
@@ -912,8 +912,7 @@ static int vf610_adc_remove(struct platform_device *pdev)
 	return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int vf610_adc_suspend(struct device *dev)
+static __maybe_unused int vf610_adc_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct vf610_adc *info = iio_priv(indio_dev);
@@ -930,7 +929,7 @@ static int vf610_adc_suspend(struct device *dev)
 	return 0;
 }
 
-static int vf610_adc_resume(struct device *dev)
+static __maybe_unused int vf610_adc_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct vf610_adc *info = iio_priv(indio_dev);
@@ -952,7 +951,6 @@ static int vf610_adc_resume(struct device *dev)
 	regulator_disable(info->vref);
 	return ret;
 }
-#endif
 
 static SIMPLE_DEV_PM_OPS(vf610_adc_pm_ops, vf610_adc_suspend, vf610_adc_resume);
 
@@ -962,7 +960,7 @@ static struct platform_driver vf610_adc_driver = {
 	.driver         = {
 		.name   = DRIVER_NAME,
 		.of_match_table = vf610_adc_match,
-		.pm     = &vf610_adc_pm_ops,
+		.pm     = pm_ptr(&vf610_adc_pm_ops),
 	},
 };
 
Signature · 1 line
2.34.0
author maintainer
#30 lore raw

PATCH 21/49 iio:common:ssp: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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. Also switch to SIMPLE_DEV_PM_OPS rather than open coding the structure.

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.

---
 drivers/iio/common/ssp_sensors/ssp_dev.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/iio/common/ssp_sensors/ssp_dev.c +4 -8
index 1aee87100038..b5d2c69b5cc9 100644
@@ -612,8 +612,7 @@ static int ssp_remove(struct spi_device *spi)
 	return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int ssp_suspend(struct device *dev)
+static __maybe_unused int ssp_suspend(struct device *dev)
 {
 	int ret;
 	struct ssp_data *data = spi_get_drvdata(to_spi_device(dev));
@@ -638,7 +637,7 @@ static int ssp_suspend(struct device *dev)
 	return 0;
 }
 
-static int ssp_resume(struct device *dev)
+static __maybe_unused int ssp_resume(struct device *dev)
 {
 	int ret;
 	struct ssp_data *data = spi_get_drvdata(to_spi_device(dev));
@@ -661,17 +660,14 @@ static int ssp_resume(struct device *dev)
 
 	return 0;
 }
-#endif /* CONFIG_PM_SLEEP */
 
-static const struct dev_pm_ops ssp_pm_ops = {
-	SET_SYSTEM_SLEEP_PM_OPS(ssp_suspend, ssp_resume)
-};
+static SIMPLE_DEV_PM_OPS(ssp_pm_ops, ssp_suspend, ssp_resume);
 
 static struct spi_driver ssp_driver = {
 	.probe = ssp_probe,
 	.remove = ssp_remove,
 	.driver = {
-		.pm = &ssp_pm_ops,
+		.pm = pm_ptr(&ssp_pm_ops),
 		.of_match_table = of_match_ptr(ssp_of_match),
 		.name = "sensorhub"
 	},
Signature · 1 line
2.34.0
author maintainer
#31 lore raw

PATCH 22/49 iio:dac:vf610: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/dac/vf610_dac.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/iio/dac/vf610_dac.c +3 -5
index 636b4009f763..44b290da078d 100644
@@ -242,8 +242,7 @@ static int vf610_dac_remove(struct platform_device *pdev)
 	return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int vf610_dac_suspend(struct device *dev)
+static __maybe_unused int vf610_dac_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct vf610_dac *info = iio_priv(indio_dev);
@@ -254,7 +253,7 @@ static int vf610_dac_suspend(struct device *dev)
 	return 0;
 }
 
-static int vf610_dac_resume(struct device *dev)
+static __maybe_unused int vf610_dac_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct vf610_dac *info = iio_priv(indio_dev);
@@ -268,7 +267,6 @@ static int vf610_dac_resume(struct device *dev)
 
 	return 0;
 }
-#endif
 
 static SIMPLE_DEV_PM_OPS(vf610_dac_pm_ops, vf610_dac_suspend, vf610_dac_resume);
 
@@ -278,7 +276,7 @@ static struct platform_driver vf610_dac_driver = {
 	.driver         = {
 		.name   = "vf610-dac",
 		.of_match_table = vf610_dac_match,
-		.pm     = &vf610_dac_pm_ops,
+		.pm     = pm_ptr(&vf610_dac_pm_ops),
 	},
 };
 module_platform_driver(vf610_dac_driver);
Signature · 1 line
2.34.0
author maintainer
#32 lore raw

PATCH 23/49 iio:light:apds9300: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/light/apds9300.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/iio/light/apds9300.c +3 -8
index baaf202dce05..56dcd255a649 100644
@@ -466,8 +466,7 @@ static int apds9300_remove(struct i2c_client *client)
 	return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int apds9300_suspend(struct device *dev)
+static __maybe_unused int apds9300_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct apds9300_data *data = iio_priv(indio_dev);
@@ -480,7 +479,7 @@ static int apds9300_suspend(struct device *dev)
 	return ret;
 }
 
-static int apds9300_resume(struct device *dev)
+static __maybe_unused int apds9300_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct apds9300_data *data = iio_priv(indio_dev);
@@ -494,10 +493,6 @@ static int apds9300_resume(struct device *dev)
 }
 
 static SIMPLE_DEV_PM_OPS(apds9300_pm_ops, apds9300_suspend, apds9300_resume);
-#define APDS9300_PM_OPS (&apds9300_pm_ops)
-#else
-#define APDS9300_PM_OPS NULL
-#endif
 
 static const struct i2c_device_id apds9300_id[] = {
 	{ APDS9300_DRV_NAME, 0 },
@@ -509,7 +504,7 @@ MODULE_DEVICE_TABLE(i2c, apds9300_id);
 static struct i2c_driver apds9300_driver = {
 	.driver = {
 		.name	= APDS9300_DRV_NAME,
-		.pm	= APDS9300_PM_OPS,
+		.pm	= pm_ptr(&apds9300_pm_ops),
 	},
 	.probe		= apds9300_probe,
 	.remove		= apds9300_remove,
Signature · 1 line
2.34.0
author maintainer
#33 lore raw

PATCH 24/49 iio:light:bh1780: Switch from CONFIG_PM guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/light/bh1780.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/iio/light/bh1780.c +4 -6
index abbf2e662e7d..d72dd825368a 100644
@@ -221,8 +221,7 @@ static int bh1780_remove(struct i2c_client *client)
 	return 0;
 }
 
-#ifdef CONFIG_PM
-static int bh1780_runtime_suspend(struct device *dev)
+static __maybe_unused int bh1780_runtime_suspend(struct device *dev)
 {
 	struct i2c_client *client = to_i2c_client(dev);
 	struct iio_dev *indio_dev = i2c_get_clientdata(client);
@@ -238,7 +237,7 @@ static int bh1780_runtime_suspend(struct device *dev)
 	return 0;
 }
 
-static int bh1780_runtime_resume(struct device *dev)
+static __maybe_unused int bh1780_runtime_resume(struct device *dev)
 {
 	struct i2c_client *client = to_i2c_client(dev);
 	struct iio_dev *indio_dev = i2c_get_clientdata(client);
@@ -256,9 +255,8 @@ static int bh1780_runtime_resume(struct device *dev)
 
 	return 0;
 }
-#endif /* CONFIG_PM */
 
-static const struct dev_pm_ops bh1780_dev_pm_ops = {
+static __maybe_unused const struct dev_pm_ops bh1780_dev_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
 				pm_runtime_force_resume)
 	SET_RUNTIME_PM_OPS(bh1780_runtime_suspend,
@@ -284,7 +282,7 @@ static struct i2c_driver bh1780_driver = {
 	.id_table	= bh1780_id,
 	.driver = {
 		.name = "bh1780",
-		.pm = &bh1780_dev_pm_ops,
+		.pm = pm_ptr(&bh1780_dev_pm_ops),
 		.of_match_table = of_bh1780_match,
 	},
 };
Signature · 1 line
2.34.0
author maintainer
#35 lore raw

PATCH 25/49 iio:light:cm3232: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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. Also switch to SIMPLE_DEV_PM_OPS rather than opencoding the same.

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.

---
 drivers/iio/light/cm3232.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/iio/light/cm3232.c +4 -9
index 18a410340dc5..660f3204dc18 100644
@@ -374,8 +374,7 @@ static const struct i2c_device_id cm3232_id[] = {
 	{}
 };
 
-#ifdef CONFIG_PM_SLEEP
-static int cm3232_suspend(struct device *dev)
+static __maybe_unused int cm3232_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct cm3232_chip *chip = iio_priv(indio_dev);
@@ -389,7 +388,7 @@ static int cm3232_suspend(struct device *dev)
 	return ret;
 }
 
-static int cm3232_resume(struct device *dev)
+static __maybe_unused int cm3232_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct cm3232_chip *chip = iio_priv(indio_dev);
@@ -403,9 +402,7 @@ static int cm3232_resume(struct device *dev)
 	return ret;
 }
 
-static const struct dev_pm_ops cm3232_pm_ops = {
-	SET_SYSTEM_SLEEP_PM_OPS(cm3232_suspend, cm3232_resume)};
-#endif
+static SIMPLE_DEV_PM_OPS(cm3232_pm_ops, cm3232_suspend, cm3232_resume);
 
 MODULE_DEVICE_TABLE(i2c, cm3232_id);
 
@@ -419,9 +416,7 @@ static struct i2c_driver cm3232_driver = {
 	.driver = {
 		.name	= "cm3232",
 		.of_match_table = cm3232_of_match,
-#ifdef CONFIG_PM_SLEEP
-		.pm	= &cm3232_pm_ops,
-#endif
+		.pm	= pm_ptr(&cm3232_pm_ops),
 	},
 	.id_table	= cm3232_id,
 	.probe		= cm3232_probe,
Signature · 1 line
2.34.0
author maintainer
#36 lore raw

PATCH 26/49 iio:light:isl29018: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

Cc Anson Huang <[email protected]>
Cc Brian Masney <[email protected]>
---
 drivers/iio/light/isl29018.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/iio/light/isl29018.c +3 -8
index 2689867467a8..608bb357b9f6 100644
@@ -784,8 +784,7 @@ static int isl29018_probe(struct i2c_client *client,
 	return devm_iio_device_register(&client->dev, indio_dev);
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int isl29018_suspend(struct device *dev)
+static __maybe_unused int isl29018_suspend(struct device *dev)
 {
 	struct isl29018_chip *chip = iio_priv(dev_get_drvdata(dev));
 	int ret;
@@ -807,7 +806,7 @@ static int isl29018_suspend(struct device *dev)
 	return ret;
 }
 
-static int isl29018_resume(struct device *dev)
+static __maybe_unused int isl29018_resume(struct device *dev)
 {
 	struct isl29018_chip *chip = iio_priv(dev_get_drvdata(dev));
 	int err;
@@ -831,10 +830,6 @@ static int isl29018_resume(struct device *dev)
 }
 
 static SIMPLE_DEV_PM_OPS(isl29018_pm_ops, isl29018_suspend, isl29018_resume);
-#define ISL29018_PM_OPS (&isl29018_pm_ops)
-#else
-#define ISL29018_PM_OPS NULL
-#endif
 
 #ifdef CONFIG_ACPI
 static const struct acpi_device_id isl29018_acpi_match[] = {
@@ -866,7 +861,7 @@ static struct i2c_driver isl29018_driver = {
 	.driver	 = {
 			.name = "isl29018",
 			.acpi_match_table = ACPI_PTR(isl29018_acpi_match),
-			.pm = ISL29018_PM_OPS,
+			.pm = pm_ptr(&isl29018_pm_ops),
 			.of_match_table = isl29018_of_match,
 		    },
 	.probe	 = isl29018_probe,
Signature · 1 line
2.34.0
author maintainer
#37 lore raw

PATCH 27/49 iio:light:isl29125: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/light/isl29125.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/iio/light/isl29125.c +3 -5
index ba53b50d711a..334267595199 100644
@@ -311,22 +311,20 @@ static int isl29125_remove(struct i2c_client *client)
 	return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int isl29125_suspend(struct device *dev)
+static __maybe_unused int isl29125_suspend(struct device *dev)
 {
 	struct isl29125_data *data = iio_priv(i2c_get_clientdata(
 		to_i2c_client(dev)));
 	return isl29125_powerdown(data);
 }
 
-static int isl29125_resume(struct device *dev)
+static __maybe_unused int isl29125_resume(struct device *dev)
 {
 	struct isl29125_data *data = iio_priv(i2c_get_clientdata(
 		to_i2c_client(dev)));
 	return i2c_smbus_write_byte_data(data->client, ISL29125_CONF1,
 		data->conf1);
 }
-#endif
 
 static SIMPLE_DEV_PM_OPS(isl29125_pm_ops, isl29125_suspend, isl29125_resume);
 
@@ -339,7 +337,7 @@ MODULE_DEVICE_TABLE(i2c, isl29125_id);
 static struct i2c_driver isl29125_driver = {
 	.driver = {
 		.name	= ISL29125_DRV_NAME,
-		.pm	= &isl29125_pm_ops,
+		.pm	= pm_ptr(&isl29125_pm_ops),
 	},
 	.probe		= isl29125_probe,
 	.remove		= isl29125_remove,
Signature · 1 line
2.34.0
author maintainer
#38 lore raw

PATCH 28/49 iio:light:jsa1212: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/light/jsa1212.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/iio/light/jsa1212.c +3 -9
index 724a0ec9f35c..218b61595436 100644
@@ -383,8 +383,7 @@ static int jsa1212_remove(struct i2c_client *client)
 	return jsa1212_power_off(data);
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int jsa1212_suspend(struct device *dev)
+static __maybe_unused int jsa1212_suspend(struct device *dev)
 {
 	struct jsa1212_data *data;
 
@@ -393,7 +392,7 @@ static int jsa1212_suspend(struct device *dev)
 	return jsa1212_power_off(data);
 }
 
-static int jsa1212_resume(struct device *dev)
+static __maybe_unused int jsa1212_resume(struct device *dev)
 {
 	int ret = 0;
 	struct jsa1212_data *data;
@@ -423,11 +422,6 @@ static int jsa1212_resume(struct device *dev)
 
 static SIMPLE_DEV_PM_OPS(jsa1212_pm_ops, jsa1212_suspend, jsa1212_resume);
 
-#define JSA1212_PM_OPS (&jsa1212_pm_ops)
-#else
-#define JSA1212_PM_OPS NULL
-#endif
-
 static const struct acpi_device_id jsa1212_acpi_match[] = {
 	{"JSA1212", 0},
 	{ },
@@ -443,7 +437,7 @@ MODULE_DEVICE_TABLE(i2c, jsa1212_id);
 static struct i2c_driver jsa1212_driver = {
 	.driver = {
 		.name	= JSA1212_DRIVER_NAME,
-		.pm	= JSA1212_PM_OPS,
+		.pm	= pm_ptr(&jsa1212_pm_ops),
 		.acpi_match_table = ACPI_PTR(jsa1212_acpi_match),
 	},
 	.probe		= jsa1212_probe,
Signature · 1 line
2.34.0
author maintainer
#39 lore raw

PATCH 29/49 iio:light:ltr501: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/light/ltr501.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/iio/light/ltr501.c +3 -5
index bab5b78f2e30..f64135a4bd0c 100644
@@ -1586,15 +1586,14 @@ static int ltr501_remove(struct i2c_client *client)
 	return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int ltr501_suspend(struct device *dev)
+static __maybe_unused int ltr501_suspend(struct device *dev)
 {
 	struct ltr501_data *data = iio_priv(i2c_get_clientdata(
 					    to_i2c_client(dev)));
 	return ltr501_powerdown(data);
 }
 
-static int ltr501_resume(struct device *dev)
+static __maybe_unused int ltr501_resume(struct device *dev)
 {
 	struct ltr501_data *data = iio_priv(i2c_get_clientdata(
 					    to_i2c_client(dev)));
@@ -1602,7 +1601,6 @@ static int ltr501_resume(struct device *dev)
 	return ltr501_write_contr(data, data->als_contr,
 		data->ps_contr);
 }
-#endif
 
 static SIMPLE_DEV_PM_OPS(ltr501_pm_ops, ltr501_suspend, ltr501_resume);
 
@@ -1636,7 +1634,7 @@ static struct i2c_driver ltr501_driver = {
 	.driver = {
 		.name   = LTR501_DRV_NAME,
 		.of_match_table = ltr501_of_match,
-		.pm	= &ltr501_pm_ops,
+		.pm	= pm_ptr(&ltr501_pm_ops),
 		.acpi_match_table = ACPI_PTR(ltr_acpi_match),
 	},
 	.probe  = ltr501_probe,
Signature · 1 line
2.34.0
author maintainer
#40 lore raw

PATCH 30/49 iio:light:stk3310: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

Cc Icenowy Zheng <[email protected]>
Cc Luca Weiss <[email protected]>
Cc Martijn Braam <[email protected]>
---
 drivers/iio/light/stk3310.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/iio/light/stk3310.c +3 -9
index 07e91846307c..fc2d5ebf0d68 100644
@@ -632,8 +632,7 @@ static int stk3310_remove(struct i2c_client *client)
 	return stk3310_set_state(iio_priv(indio_dev), STK3310_STATE_STANDBY);
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int stk3310_suspend(struct device *dev)
+static __maybe_unused int stk3310_suspend(struct device *dev)
 {
 	struct stk3310_data *data;
 
@@ -642,7 +641,7 @@ static int stk3310_suspend(struct device *dev)
 	return stk3310_set_state(data, STK3310_STATE_STANDBY);
 }
 
-static int stk3310_resume(struct device *dev)
+static __maybe_unused int stk3310_resume(struct device *dev)
 {
 	u8 state = 0;
 	struct stk3310_data *data;
@@ -658,11 +657,6 @@ static int stk3310_resume(struct device *dev)
 
 static SIMPLE_DEV_PM_OPS(stk3310_pm_ops, stk3310_suspend, stk3310_resume);
 
-#define STK3310_PM_OPS (&stk3310_pm_ops)
-#else
-#define STK3310_PM_OPS NULL
-#endif
-
 static const struct i2c_device_id stk3310_i2c_id[] = {
 	{"STK3310", 0},
 	{"STK3311", 0},
@@ -692,7 +686,7 @@ static struct i2c_driver stk3310_driver = {
 	.driver = {
 		.name = "stk3310",
 		.of_match_table = stk3310_of_match,
-		.pm = STK3310_PM_OPS,
+		.pm = pm_ptr(&stk3310_pm_ops),
 		.acpi_match_table = ACPI_PTR(stk3310_acpi_id),
 	},
 	.probe =            stk3310_probe,
Signature · 1 line
2.34.0
author maintainer
#41 lore raw

PATCH 31/49 iio:light:tcs3414: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/light/tcs3414.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/iio/light/tcs3414.c +3 -5
index b87222141429..e6e49054ddfa 100644
@@ -345,22 +345,20 @@ static int tcs3414_probe(struct i2c_client *client,
 	return devm_iio_device_register(&client->dev, indio_dev);
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int tcs3414_suspend(struct device *dev)
+static __maybe_unused int tcs3414_suspend(struct device *dev)
 {
 	struct tcs3414_data *data = iio_priv(i2c_get_clientdata(
 		to_i2c_client(dev)));
 	return tcs3414_powerdown(data);
 }
 
-static int tcs3414_resume(struct device *dev)
+static __maybe_unused int tcs3414_resume(struct device *dev)
 {
 	struct tcs3414_data *data = iio_priv(i2c_get_clientdata(
 		to_i2c_client(dev)));
 	return i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
 		data->control);
 }
-#endif
 
 static SIMPLE_DEV_PM_OPS(tcs3414_pm_ops, tcs3414_suspend, tcs3414_resume);
 
@@ -373,7 +371,7 @@ MODULE_DEVICE_TABLE(i2c, tcs3414_id);
 static struct i2c_driver tcs3414_driver = {
 	.driver = {
 		.name	= TCS3414_DRV_NAME,
-		.pm	= &tcs3414_pm_ops,
+		.pm	= pm_ptr(&tcs3414_pm_ops),
 	},
 	.probe		= tcs3414_probe,
 	.id_table	= tcs3414_id,
Signature · 1 line
2.34.0
author maintainer
#42 lore raw

PATCH 32/49 iio:light:tcs3472: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/light/tcs3472.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/iio/light/tcs3472.c +3 -5
index 371c6a39a165..ff548a562fc2 100644
@@ -572,15 +572,14 @@ static int tcs3472_remove(struct i2c_client *client)
 	return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int tcs3472_suspend(struct device *dev)
+static __maybe_unused int tcs3472_suspend(struct device *dev)
 {
 	struct tcs3472_data *data = iio_priv(i2c_get_clientdata(
 		to_i2c_client(dev)));
 	return tcs3472_powerdown(data);
 }
 
-static int tcs3472_resume(struct device *dev)
+static __maybe_unused int tcs3472_resume(struct device *dev)
 {
 	struct tcs3472_data *data = iio_priv(i2c_get_clientdata(
 		to_i2c_client(dev)));
@@ -598,7 +597,6 @@ static int tcs3472_resume(struct device *dev)
 
 	return ret;
 }
-#endif
 
 static SIMPLE_DEV_PM_OPS(tcs3472_pm_ops, tcs3472_suspend, tcs3472_resume);
 
@@ -611,7 +609,7 @@ MODULE_DEVICE_TABLE(i2c, tcs3472_id);
 static struct i2c_driver tcs3472_driver = {
 	.driver = {
 		.name	= TCS3472_DRV_NAME,
-		.pm	= &tcs3472_pm_ops,
+		.pm	= pm_ptr(&tcs3472_pm_ops),
 	},
 	.probe		= tcs3472_probe,
 	.remove		= tcs3472_remove,
Signature · 1 line
2.34.0
author maintainer
#43 lore raw

PATCH 33/49 iio:light:tsl2563: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/light/tsl2563.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/iio/light/tsl2563.c +3 -8
index 5bf2bfbc5379..49a45c78603c 100644
@@ -814,8 +814,7 @@ static int tsl2563_remove(struct i2c_client *client)
 	return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int tsl2563_suspend(struct device *dev)
+static __maybe_unused int tsl2563_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct tsl2563_chip *chip = iio_priv(indio_dev);
@@ -834,7 +833,7 @@ static int tsl2563_suspend(struct device *dev)
 	return ret;
 }
 
-static int tsl2563_resume(struct device *dev)
+static __maybe_unused int tsl2563_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct tsl2563_chip *chip = iio_priv(indio_dev);
@@ -858,10 +857,6 @@ static int tsl2563_resume(struct device *dev)
 }
 
 static SIMPLE_DEV_PM_OPS(tsl2563_pm_ops, tsl2563_suspend, tsl2563_resume);
-#define TSL2563_PM_OPS (&tsl2563_pm_ops)
-#else
-#define TSL2563_PM_OPS NULL
-#endif
 
 static const struct i2c_device_id tsl2563_id[] = {
 	{ "tsl2560", 0 },
@@ -885,7 +880,7 @@ static struct i2c_driver tsl2563_i2c_driver = {
 	.driver = {
 		.name	 = "tsl2563",
 		.of_match_table = tsl2563_of_match,
-		.pm	= TSL2563_PM_OPS,
+		.pm	= pm_ptr(&tsl2563_pm_ops),
 	},
 	.probe		= tsl2563_probe,
 	.remove		= tsl2563_remove,
Signature · 1 line
2.34.0
author maintainer
#44 lore raw

PATCH 34/49 iio:light:tsl4531: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/light/tsl4531.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/iio/light/tsl4531.c +3 -8
index 70505ba6d858..8632927bc077 100644
@@ -215,23 +215,18 @@ static int tsl4531_remove(struct i2c_client *client)
 	return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int tsl4531_suspend(struct device *dev)
+static __maybe_unused int tsl4531_suspend(struct device *dev)
 {
 	return tsl4531_powerdown(to_i2c_client(dev));
 }
 
-static int tsl4531_resume(struct device *dev)
+static __maybe_unused int tsl4531_resume(struct device *dev)
 {
 	return i2c_smbus_write_byte_data(to_i2c_client(dev), TSL4531_CONTROL,
 		TSL4531_MODE_NORMAL);
 }
 
 static SIMPLE_DEV_PM_OPS(tsl4531_pm_ops, tsl4531_suspend, tsl4531_resume);
-#define TSL4531_PM_OPS (&tsl4531_pm_ops)
-#else
-#define TSL4531_PM_OPS NULL
-#endif
 
 static const struct i2c_device_id tsl4531_id[] = {
 	{ "tsl4531", 0 },
@@ -242,7 +237,7 @@ MODULE_DEVICE_TABLE(i2c, tsl4531_id);
 static struct i2c_driver tsl4531_driver = {
 	.driver = {
 		.name   = TSL4531_DRV_NAME,
-		.pm	= TSL4531_PM_OPS,
+		.pm	= pm_ptr(&tsl4531_pm_ops),
 	},
 	.probe  = tsl4531_probe,
 	.remove = tsl4531_remove,
Signature · 1 line
2.34.0
author maintainer
#45 lore raw

PATCH 35/49 iio:light:us5182: Switch from CONFIG_PM guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/light/us5182d.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/iio/light/us5182d.c +4 -6
index 96e4a66ddf28..79d589f2fb79 100644
@@ -916,8 +916,7 @@ static int us5182d_remove(struct i2c_client *client)
 	return us5182d_shutdown_en(data, US5182D_CFG0_SHUTDOWN_EN);
 }
 
-#if defined(CONFIG_PM_SLEEP) || defined(CONFIG_PM)
-static int us5182d_suspend(struct device *dev)
+static __maybe_unused int us5182d_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct us5182d_data *data = iio_priv(indio_dev);
@@ -928,7 +927,7 @@ static int us5182d_suspend(struct device *dev)
 	return 0;
 }
 
-static int us5182d_resume(struct device *dev)
+static __maybe_unused int us5182d_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct us5182d_data *data = iio_priv(indio_dev);
@@ -939,9 +938,8 @@ static int us5182d_resume(struct device *dev)
 
 	return 0;
 }
-#endif
 
-static const struct dev_pm_ops us5182d_pm_ops = {
+static __maybe_unused const struct dev_pm_ops us5182d_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(us5182d_suspend, us5182d_resume)
 	SET_RUNTIME_PM_OPS(us5182d_suspend, us5182d_resume, NULL)
 };
@@ -969,7 +967,7 @@ MODULE_DEVICE_TABLE(of, us5182d_of_match);
 static struct i2c_driver us5182d_driver = {
 	.driver = {
 		.name = US5182D_DRV_NAME,
-		.pm = &us5182d_pm_ops,
+		.pm = pm_ptr(&us5182d_pm_ops),
 		.of_match_table = us5182d_of_match,
 		.acpi_match_table = ACPI_PTR(us5182d_acpi_match),
 	},
Signature · 1 line
2.34.0
author maintainer
#46 lore raw

PATCH 36/49 iio:magn:ak8975: Switch from CONFIG_PM guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

Cc Matt Ranostay <[email protected]>
Cc Jonathan Albrieux <[email protected]>
Cc Linus Walleij <[email protected]>
---
 drivers/iio/magnetometer/ak8975.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/iio/magnetometer/ak8975.c +4 -6
index 6e82dc54a417..ced3e674eb5f 100644
@@ -1033,8 +1033,7 @@ static int ak8975_remove(struct i2c_client *client)
 	return 0;
 }
 
-#ifdef CONFIG_PM
-static int ak8975_runtime_suspend(struct device *dev)
+static __maybe_unused int ak8975_runtime_suspend(struct device *dev)
 {
 	struct i2c_client *client = to_i2c_client(dev);
 	struct iio_dev *indio_dev = i2c_get_clientdata(client);
@@ -1053,7 +1052,7 @@ static int ak8975_runtime_suspend(struct device *dev)
 	return 0;
 }
 
-static int ak8975_runtime_resume(struct device *dev)
+static __maybe_unused int ak8975_runtime_resume(struct device *dev)
 {
 	struct i2c_client *client = to_i2c_client(dev);
 	struct iio_dev *indio_dev = i2c_get_clientdata(client);
@@ -1074,9 +1073,8 @@ static int ak8975_runtime_resume(struct device *dev)
 
 	return 0;
 }
-#endif /* CONFIG_PM */
 
-static const struct dev_pm_ops ak8975_dev_pm_ops = {
+static __maybe_unused const struct dev_pm_ops ak8975_dev_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
 				pm_runtime_force_resume)
 	SET_RUNTIME_PM_OPS(ak8975_runtime_suspend,
@@ -1113,7 +1111,7 @@ MODULE_DEVICE_TABLE(of, ak8975_of_match);
 static struct i2c_driver ak8975_driver = {
 	.driver = {
 		.name	= "ak8975",
-		.pm = &ak8975_dev_pm_ops,
+		.pm = pm_ptr(&ak8975_dev_pm_ops),
 		.of_match_table = ak8975_of_match,
 		.acpi_match_table = ak_acpi_match,
 	},
Signature · 1 line
2.34.0
author maintainer
#48 lore raw

PATCH 37/49 iio:magn:hmc5843: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/magnetometer/hmc5843.h     | 5 -----
 drivers/iio/magnetometer/hmc5843_i2c.c | 2 +-
 drivers/iio/magnetometer/hmc5843_spi.c | 2 +-
 3 files changed, 2 insertions(+), 7 deletions(-)
drivers/iio/magnetometer/hmc5843.h +0 -5
index 9120c8bbf3dd..c3444f3ab1dc 100644
@@ -55,13 +55,8 @@ void hmc5843_common_remove(struct device *dev);
 int hmc5843_common_suspend(struct device *dev);
 int hmc5843_common_resume(struct device *dev);
 
-#ifdef CONFIG_PM_SLEEP
 static __maybe_unused SIMPLE_DEV_PM_OPS(hmc5843_pm_ops,
 					hmc5843_common_suspend,
 					hmc5843_common_resume);
-#define HMC5843_PM_OPS (&hmc5843_pm_ops)
-#else
-#define HMC5843_PM_OPS NULL
-#endif
 
 #endif /* HMC5843_CORE_H */
drivers/iio/magnetometer/hmc5843_i2c.c +1 -1
index bc6e12f1d521..a7359f439f10 100644
@@ -93,7 +93,7 @@ MODULE_DEVICE_TABLE(of, hmc5843_of_match);
 static struct i2c_driver hmc5843_driver = {
 	.driver = {
 		.name	= "hmc5843",
-		.pm	= HMC5843_PM_OPS,
+		.pm	= pm_ptr(&hmc5843_pm_ops),
 		.of_match_table = hmc5843_of_match,
 	},
 	.id_table	= hmc5843_id,
drivers/iio/magnetometer/hmc5843_spi.c +1 -1
index 89cf59a62c28..c1bd2ff3c64a 100644
@@ -90,7 +90,7 @@ MODULE_DEVICE_TABLE(spi, hmc5843_id);
 static struct spi_driver hmc5843_driver = {
 		.driver = {
 				.name = "hmc5843",
-				.pm = HMC5843_PM_OPS,
+				.pm = pm_ptr(&hmc5843_pm_ops),
 		},
 		.id_table = hmc5843_id,
 		.probe = hmc5843_spi_probe,
Signature · 1 line
2.34.0
author maintainer
#53 lore raw

PATCH 41/49 iio:pressure:bmp280: Switch from CONFIG_PM guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/pressure/bmp280-core.c | 6 ++----
 drivers/iio/pressure/bmp280-i2c.c  | 2 +-
 drivers/iio/pressure/bmp280-spi.c  | 2 +-
 3 files changed, 4 insertions(+), 6 deletions(-)
drivers/iio/pressure/bmp280-core.c +2 -4
index 6b7da40f99c8..0653e1ea88da 100644
@@ -1138,8 +1138,7 @@ int bmp280_common_probe(struct device *dev,
 }
 EXPORT_SYMBOL(bmp280_common_probe);
 
-#ifdef CONFIG_PM
-static int bmp280_runtime_suspend(struct device *dev)
+static __maybe_unused int bmp280_runtime_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct bmp280_data *data = iio_priv(indio_dev);
@@ -1147,7 +1146,7 @@ static int bmp280_runtime_suspend(struct device *dev)
 	return regulator_bulk_disable(BMP280_NUM_SUPPLIES, data->supplies);
 }
 
-static int bmp280_runtime_resume(struct device *dev)
+static __maybe_unused int bmp280_runtime_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct bmp280_data *data = iio_priv(indio_dev);
@@ -1159,7 +1158,6 @@ static int bmp280_runtime_resume(struct device *dev)
 	usleep_range(data->start_up_time, data->start_up_time + 100);
 	return data->chip_info->chip_config(data);
 }
-#endif /* CONFIG_PM */
 
 const struct dev_pm_ops bmp280_dev_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
drivers/iio/pressure/bmp280-i2c.c +1 -1
index 8b03ea15c0d0..35045bd92846 100644
@@ -58,7 +58,7 @@ static struct i2c_driver bmp280_i2c_driver = {
 	.driver = {
 		.name	= "bmp280",
 		.of_match_table = bmp280_of_i2c_match,
-		.pm = &bmp280_dev_pm_ops,
+		.pm = pm_ptr(&bmp280_dev_pm_ops),
 	},
 	.probe		= bmp280_i2c_probe,
 	.id_table	= bmp280_i2c_id,
drivers/iio/pressure/bmp280-spi.c +1 -1
index 625b86878ad8..41f6cc56d229 100644
@@ -109,7 +109,7 @@ static struct spi_driver bmp280_spi_driver = {
 	.driver = {
 		.name = "bmp280",
 		.of_match_table = bmp280_of_spi_match,
-		.pm = &bmp280_dev_pm_ops,
+		.pm = pm_ptr(&bmp280_dev_pm_ops),
 	},
 	.id_table = bmp280_spi_id,
 	.probe = bmp280_spi_probe,
Signature · 1 line
2.34.0
author maintainer
#51 lore raw

PATCH 39/49 iio:magn:mmc35240: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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. Also use SIMPLE_DEV_PM_OPS instead of open-coding the equivalent.

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.

---
 drivers/iio/magnetometer/mmc35240.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/iio/magnetometer/mmc35240.c +4 -8
index 65f3d1ed0d59..57ecb6adeb1b 100644
@@ -521,8 +521,7 @@ static int mmc35240_probe(struct i2c_client *client,
 	return devm_iio_device_register(&client->dev, indio_dev);
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int mmc35240_suspend(struct device *dev)
+static __maybe_unused int mmc35240_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct mmc35240_data *data = iio_priv(indio_dev);
@@ -532,7 +531,7 @@ static int mmc35240_suspend(struct device *dev)
 	return 0;
 }
 
-static int mmc35240_resume(struct device *dev)
+static __maybe_unused int mmc35240_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct mmc35240_data *data = iio_priv(indio_dev);
@@ -548,11 +547,8 @@ static int mmc35240_resume(struct device *dev)
 
 	return 0;
 }
-#endif
 
-static const struct dev_pm_ops mmc35240_pm_ops = {
-	SET_SYSTEM_SLEEP_PM_OPS(mmc35240_suspend, mmc35240_resume)
-};
+static SIMPLE_DEV_PM_OPS(mmc35240_pm_ops, mmc35240_suspend, mmc35240_resume);
 
 static const struct of_device_id mmc35240_of_match[] = {
 	{ .compatible = "memsic,mmc35240", },
@@ -576,7 +572,7 @@ static struct i2c_driver mmc35240_driver = {
 	.driver = {
 		.name = MMC35240_DRV_NAME,
 		.of_match_table = mmc35240_of_match,
-		.pm = &mmc35240_pm_ops,
+		.pm = pm_ptr(&mmc35240_pm_ops),
 		.acpi_match_table = ACPI_PTR(mmc35240_acpi_match),
 	},
 	.probe		= mmc35240_probe,
Signature · 1 line
2.34.0
author maintainer
#52 lore raw

PATCH 40/49 iio:pressure:mpl3115: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/pressure/mpl3115.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/iio/pressure/mpl3115.c +3 -8
index e95b9a5475b4..8148655537c9 100644
@@ -301,14 +301,13 @@ static int mpl3115_remove(struct i2c_client *client)
 	return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int mpl3115_suspend(struct device *dev)
+static __maybe_unused int mpl3115_suspend(struct device *dev)
 {
 	return mpl3115_standby(iio_priv(i2c_get_clientdata(
 		to_i2c_client(dev))));
 }
 
-static int mpl3115_resume(struct device *dev)
+static __maybe_unused int mpl3115_resume(struct device *dev)
 {
 	struct mpl3115_data *data = iio_priv(i2c_get_clientdata(
 		to_i2c_client(dev)));
@@ -318,10 +317,6 @@ static int mpl3115_resume(struct device *dev)
 }
 
 static SIMPLE_DEV_PM_OPS(mpl3115_pm_ops, mpl3115_suspend, mpl3115_resume);
-#define MPL3115_PM_OPS (&mpl3115_pm_ops)
-#else
-#define MPL3115_PM_OPS NULL
-#endif
 
 static const struct i2c_device_id mpl3115_id[] = {
 	{ "mpl3115", 0 },
@@ -339,7 +334,7 @@ static struct i2c_driver mpl3115_driver = {
 	.driver = {
 		.name	= "mpl3115",
 		.of_match_table = mpl3115_of_match,
-		.pm	= MPL3115_PM_OPS,
+		.pm	= pm_ptr(&mpl3115_pm_ops),
 	},
 	.probe = mpl3115_probe,
 	.remove = mpl3115_remove,
Signature · 1 line
2.34.0
author maintainer
#50 lore raw

PATCH 38/49 iio:magn:mag3110: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/magnetometer/mag3110.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/iio/magnetometer/mag3110.c +3 -8
index 17c62d806218..475fdff037f7 100644
@@ -573,8 +573,7 @@ static int mag3110_remove(struct i2c_client *client)
 	return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int mag3110_suspend(struct device *dev)
+static __maybe_unused int mag3110_suspend(struct device *dev)
 {
 	struct mag3110_data *data = iio_priv(i2c_get_clientdata(
 		to_i2c_client(dev)));
@@ -600,7 +599,7 @@ static int mag3110_suspend(struct device *dev)
 	return 0;
 }
 
-static int mag3110_resume(struct device *dev)
+static __maybe_unused int mag3110_resume(struct device *dev)
 {
 	struct mag3110_data *data = iio_priv(i2c_get_clientdata(
 		to_i2c_client(dev)));
@@ -624,10 +623,6 @@ static int mag3110_resume(struct device *dev)
 }
 
 static SIMPLE_DEV_PM_OPS(mag3110_pm_ops, mag3110_suspend, mag3110_resume);
-#define MAG3110_PM_OPS (&mag3110_pm_ops)
-#else
-#define MAG3110_PM_OPS NULL
-#endif
 
 static const struct i2c_device_id mag3110_id[] = {
 	{ "mag3110", 0 },
@@ -645,7 +640,7 @@ static struct i2c_driver mag3110_driver = {
 	.driver = {
 		.name	= "mag3110",
 		.of_match_table = mag3110_of_match,
-		.pm	= MAG3110_PM_OPS,
+		.pm	= pm_ptr(&mag3110_pm_ops),
 	},
 	.probe = mag3110_probe,
 	.remove = mag3110_remove,
Signature · 1 line
2.34.0
author maintainer
#56 lore raw

PATCH 42/49 iio:proximity:as3935: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/proximity/as3935.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/iio/proximity/as3935.c +3 -9
index d62766b6b39e..605c6095d704 100644
@@ -295,8 +295,7 @@ 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)
+static __maybe_unused int as3935_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct as3935_state *st = iio_priv(indio_dev);
@@ -316,7 +315,7 @@ static int as3935_suspend(struct device *dev)
 	return ret;
 }
 
-static int as3935_resume(struct device *dev)
+static __maybe_unused int as3935_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct as3935_state *st = iio_priv(indio_dev);
@@ -338,11 +337,6 @@ static int as3935_resume(struct device *dev)
 }
 
 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
 
 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_ptr(&as3935_pm_ops),
 	},
 	.probe		= as3935_probe,
 	.id_table	= as3935_id,
Signature · 1 line
2.34.0
author maintainer
#58 lore raw

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

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/proximity/pulsedlight-lidar-lite-v2.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/iio/proximity/pulsedlight-lidar-lite-v2.c +4 -6
index 27026c060ab9..6adc2a0c27cb 100644
@@ -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,
Signature · 1 line
2.34.0
author maintainer
#61 lore raw

PATCH 44/49 iio:proximity:rfd77492: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/proximity/rfd77402.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/iio/proximity/rfd77402.c +3 -5
index 8c06d02139b6..456afeb71db1 100644
@@ -295,17 +295,15 @@ static int rfd77402_probe(struct i2c_client *client,
 	return devm_iio_device_register(&client->dev, indio_dev);
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int rfd77402_suspend(struct device *dev)
+static __maybe_unused int rfd77402_suspend(struct device *dev)
 {
 	return rfd77402_powerdown(to_i2c_client(dev));
 }
 
-static int rfd77402_resume(struct device *dev)
+static __maybe_unused int rfd77402_resume(struct device *dev)
 {
 	return rfd77402_init(to_i2c_client(dev));
 }
-#endif
 
 static SIMPLE_DEV_PM_OPS(rfd77402_pm_ops, rfd77402_suspend, rfd77402_resume);
 
@@ -318,7 +316,7 @@ MODULE_DEVICE_TABLE(i2c, rfd77402_id);
 static struct i2c_driver rfd77402_driver = {
 	.driver = {
 		.name   = RFD77402_DRV_NAME,
-		.pm     = &rfd77402_pm_ops,
+		.pm     = pm_ptr(&rfd77402_pm_ops),
 	},
 	.probe  = rfd77402_probe,
 	.id_table = rfd77402_id,
Signature · 1 line
2.34.0
author maintainer
#62 lore raw

PATCH 45/49 iio:proximity:sx9500: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/proximity/sx9500.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/iio/proximity/sx9500.c +4 -8
index 3e4ddb2e8c2b..f59bee2707ca 100644
@@ -993,8 +993,7 @@ static int sx9500_remove(struct i2c_client *client)
 	return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int sx9500_suspend(struct device *dev)
+static __maybe_unused int sx9500_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct sx9500_data *data = iio_priv(indio_dev);
@@ -1017,7 +1016,7 @@ static int sx9500_suspend(struct device *dev)
 	return ret;
 }
 
-static int sx9500_resume(struct device *dev)
+static __maybe_unused int sx9500_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
 	struct sx9500_data *data = iio_priv(indio_dev);
@@ -1030,11 +1029,8 @@ static int sx9500_resume(struct device *dev)
 
 	return ret;
 }
-#endif /* CONFIG_PM_SLEEP */
 
-static const struct dev_pm_ops sx9500_pm_ops = {
-	SET_SYSTEM_SLEEP_PM_OPS(sx9500_suspend, sx9500_resume)
-};
+static SIMPLE_DEV_PM_OPS(sx9500_pm_ops, sx9500_suspend, sx9500_resume);
 
 static const struct acpi_device_id sx9500_acpi_match[] = {
 	{"SSX9500", 0},
@@ -1060,7 +1056,7 @@ static struct i2c_driver sx9500_driver = {
 		.name	= SX9500_DRIVER_NAME,
 		.acpi_match_table = ACPI_PTR(sx9500_acpi_match),
 		.of_match_table = of_match_ptr(sx9500_of_match),
-		.pm = &sx9500_pm_ops,
+		.pm = pm_ptr(&sx9500_pm_ops),
 	},
 	.probe		= sx9500_probe,
 	.remove		= sx9500_remove,
Signature · 1 line
2.34.0
author maintainer
#63 lore raw

PATCH 46/49 iio:temperature:tmp006: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/temperature/tmp006.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/iio/temperature/tmp006.c +3 -5
index e4943a0bc9aa..beac388e56f5 100644
@@ -261,17 +261,15 @@ static int tmp006_probe(struct i2c_client *client,
 	return devm_iio_device_register(&client->dev, indio_dev);
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int tmp006_suspend(struct device *dev)
+static __maybe_unused int tmp006_suspend(struct device *dev)
 {
 	return tmp006_power(dev, false);
 }
 
-static int tmp006_resume(struct device *dev)
+static __maybe_unused int tmp006_resume(struct device *dev)
 {
 	return tmp006_power(dev, true);
 }
-#endif
 
 static SIMPLE_DEV_PM_OPS(tmp006_pm_ops, tmp006_suspend, tmp006_resume);
 
@@ -284,7 +282,7 @@ MODULE_DEVICE_TABLE(i2c, tmp006_id);
 static struct i2c_driver tmp006_driver = {
 	.driver = {
 		.name	= "tmp006",
-		.pm	= &tmp006_pm_ops,
+		.pm	= pm_ptr(&tmp006_pm_ops),
 	},
 	.probe = tmp006_probe,
 	.id_table = tmp006_id,
Signature · 1 line
2.34.0
author maintainer
#64 lore raw

PATCH 47/49 iio:temperature:tmp007: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

Cc Manivannan Sadhasivam <[email protected]>
---
 drivers/iio/temperature/tmp007.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/iio/temperature/tmp007.c +3 -5
index b422371a4674..9a1b7f63500e 100644
@@ -537,8 +537,7 @@ static int tmp007_probe(struct i2c_client *client,
 	return devm_iio_device_register(&client->dev, indio_dev);
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int tmp007_suspend(struct device *dev)
+static __maybe_unused int tmp007_suspend(struct device *dev)
 {
 	struct tmp007_data *data = iio_priv(i2c_get_clientdata(
 			to_i2c_client(dev)));
@@ -546,7 +545,7 @@ static int tmp007_suspend(struct device *dev)
 	return tmp007_powerdown(data);
 }
 
-static int tmp007_resume(struct device *dev)
+static __maybe_unused int tmp007_resume(struct device *dev)
 {
 	struct tmp007_data *data = iio_priv(i2c_get_clientdata(
 			to_i2c_client(dev)));
@@ -554,7 +553,6 @@ static int tmp007_resume(struct device *dev)
 	return i2c_smbus_write_word_swapped(data->client, TMP007_CONFIG,
 			data->config | TMP007_CONFIG_CONV_EN);
 }
-#endif
 
 static SIMPLE_DEV_PM_OPS(tmp007_pm_ops, tmp007_suspend, tmp007_resume);
 
@@ -574,7 +572,7 @@ static struct i2c_driver tmp007_driver = {
 	.driver = {
 		.name	= "tmp007",
 		.of_match_table = tmp007_of_match,
-		.pm	= &tmp007_pm_ops,
+		.pm	= pm_ptr(&tmp007_pm_ops),
 	},
 	.probe		= tmp007_probe,
 	.id_table	= tmp007_id,
Signature · 1 line
2.34.0
author maintainer
#65 lore raw

PATCH 48/49 iio:gyro:mpu3050: Switch from CONFIG_PM guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/gyro/mpu3050-core.c | 8 +++-----
 drivers/iio/gyro/mpu3050-i2c.c  | 2 +-
 2 files changed, 4 insertions(+), 6 deletions(-)
drivers/iio/gyro/mpu3050-core.c +3 -5
index ea387efab62d..4ec107b9e779 100644
@@ -1281,19 +1281,17 @@ int mpu3050_common_remove(struct device *dev)
 }
 EXPORT_SYMBOL(mpu3050_common_remove);
 
-#ifdef CONFIG_PM
-static int mpu3050_runtime_suspend(struct device *dev)
+static __maybe_unused int mpu3050_runtime_suspend(struct device *dev)
 {
 	return mpu3050_power_down(iio_priv(dev_get_drvdata(dev)));
 }
 
-static int mpu3050_runtime_resume(struct device *dev)
+static __maybe_unused int mpu3050_runtime_resume(struct device *dev)
 {
 	return mpu3050_power_up(iio_priv(dev_get_drvdata(dev)));
 }
-#endif /* CONFIG_PM */
 
-const struct dev_pm_ops mpu3050_dev_pm_ops = {
+const __maybe_unused struct dev_pm_ops mpu3050_dev_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
 				pm_runtime_force_resume)
 	SET_RUNTIME_PM_OPS(mpu3050_runtime_suspend,
drivers/iio/gyro/mpu3050-i2c.c +1 -1
index ef5bcbc4b45b..820133cad601 100644
@@ -114,7 +114,7 @@ static struct i2c_driver mpu3050_i2c_driver = {
 	.driver = {
 		.of_match_table = mpu3050_i2c_of_match,
 		.name = "mpu3050-i2c",
-		.pm = &mpu3050_dev_pm_ops,
+		.pm = pm_ptr(&mpu3050_dev_pm_ops),
 	},
 };
 module_i2c_driver(mpu3050_i2c_driver);
Signature · 1 line
2.34.0
author maintainer
#68 lore raw

PATCH 49/49 iio:chemical:atlas: Switch from CONFIG_PM guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/chemical/atlas-sensor.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/iio/chemical/atlas-sensor.c +4 -6
index 04b44a327614..7bacd0bd6f19 100644
@@ -737,8 +737,7 @@ static int atlas_remove(struct i2c_client *client)
 	return atlas_set_powermode(data, 0);
 }
 
-#ifdef CONFIG_PM
-static int atlas_runtime_suspend(struct device *dev)
+static __maybe_unused int atlas_runtime_suspend(struct device *dev)
 {
 	struct atlas_data *data =
 		     iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
@@ -746,16 +745,15 @@ static int atlas_runtime_suspend(struct device *dev)
 	return atlas_set_powermode(data, 0);
 }
 
-static int atlas_runtime_resume(struct device *dev)
+static __maybe_unused int atlas_runtime_resume(struct device *dev)
 {
 	struct atlas_data *data =
 		     iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
 
 	return atlas_set_powermode(data, 1);
 }
-#endif
 
-static const struct dev_pm_ops atlas_pm_ops = {
+static __maybe_unused const struct dev_pm_ops atlas_pm_ops = {
 	SET_RUNTIME_PM_OPS(atlas_runtime_suspend,
 			   atlas_runtime_resume, NULL)
 };
@@ -764,7 +762,7 @@ static struct i2c_driver atlas_driver = {
 	.driver = {
 		.name	= ATLAS_DRV_NAME,
 		.of_match_table	= atlas_dt_ids,
-		.pm	= &atlas_pm_ops,
+		.pm	= pm_ptr(&atlas_pm_ops),
 	},
 	.probe		= atlas_probe,
 	.remove		= atlas_remove,
Signature · 1 line
2.34.0
Reviewed-by on v1 5/49
#8 lore raw

Re: [PATCH 05/49] iio:accel:mc3230: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

Hi,

Quoted 9 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

Quoted 6 lines

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.

Thanks, patch looks good to me:

Regards,

Hans

Quoted 45 lines
---
 drivers/iio/accel/mc3230.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/iio/accel/mc3230.c +3 -5
index 735002b716f3..139c7f6839df 100644
@@ -160,8 +160,7 @@ static int mc3230_remove(struct i2c_client *client)
 	return mc3230_set_opcon(iio_priv(indio_dev), MC3230_MODE_OPCON_STANDBY);
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int mc3230_suspend(struct device *dev)
+static __maybe_unused int mc3230_suspend(struct device *dev)
 {
 	struct mc3230_data *data;
 
@@ -170,7 +169,7 @@ static int mc3230_suspend(struct device *dev)
 	return mc3230_set_opcon(data, MC3230_MODE_OPCON_STANDBY);
 }
 
-static int mc3230_resume(struct device *dev)
+static __maybe_unused int mc3230_resume(struct device *dev)
 {
 	struct mc3230_data *data;
 
@@ -178,7 +177,6 @@ static int mc3230_resume(struct device *dev)
 
 	return mc3230_set_opcon(data, MC3230_MODE_OPCON_WAKE);
 }
-#endif
 
 static SIMPLE_DEV_PM_OPS(mc3230_pm_ops, mc3230_suspend, mc3230_resume);
 
@@ -191,7 +189,7 @@ MODULE_DEVICE_TABLE(i2c, mc3230_i2c_id);
 static struct i2c_driver mc3230_driver = {
 	.driver = {
 		.name = "mc3230",
-		.pm = &mc3230_pm_ops,
+		.pm = pm_ptr(&mc3230_pm_ops),
 	},
 	.probe		= mc3230_probe,
 	.remove		= mc3230_remove,
#70 lore raw
In reply to Jonathan Cameron

Hi Jonathan,

Cc'd Arnd who may have some interest in the topic.

Quoted 27 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Note this series includes many drivers that are quite old and I'm not sure have active maintainers. Hence if anyone has time to look at some of these beyond their own drivers and sanity check them it would be much appreciated!

Two motivations behind this set.
1 - General code reduction and improvement in readability in these drivers. 2 - Reduce change I'll have to ask people to change how they do this in
future patches.

Mostly this is just a case of letting the compiler work out it can remove the PM related functions rather than using #ifdefs in the code to do so.

The __maybe_unused markings make it clear we are intentionally building functions that the compiler can see are unused and remove in some build configurations.

The new pm_ptr() macro is rather convenient to got futher than many of the drivers were and when CONFIG_PM is not define ensure that the struct dev_pm_ops can also be removed. Note there is a subtlty in that we only remove that whe CONFIG_PM is not defined whereas a few of these drivers were using CONFIG_PM_SLEEP which is a tighter condition (will remove the structure in more configurations). I think that's a small price to pay for the convenience this macro brings.

Quoted 6 lines

I did this set as one patch per driver, as personally I prefer that option for all but the most trivial patches because it makes backports that cross with this series simpler and also avoid the complex tag giving we get for sets touching code from many authors.

All comments welcome.

One word about the pm_ptr() macro. Right now it's defined as:
#ifdef CONFIG_PM
#define pm_ptr(_ptr) (_ptr)
#else
#define pm_ptr(_ptr) NULL
#endif

It could be possible to define it like this instead:
#define pm_ptr(_ptr) PTR_IF(IS_ENABLED(CONFIG_PM), (_ptr))

The difference is that if !CONFIG_PM, in the first case the (_ptr) is not visible by the compiler and the __maybe_unused is required, while in the second case the (_ptr) is always visible by the compiler, but discarded as dead code. The reason we'd want that is the same reason we use IS_ENABLED() instead of macro guards; and you wouldn't need the __maybe_unused attribute anywhere.

The problem then is that the SET_*_PM_OPS macros are defined differently according to CONFIG_PM, so their definition would need to be changed to use the (redefined) pm_ptr() macro and a corresponding pm_sleep_ptr() macro. Unfortunately since the SET_*_PM_OPS macros are used everywhere with code wrapped around #ifdef CONFIG_PM guards, it wouldn't be easy to change them, and it would just be easier to introduce new macros.

The patchset looks fine as-is and I am not asking you to work on anything I just said, I just thought it was worth mentioning.

Cheers,
-Paul

Quoted 197 lines
Cc Alexandre Belloni <[email protected]>
Cc Anson Huang <[email protected]>
Cc Brian Masney <[email protected]>
Cc Fabrice Gasnier <[email protected]>
Cc Hans de Goede <[email protected]>
Cc Heiko Stuebner <[email protected]>
Cc Icenowy Zheng <[email protected]>
Cc Jonathan Albrieux <[email protected]>
Cc Krzysztof Kozlowski <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Luca Weiss <[email protected]>
Cc Ludovic Desroches <[email protected]>
Cc Manivannan Sadhasivam <[email protected]>
Cc Martijn Braam <[email protected]>
Cc Maslov Dmitry <[email protected]>
Cc Matt Ranostay <[email protected]
Cc Olivier Moysan <[email protected]>
Cc Stefan-Gabriel Mirea <[email protected]>
Cc Vaishnav M A <[email protected]>

Jonathan Cameron (49):
iio:accel:da311: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:accel:da280: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:accel:dmard06: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:accel:dmard10: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:accel:mc3230: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:accel:mma7660: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:accel:mma9551: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:accel:mma9553: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:accel:stk8ba50: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:accel:kxsd9: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:adc:ab8500: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:adc:ad7606: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:adc:at91-adc: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:adc:exynos_adc: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:adc:palmas_gpadc: Switch from CONFIG_PM_SLEEP guards to
pm_ptr() /
__maybe_unused
iio:adc:stm32:Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:adc:rcar: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:adc:rockchip: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:adc:twl6030: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:adc:vf610: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:common:ssp: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:dac:vf610: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:apds9300: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:bh1780: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:light:cm3232: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:isl29018: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:isl29125: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:jsa1212: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:ltr501: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:stk3310: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:tcs3414: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:tcs3472: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:tsl2563: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:tsl4531: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:us5182: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:magn:ak8975: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:magn:hmc5843: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:magn:mag3110: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:magn:mmc35240: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:pressure:mpl3115: Switch from CONFIG_PM_SLEEP guards to
pm_ptr() /
__maybe_unused
iio:pressure:bmp280: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:proximity:as3935: Switch from CONFIG_PM_SLEEP guards to
pm_ptr() /
__maybe_unused
iio:proximity:pulsedlight: Switch from CONFIG_PM guards to pm_ptr()
/
__maybe_unused
iio:proximity:rfd77492: Switch from CONFIG_PM_SLEEP guards to
pm_ptr()
/ __maybe_unused
iio:proximity:sx9500: Switch from CONFIG_PM_SLEEP guards to
pm_ptr() /
__maybe_unused
iio:temperature:tmp006: Switch from CONFIG_PM_SLEEP guards to
pm_ptr()
/ __maybe_unused
iio:temperature:tmp007: Switch from CONFIG_PM_SLEEP guards to
pm_ptr()
/ __maybe_unused
iio:gyro:mpu3050: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:chemical:atlas: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused

 drivers/iio/accel/da280.c                        |  6 ++----
 drivers/iio/accel/da311.c                        |  8 +++-----
 drivers/iio/accel/dmard06.c                      | 12 ++++--------
 drivers/iio/accel/dmard10.c                      |  9 ++++-----
 drivers/iio/accel/kxsd9-i2c.c                    |  2 +-
 drivers/iio/accel/kxsd9-spi.c                    |  2 +-
 drivers/iio/accel/kxsd9.c                        |  8 +++-----
 drivers/iio/accel/mc3230.c                       |  8 +++-----
 drivers/iio/accel/mma7660.c                      | 12 +++---------
 drivers/iio/accel/mma9551.c                      | 16 
++++++----------
 drivers/iio/accel/mma9553.c                      | 16 
++++++----------
 drivers/iio/accel/stk8ba50.c                     | 12 +++---------
 drivers/iio/adc/ab8500-gpadc.c                   | 10 ++++------
 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 +-
 drivers/iio/adc/at91_adc.c                       |  8 +++-----
 drivers/iio/adc/exynos_adc.c                     |  8 +++-----
 drivers/iio/adc/palmas_gpadc.c                   | 14 ++++++--------
 drivers/iio/adc/rcar-gyroadc.c                   | 10 ++++------
 drivers/iio/adc/rockchip_saradc.c                |  8 +++-----
 drivers/iio/adc/stm32-adc-core.c                 | 12 +++++-------
 drivers/iio/adc/stm32-adc.c                      | 16 
++++++----------
 drivers/iio/adc/twl6030-gpadc.c                  |  8 +++-----
 drivers/iio/adc/vf610_adc.c                      |  8 +++-----
 drivers/iio/chemical/atlas-sensor.c              | 10 ++++------
 drivers/iio/common/ssp_sensors/ssp_dev.c         | 12 ++++--------
 drivers/iio/dac/vf610_dac.c                      |  8 +++-----
 drivers/iio/gyro/mpu3050-core.c                  |  8 +++-----
 drivers/iio/gyro/mpu3050-i2c.c                   |  2 +-
 drivers/iio/light/apds9300.c                     | 11 +++--------
 drivers/iio/light/bh1780.c                       | 10 ++++------
 drivers/iio/light/cm3232.c                       | 13 ++++---------
 drivers/iio/light/isl29018.c                     | 11 +++--------
 drivers/iio/light/isl29125.c                     |  8 +++-----
 drivers/iio/light/jsa1212.c                      | 12 +++---------
 drivers/iio/light/ltr501.c                       |  8 +++-----
 drivers/iio/light/stk3310.c                      | 12 +++---------
 drivers/iio/light/tcs3414.c                      |  8 +++-----
 drivers/iio/light/tcs3472.c                      |  8 +++-----
 drivers/iio/light/tsl2563.c                      | 11 +++--------
 drivers/iio/light/tsl4531.c                      | 11 +++--------
 drivers/iio/light/us5182d.c                      | 10 ++++------
 drivers/iio/magnetometer/ak8975.c                | 10 ++++------
 drivers/iio/magnetometer/hmc5843.h               |  5 -----
 drivers/iio/magnetometer/hmc5843_i2c.c           |  2 +-
 drivers/iio/magnetometer/hmc5843_spi.c           |  2 +-
 drivers/iio/magnetometer/mag3110.c               | 11 +++--------
 drivers/iio/magnetometer/mmc35240.c              | 12 ++++--------
 drivers/iio/pressure/bmp280-core.c               |  6 ++----
 drivers/iio/pressure/bmp280-i2c.c                |  2 +-
 drivers/iio/pressure/bmp280-spi.c                |  2 +-
 drivers/iio/pressure/mpl3115.c                   | 11 +++--------
 drivers/iio/proximity/as3935.c                   | 12 +++---------
 .../iio/proximity/pulsedlight-lidar-lite-v2.c    | 10 ++++------
 drivers/iio/proximity/rfd77402.c                 |  8 +++-----
 drivers/iio/proximity/sx9500.c                   | 12 ++++--------
 drivers/iio/temperature/tmp006.c                 |  8 +++-----
 drivers/iio/temperature/tmp007.c                 |  8 +++-----
 60 files changed, 180 insertions(+), 344 deletions(-)

--
2.34.0

#3 lore raw

Re: [PATCH 02/49] iio:accel:da280: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron

Hi,

Quoted 6 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

Quoted 8 lines

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.

No pm_ptr() for this one?

-Paul

Quoted 32 lines
---
 drivers/iio/accel/da280.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/iio/accel/da280.c +2 -5
index 9633bdae5fd4..91ac478891ce 100644
@@ -153,17 +153,15 @@ static int da280_probe(struct i2c_client 
 *client,
 	return devm_iio_device_register(&client->dev, indio_dev);
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int da280_suspend(struct device *dev)
+static __maybe_unused int da280_suspend(struct device *dev)
 {
 	return da280_enable(to_i2c_client(dev), false);
 }
 
-static int da280_resume(struct device *dev)
+static __maybe_unused int da280_resume(struct device *dev)
 {
 	return da280_enable(to_i2c_client(dev), true);
 }
-#endif
 
 static SIMPLE_DEV_PM_OPS(da280_pm_ops, da280_suspend, da280_resume);
 
--

2.34.0

Acked-by on v1 49/49
#69 lore raw

Re: [PATCH 49/49] iio:chemical:atlas: Switch from CONFIG_PM guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron
Quoted 10 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

Quoted 51 lines
---
 drivers/iio/chemical/atlas-sensor.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/iio/chemical/atlas-sensor.c +4 -7
index 04b44a327614..7bacd0bd6f19 100644
@@ -737,8 +737,7 @@ static int atlas_remove(struct i2c_client *client)
        return atlas_set_powermode(data, 0);
 }
 
-#ifdef CONFIG_PM
-static int atlas_runtime_suspend(struct device *dev)
+static __maybe_unused int atlas_runtime_suspend(struct device *dev)
 {
        struct atlas_data *data =
                     iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
@@ -746,16 +745,15 @@ static int atlas_runtime_suspend(struct device *dev)
        return atlas_set_powermode(data, 0);
 }
 
-static int atlas_runtime_resume(struct device *dev)
+static __maybe_unused int atlas_runtime_resume(struct device *dev)
 {
        struct atlas_data *data =
                     iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
 
        return atlas_set_powermode(data, 1);
 }
-#endif
 
-static const struct dev_pm_ops atlas_pm_ops = {
+static __maybe_unused const struct dev_pm_ops atlas_pm_ops = {
        SET_RUNTIME_PM_OPS(atlas_runtime_suspend,
                           atlas_runtime_resume, NULL)
 };
@@ -764,7 +762,7 @@ static struct i2c_driver atlas_driver = {
        .driver = {
                .name   = ATLAS_DRV_NAME,
                .of_match_table = atlas_dt_ids,
-               .pm     = &atlas_pm_ops,
+               .pm     = pm_ptr(&atlas_pm_ops),
        },
        .probe          = atlas_probe,
        .remove         = atlas_remove,
--

2.34.0

Acked-by on v1 43/49
#59 lore raw

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

In reply to Jonathan Cameron
Quoted 7 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

Quoted 5 lines

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

Quoted 50 lines
---
 drivers/iio/proximity/pulsedlight-lidar-lite-v2.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/iio/proximity/pulsedlight-lidar-lite-v2.c +4 -7
index 27026c060ab9..6adc2a0c27cb 100644
@@ -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

Acked-by on v1 42/49
#57 lore raw

Re: [PATCH 42/49] iio:proximity:as3935: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron
Quoted 10 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

Quoted 6 lines

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.

Quoted 51 lines
---
 drivers/iio/proximity/as3935.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/iio/proximity/as3935.c +3 -10
index d62766b6b39e..605c6095d704 100644
@@ -295,8 +295,7 @@ 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)
+static __maybe_unused int as3935_suspend(struct device *dev)
 {
        struct iio_dev *indio_dev = dev_get_drvdata(dev);
        struct as3935_state *st = iio_priv(indio_dev);
@@ -316,7 +315,7 @@ static int as3935_suspend(struct device *dev)
        return ret;
 }
 
-static int as3935_resume(struct device *dev)
+static __maybe_unused int as3935_resume(struct device *dev)
 {
        struct iio_dev *indio_dev = dev_get_drvdata(dev);
        struct as3935_state *st = iio_priv(indio_dev);
@@ -338,11 +337,6 @@ static int as3935_resume(struct device *dev)
 }
 
 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
 
 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_ptr(&as3935_pm_ops),
        },
        .probe          = as3935_probe,
        .id_table       = as3935_id,
--

2.34.0

Acked-by on v1 36/49
#47 lore raw

Re: [PATCH 36/49] iio:magn:ak8975: Switch from CONFIG_PM guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron
Quoted 7 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

Quoted 5 lines

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

Quoted 52 lines
Cc Jonathan Albrieux <[email protected]>
Cc Linus Walleij <[email protected]>
---
 drivers/iio/magnetometer/ak8975.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/iio/magnetometer/ak8975.c +4 -7
index 6e82dc54a417..ced3e674eb5f 100644
@@ -1033,8 +1033,7 @@ static int ak8975_remove(struct i2c_client *client)
        return 0;
 }
 
-#ifdef CONFIG_PM
-static int ak8975_runtime_suspend(struct device *dev)
+static __maybe_unused int ak8975_runtime_suspend(struct device *dev)
 {
        struct i2c_client *client = to_i2c_client(dev);
        struct iio_dev *indio_dev = i2c_get_clientdata(client);
@@ -1053,7 +1052,7 @@ static int ak8975_runtime_suspend(struct device *dev)
        return 0;
 }
 
-static int ak8975_runtime_resume(struct device *dev)
+static __maybe_unused int ak8975_runtime_resume(struct device *dev)
 {
        struct i2c_client *client = to_i2c_client(dev);
        struct iio_dev *indio_dev = i2c_get_clientdata(client);
@@ -1074,9 +1073,8 @@ static int ak8975_runtime_resume(struct device *dev)
 
        return 0;
 }
-#endif /* CONFIG_PM */
 
-static const struct dev_pm_ops ak8975_dev_pm_ops = {
+static __maybe_unused const struct dev_pm_ops ak8975_dev_pm_ops = {
        SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
                                pm_runtime_force_resume)
        SET_RUNTIME_PM_OPS(ak8975_runtime_suspend,
@@ -1113,7 +1111,7 @@ MODULE_DEVICE_TABLE(of, ak8975_of_match);
 static struct i2c_driver ak8975_driver = {
        .driver = {
                .name   = "ak8975",
-               .pm = &ak8975_dev_pm_ops,
+               .pm = pm_ptr(&ak8975_dev_pm_ops),
                .of_match_table = ak8975_of_match,
                .acpi_match_table = ak_acpi_match,
        },
--

2.34.0

Reviewed-by on the v1 series
#82 lore raw
In reply to Jonathan Cameron
Quoted 27 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Note this series includes many drivers that are quite old and I'm not sure have active maintainers. Hence if anyone has time to look at some of these beyond their own drivers and sanity check them it would be much appreciated!

Two motivations behind this set.
1 - General code reduction and improvement in readability in these drivers. 2 - Reduce change I'll have to ask people to change how they do this in
future patches.

Mostly this is just a case of letting the compiler work out it can remove the PM related functions rather than using #ifdefs in the code to do so.

The __maybe_unused markings make it clear we are intentionally building functions that the compiler can see are unused and remove in some build configurations.

The new pm_ptr() macro is rather convenient to got futher than many of the drivers were and when CONFIG_PM is not define ensure that the struct dev_pm_ops can also be removed. Note there is a subtlty in that we only remove that whe CONFIG_PM is not defined whereas a few of these drivers were using CONFIG_PM_SLEEP which is a tighter condition (will remove the structure in more configurations). I think that's a small price to pay for the convenience this macro brings.

Quoted 6 lines

I did this set as one patch per driver, as personally I prefer that option for all but the most trivial patches because it makes backports that cross with this series simpler and also avoid the complex tag giving we get for sets touching code from many authors.

All comments welcome.

Nice cleanup! Assuming that you add the missing pm_ptr() to patch 2 (iio:accel:da280) you can add this to the series:

#71 lore raw
In reply to Paul Cercueil
Quoted 11 lines · Paul Cercueil

One word about the pm_ptr() macro. Right now it's defined as:
#ifdef CONFIG_PM
#define pm_ptr(_ptr) (_ptr)
#else
#define pm_ptr(_ptr) NULL
#endif

It could be possible to define it like this instead:
#define pm_ptr(_ptr) PTR_IF(IS_ENABLED(CONFIG_PM), (_ptr))

Quoted 6 lines

The difference is that if !CONFIG_PM, in the first case the (_ptr) is not visible by the compiler and the __maybe_unused is required, while in the second case the (_ptr) is always visible by the compiler, but discarded as dead code. The reason we'd want that is the same reason we use IS_ENABLED() instead of macro guards; and you wouldn't need the __maybe_unused attribute anywhere.

That sounds like a great idea. I see there are only 12 users of pm_ptr at the moment, so auditing all of these should not be a problem.

I gave it a brief look and found that we probably only need to fix drivers/net/ethernet/realtek/r8169_main.c if we change the definition.

Quoted 7 lines

The problem then is that the SET_*_PM_OPS macros are defined differently according to CONFIG_PM, so their definition would need to be changed to use the (redefined) pm_ptr() macro and a corresponding pm_sleep_ptr() macro. Unfortunately since the SET_*_PM_OPS macros are used everywhere with code wrapped around #ifdef CONFIG_PM guards, it wouldn't be easy to change them, and it would just be easier to introduce new macros.

Right, this is what we've discussed multiple times, and I think everyone agreed we should do this, but so far we could not come up with a name for the new macro, and changing the macro in place is not practical unless we change hundreds of drivers in the same way as the iio series first.

Arnd

maintainer Reviewed-by on v1 13/49
#19 lore raw

Re: [PATCH 13/49] iio:adc:at91-adc: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron
Quoted 6 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

Quoted 8 lines

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.

Quoted 49 lines
Cc Alexandre Belloni <[email protected]>
Cc Ludovic Desroches <[email protected]>
---
 drivers/iio/adc/at91_adc.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/iio/adc/at91_adc.c +3 -5
index 5a7d3a3a5fa8..14a4735d72b5 100644
@@ -1234,8 +1234,7 @@ static int at91_adc_remove(struct platform_device *pdev)
 	return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int at91_adc_suspend(struct device *dev)
+static __maybe_unused int at91_adc_suspend(struct device *dev)
 {
 	struct iio_dev *idev = dev_get_drvdata(dev);
 	struct at91_adc_state *st = iio_priv(idev);
@@ -1246,7 +1245,7 @@ static int at91_adc_suspend(struct device *dev)
 	return 0;
 }
 
-static int at91_adc_resume(struct device *dev)
+static __maybe_unused int at91_adc_resume(struct device *dev)
 {
 	struct iio_dev *idev = dev_get_drvdata(dev);
 	struct at91_adc_state *st = iio_priv(idev);
@@ -1256,7 +1255,6 @@ static int at91_adc_resume(struct device *dev)
 
 	return 0;
 }
-#endif
 
 static SIMPLE_DEV_PM_OPS(at91_adc_pm_ops, at91_adc_suspend, at91_adc_resume);
 
@@ -1386,7 +1384,7 @@ static struct platform_driver at91_adc_driver = {
 	.driver = {
 		   .name = DRIVER_NAME,
 		   .of_match_table = at91_adc_dt_ids,
-		   .pm = &at91_adc_pm_ops,
+		   .pm = pm_ptr(&at91_adc_pm_ops),
 	},
 };
 
Signature · 1 line
2.34.0
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Reviewed-by on v1 16/49
#25 lore raw

Re: [PATCH 16/49] iio:adc:stm32:Switch from CONFIG_PM guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron
Quoted 9 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

Hi Jonathan,

You can add my:

Thanks for your patch,
Best Regards,
Fabrice

Quoted 112 lines
Cc Fabrice Gasnier <[email protected]>
Cc Olivier Moysan <[email protected]>
---
 drivers/iio/adc/stm32-adc-core.c | 12 +++++-------
 drivers/iio/adc/stm32-adc.c      | 16 ++++++----------
 2 files changed, 11 insertions(+), 17 deletions(-)
drivers/iio/adc/stm32-adc-core.c +5 -7
index b6e18eb101f7..316ae84ab961 100644
@@ -763,28 +763,26 @@ static int stm32_adc_remove(struct platform_device *pdev)
 	return 0;
 }
 
-#if defined(CONFIG_PM)
-static int stm32_adc_core_runtime_suspend(struct device *dev)
+static __maybe_unused int stm32_adc_core_runtime_suspend(struct device *dev)
 {
 	stm32_adc_core_hw_stop(dev);
 
 	return 0;
 }
 
-static int stm32_adc_core_runtime_resume(struct device *dev)
+static __maybe_unused int stm32_adc_core_runtime_resume(struct device *dev)
 {
 	return stm32_adc_core_hw_start(dev);
 }
 
-static int stm32_adc_core_runtime_idle(struct device *dev)
+static __maybe_unused int stm32_adc_core_runtime_idle(struct device *dev)
 {
 	pm_runtime_mark_last_busy(dev);
 
 	return 0;
 }
-#endif
 
-static const struct dev_pm_ops stm32_adc_core_pm_ops = {
+static __maybe_unused const struct dev_pm_ops stm32_adc_core_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
 				pm_runtime_force_resume)
 	SET_RUNTIME_PM_OPS(stm32_adc_core_runtime_suspend,
@@ -836,7 +834,7 @@ static struct platform_driver stm32_adc_driver = {
 	.driver = {
 		.name = "stm32-adc-core",
 		.of_match_table = stm32_adc_of_match,
-		.pm = &stm32_adc_core_pm_ops,
+		.pm = pm_ptr(&stm32_adc_core_pm_ops),
 	},
 };
 module_platform_driver(stm32_adc_driver);
drivers/iio/adc/stm32-adc.c +6 -10
index 7f1fb36c747c..2d94de6de848 100644
@@ -2351,8 +2351,7 @@ static int stm32_adc_remove(struct platform_device *pdev)
 	return 0;
 }
 
-#if defined(CONFIG_PM_SLEEP)
-static int stm32_adc_suspend(struct device *dev)
+static __maybe_unused int stm32_adc_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 
@@ -2362,7 +2361,7 @@ static int stm32_adc_suspend(struct device *dev)
 	return pm_runtime_force_suspend(dev);
 }
 
-static int stm32_adc_resume(struct device *dev)
+static __maybe_unused int stm32_adc_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	int ret;
@@ -2381,21 +2380,18 @@ static int stm32_adc_resume(struct device *dev)
 
 	return stm32_adc_buffer_postenable(indio_dev);
 }
-#endif
 
-#if defined(CONFIG_PM)
-static int stm32_adc_runtime_suspend(struct device *dev)
+static __maybe_unused int stm32_adc_runtime_suspend(struct device *dev)
 {
 	return stm32_adc_hw_stop(dev);
 }
 
-static int stm32_adc_runtime_resume(struct device *dev)
+static __maybe_unused int stm32_adc_runtime_resume(struct device *dev)
 {
 	return stm32_adc_hw_start(dev);
 }
-#endif
 
-static const struct dev_pm_ops stm32_adc_pm_ops = {
+static __maybe_unused const struct dev_pm_ops stm32_adc_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(stm32_adc_suspend, stm32_adc_resume)
 	SET_RUNTIME_PM_OPS(stm32_adc_runtime_suspend, stm32_adc_runtime_resume,
 			   NULL)
@@ -2452,7 +2448,7 @@ static struct platform_driver stm32_adc_driver = {
 	.driver = {
 		.name = "stm32-adc",
 		.of_match_table = stm32_adc_of_match,
-		.pm = &stm32_adc_pm_ops,
+		.pm = pm_ptr(&stm32_adc_pm_ops),
 	},
 };
 module_platform_driver(stm32_adc_driver);
#4 lore raw

Re: [PATCH 02/49] iio:accel:da280: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Paul Cercueil
Quoted 14 lines · On Tue, 23 Nov 2021 22:17:52 +0000 Paul Cercueil <[email protected]> wrote:

Hi,

Quoted 10 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

Quoted 8 lines
Quoted 5 lines

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.

No pm_ptr() for this one?

Gah. I changed my mind about this half way through doing this and decided to use it throughout rather than just in places that had defined the pm_ops out by hand.

Missed this one in the update! Anyhow, easy fix :)

Thanks,

Jonathan

Quoted 36 lines

-Paul

Quoted 32 lines
---
 drivers/iio/accel/da280.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/iio/accel/da280.c +2 -5
index 9633bdae5fd4..91ac478891ce 100644
@@ -153,17 +153,15 @@ static int da280_probe(struct i2c_client 
 *client,
 	return devm_iio_device_register(&client->dev, indio_dev);
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int da280_suspend(struct device *dev)
+static __maybe_unused int da280_suspend(struct device *dev)
 {
 	return da280_enable(to_i2c_client(dev), false);
 }
 
-static int da280_resume(struct device *dev)
+static __maybe_unused int da280_resume(struct device *dev)
 {
 	return da280_enable(to_i2c_client(dev), true);
 }
-#endif
 
 static SIMPLE_DEV_PM_OPS(da280_pm_ops, da280_suspend, da280_resume);
 
--

2.34.0

#72 lore raw
In reply to Arnd Bergmann
Quoted 19 lines · On Wed, 24 Nov 2021 08:29:40 +0100 Arnd Bergmann <[email protected]> wrote:
Quoted 11 lines · Paul Cercueil

One word about the pm_ptr() macro. Right now it's defined as:
#ifdef CONFIG_PM
#define pm_ptr(_ptr) (_ptr)
#else
#define pm_ptr(_ptr) NULL
#endif

It could be possible to define it like this instead:
#define pm_ptr(_ptr) PTR_IF(IS_ENABLED(CONFIG_PM), (_ptr))

Quoted 6 lines

The difference is that if !CONFIG_PM, in the first case the (_ptr) is not visible by the compiler and the __maybe_unused is required, while in the second case the (_ptr) is always visible by the compiler, but discarded as dead code. The reason we'd want that is the same reason we use IS_ENABLED() instead of macro guards; and you wouldn't need the __maybe_unused attribute anywhere.

Quoted 5 lines

That sounds like a great idea. I see there are only 12 users of pm_ptr at the moment, so auditing all of these should not be a problem.

I gave it a brief look and found that we probably only need to fix drivers/net/ethernet/realtek/r8169_main.c if we change the definition.

Cool.

Quoted 9 lines
Quoted 8 lines

The problem then is that the SET_*_PM_OPS macros are defined differently according to CONFIG_PM, so their definition would need to be changed to use the (redefined) pm_ptr() macro and a corresponding pm_sleep_ptr() macro. Unfortunately since the SET_*_PM_OPS macros are used everywhere with code wrapped around #ifdef CONFIG_PM guards, it wouldn't be easy to change them, and it would just be easier to introduce new macros.

Quoted 4 lines

Right, this is what we've discussed multiple times, and I think everyone agreed we should do this, but so far we could not come up with a name for the new macro, and changing the macro in place is not practical unless we change hundreds of drivers in the same way as the iio series first.

Nasty indeed and I'm not sure how scriptable either as lots of subtle variants unfortunately.

I'm cynical - don't need a good name. *_OPS2 works fine for me as long as the docs are good.

Jonathan

Quoted 2 lines

Arnd

#73 lore raw
Quoted 60 lines · Jonathan Cameron
Quoted 25 lines · On Wed, 24 Nov 2021 08:29:40 +0100 Arnd Bergmann <[email protected]> wrote:
Quoted 8 lines · Paul Cercueil

One word about the pm_ptr() macro. Right now it's defined as:
#ifdef CONFIG_PM
#define pm_ptr(_ptr) (_ptr)
#else
#define pm_ptr(_ptr) NULL
#endif

Quoted 4 lines

It could be possible to define it like this instead:
#define pm_ptr(_ptr) PTR_IF(IS_ENABLED(CONFIG_PM), (_ptr))

The difference is that if !CONFIG_PM, in the first case the

(_ptr) is

Quoted 1 line

not visible by the compiler and the __maybe_unused is required,

while

Quoted 1 line

in the second case the (_ptr) is always visible by the compiler,

but

Quoted 1 line

discarded as dead code. The reason we'd want that is the same

reason we

Quoted 1 line

use IS_ENABLED() instead of macro guards; and you wouldn't need

the

Quoted 1 line

__maybe_unused attribute anywhere.

Quoted 7 lines

That sounds like a great idea. I see there are only 12 users of
pm_ptr at
the moment, so auditing all of these should not be a problem.

I gave it a brief look and found that we probably only need to fix drivers/net/ethernet/realtek/r8169_main.c if we change the
definition.

Cool.

Quoted 13 lines
Quoted 3 lines

The problem then is that the SET_*_PM_OPS macros are defined differently according to CONFIG_PM, so their definition would

need to

Quoted 1 line

be changed to use the (redefined) pm_ptr() macro and a

corresponding

Quoted 1 line

pm_sleep_ptr() macro. Unfortunately since the SET_*_PM_OPS macros

are

Quoted 1 line

used everywhere with code wrapped around #ifdef CONFIG_PM guards,

it

Quoted 2 lines

wouldn't be easy to change them, and it would just be easier to introduce new macros.

Quoted 8 lines

Right, this is what we've discussed multiple times, and I think
everyone
agreed we should do this, but so far we could not come up with a
name
for the new macro, and changing the macro in place is not practical
unless
we change hundreds of drivers in the same way as the iio series
first.

Quoted 5 lines

Nasty indeed and I'm not sure how scriptable either as lots of subtle variants unfortunately.

I'm cynical - don't need a good name. *_OPS2 works fine for me as long as the docs are good.

We could just remove the SET_ prefix,
SET_SYSTEM_SLEEP_PM_OPS -> SYSTEM_SLEEP_PM_OPS,

Or would that be too confusing?

-Paul

#74 lore raw
In reply to Jonathan Cameron
Quoted 10 lines · Jonathan Cameron
Quoted 9 lines · On Wed, 24 Nov 2021 08:29:40 +0100 Arnd Bergmann <[email protected]> wrote:
Quoted 8 lines

The problem then is that the SET_*_PM_OPS macros are defined differently according to CONFIG_PM, so their definition would need to be changed to use the (redefined) pm_ptr() macro and a corresponding pm_sleep_ptr() macro. Unfortunately since the SET_*_PM_OPS macros are used everywhere with code wrapped around #ifdef CONFIG_PM guards, it wouldn't be easy to change them, and it would just be easier to introduce new macros.

Quoted 7 lines
Quoted 4 lines

Right, this is what we've discussed multiple times, and I think everyone agreed we should do this, but so far we could not come up with a name for the new macro, and changing the macro in place is not practical unless we change hundreds of drivers in the same way as the iio series first.

Nasty indeed and I'm not sure how scriptable either as lots of subtle variants unfortunately.

The minor variants (late, noirq) are actually the easy part, for the macros that have fewer users, we can just have one patch per macro that changes it treewide. For SET_SYSTEM_SLEEP_PM_OPS/SET_RUNTIME_PM_OPS and their
DEV_PM_OPS variants, this would be a lot harder:

$ for i in SET_SYSTEM_SLEEP_PM_OPS SET_LATE_SYSTEM_SLEEP_PM_OPS
SET_NOIRQ_SYSTEM_SLEEP_PM_OPS SET_RUNTIME_PM_OPS SIMPLE_DEV_PM_OPS
UNIVERSAL_DEV_PM_OPS ; do echo `git grep -wl $i | wc  -l` $i ; done

459 SET_SYSTEM_SLEEP_PM_OPS
51 SET_LATE_SYSTEM_SLEEP_PM_OPS
59 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS
497 SET_RUNTIME_PM_OPS
797 SIMPLE_DEV_PM_OPS
20 UNIVERSAL_DEV_PM_OPS

About half of those actually use an #ifdef, while the other half does not:

$ git grep -wl 'SET_SYSTEM_SLEEP_PM_OPS\|SET_RUNTIME_PM_OPS\|SIMPLE_DEV_PM_OPS\|UNIVERSAL_DEV_PM_OPS'
 | xargs grep -l CONFIG_PM | wc -l
712
$ git grep -wl 'SET_SYSTEM_SLEEP_PM_OPS\|SET_RUNTIME_PM_OPS\|SIMPLE_DEV_PM_OPS\|UNIVERSAL_DEV_PM_OPS'
 | xargs grep -L CONFIG_PM | wc -l
745

If we rename the macros in the first half of this using a script, then we should be able to change the behavior of the normal macros to use the new pm_ptr().

Arnd

#75 lore raw
Quoted 56 lines · Arnd Bergmann
Quoted 19 lines · Jonathan Cameron
Quoted 3 lines · On Wed, 24 Nov 2021 08:29:40 +0100 Arnd Bergmann <[email protected]> wrote:
Quoted 3 lines

The problem then is that the SET_*_PM_OPS macros are defined differently according to CONFIG_PM, so their definition would

need to

Quoted 1 line
Quoted 1 line

be changed to use the (redefined) pm_ptr() macro and a

corresponding

Quoted 1 line
Quoted 1 line

pm_sleep_ptr() macro. Unfortunately since the SET_*_PM_OPS

macros are

Quoted 1 line
Quoted 1 line

used everywhere with code wrapped around #ifdef CONFIG_PM

guards, it

Quoted 4 lines
Quoted 2 lines

wouldn't be easy to change them, and it would just be easier to introduce new macros.

Right, this is what we've discussed multiple times, and I think

everyone

Quoted 1 line

agreed we should do this, but so far we could not come up with a

name

Quoted 8 lines
Quoted 1 line

for the new macro, and changing the macro in place is not

practical unless

Quoted 1 line

we change hundreds of drivers in the same way as the iio series

first.

Nasty indeed and I'm not sure how scriptable either as lots of
subtle variants
unfortunately.

The minor variants (late, noirq) are actually the easy part, for the macros that have fewer users, we can just have one patch per macro that changes it treewide. For SET_SYSTEM_SLEEP_PM_OPS/SET_RUNTIME_PM_OPS and their
DEV_PM_OPS variants, this would be a lot harder:

$ for i in SET_SYSTEM_SLEEP_PM_OPS SET_LATE_SYSTEM_SLEEP_PM_OPS
SET_NOIRQ_SYSTEM_SLEEP_PM_OPS SET_RUNTIME_PM_OPS SIMPLE_DEV_PM_OPS
UNIVERSAL_DEV_PM_OPS ; do echo `git grep -wl $i | wc  -l` $i ; done

459 SET_SYSTEM_SLEEP_PM_OPS
51 SET_LATE_SYSTEM_SLEEP_PM_OPS
59 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS
497 SET_RUNTIME_PM_OPS
797 SIMPLE_DEV_PM_OPS
20 UNIVERSAL_DEV_PM_OPS

About half of those actually use an #ifdef, while the other half does not:

$ git grep -wl 'SET_SYSTEM_SLEEP_PM_OPS\|SET_RUNTIME_PM_OPS\|SIMPLE_DEV_PM_OPS\|UNIVERSAL_DEV_PM_OPS'
 | xargs grep -l CONFIG_PM | wc -l
712
$ git grep -wl 'SET_SYSTEM_SLEEP_PM_OPS\|SET_RUNTIME_PM_OPS\|SIMPLE_DEV_PM_OPS\|UNIVERSAL_DEV_PM_OPS'
 | xargs grep -L CONFIG_PM | wc -l
745
Quoted 2 lines

If we rename the macros in the first half of this using a script, then we should be able to change the behavior of the normal macros to use the new pm_ptr().

So you want to rename the current macros (to e.g. *_PM_OPS_LEGACY) everywhere so that new ones can be defined?

What about we introduce new macros, and just deprecate the old ones (with e.g. a checkpatch warning)? That would be way less work.

-Paul

Reviewed-by on v1 14/49
#21 lore raw

Re: [PATCH 14/49] iio:adc:exynos_adc: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron
Quoted 13 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

Quoted 6 lines
Cc Krzysztof Kozlowski <[email protected]>
---
 drivers/iio/adc/exynos_adc.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Looks good:

Best regards,
Krzysztof

Reviewed-by on v1 11/49
#15 lore raw

Re: [PATCH 11/49] iio:adc:ab8500: Switch from CONFIG_PM guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron
Quoted 11 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

Yours,
Linus Walleij

Reviewed-by on v1 24/49
#34 lore raw

Re: [PATCH 24/49] iio:light:bh1780: Switch from CONFIG_PM guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron
Quoted 11 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

Yours,
Linus Walleij

Reviewed-by on v1 41/49
#54 lore raw

Re: [PATCH 41/49] iio:pressure:bmp280: Switch from CONFIG_PM guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron
Quoted 11 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

Yours,
Linus Walleij

Reviewed-by on v1 48/49
#66 lore raw

Re: [PATCH 48/49] iio:gyro:mpu3050: Switch from CONFIG_PM guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron
Quoted 11 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

Yours,
Linus Walleij

author maintainer
#79 lore raw
In reply to Paul Cercueil
Quoted 67 lines · On Tue, 23 Nov 2021 22:11:08 +0000 Paul Cercueil <[email protected]> wrote:

Hi Jonathan,

Cc'd Arnd who may have some interest in the topic.

Quoted 37 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Note this series includes many drivers that are quite old and I'm not sure have active maintainers. Hence if anyone has time to look at some
of these beyond their own drivers and sanity check them it would be much
appreciated!

Two motivations behind this set.
1 - General code reduction and improvement in readability in these drivers.
2 - Reduce change I'll have to ask people to change how they do this in
future patches.

Mostly this is just a case of letting the compiler work out it can remove
the PM related functions rather than using #ifdefs in the code to do so.

The __maybe_unused markings make it clear we are intentionally building
functions that the compiler can see are unused and remove in some build
configurations.

The new pm_ptr() macro is rather convenient to got futher than many of the drivers were and when CONFIG_PM is not define ensure that the struct dev_pm_ops can also be removed. Note there is a subtlty in that
we only remove that whe CONFIG_PM is not defined whereas a few of these
drivers were using CONFIG_PM_SLEEP which is a tighter condition (will remove the structure in more configurations). I think that's a small price to pay for the convenience this macro brings.

Quoted 6 lines

I did this set as one patch per driver, as personally I prefer that option for all but the most trivial patches because it makes backports that cross with this series simpler and also avoid the complex tag giving we get for sets touching code from many authors.

All comments welcome.

One word about the pm_ptr() macro. Right now it's defined as:
#ifdef CONFIG_PM
#define pm_ptr(_ptr) (_ptr)
#else
#define pm_ptr(_ptr) NULL
#endif

It could be possible to define it like this instead:
#define pm_ptr(_ptr) PTR_IF(IS_ENABLED(CONFIG_PM), (_ptr))

The difference is that if !CONFIG_PM, in the first case the (_ptr) is not visible by the compiler and the __maybe_unused is required, while in the second case the (_ptr) is always visible by the compiler, but discarded as dead code. The reason we'd want that is the same reason we use IS_ENABLED() instead of macro guards; and you wouldn't need the __maybe_unused attribute anywhere.

Quoted 4 lines

The problem then is that the SET_*_PM_OPS macros are defined differently according to CONFIG_PM, so their definition would need to be changed to use the (redefined) pm_ptr() macro and a corresponding pm_sleep_ptr() macro.

Small question here. Why would these macros need to use pm_ptr() macro at all?

Why not just stop them being conditional on CONFIG_PM at all and let dead code removal kill them off for us? You might want to do something different for the CONFIG_PM_SLEEP ones though if we care about having it that fine grained.

Obviously still need new macros to do this, so doesn't change the fundamental question.

Quoted 210 lines

Unfortunately since the SET_*_PM_OPS macros are
used everywhere with code wrapped around #ifdef CONFIG_PM guards, it wouldn't be easy to change them, and it would just be easier to introduce new macros.

The patchset looks fine as-is and I am not asking you to work on anything I just said, I just thought it was worth mentioning.

Cheers,
-Paul

Quoted 197 lines
Cc Alexandre Belloni <[email protected]>
Cc Anson Huang <[email protected]>
Cc Brian Masney <[email protected]>
Cc Fabrice Gasnier <[email protected]>
Cc Hans de Goede <[email protected]>
Cc Heiko Stuebner <[email protected]>
Cc Icenowy Zheng <[email protected]>
Cc Jonathan Albrieux <[email protected]>
Cc Krzysztof Kozlowski <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Luca Weiss <[email protected]>
Cc Ludovic Desroches <[email protected]>
Cc Manivannan Sadhasivam <[email protected]>
Cc Martijn Braam <[email protected]>
Cc Maslov Dmitry <[email protected]>
Cc Matt Ranostay <[email protected]
Cc Olivier Moysan <[email protected]>
Cc Stefan-Gabriel Mirea <[email protected]>
Cc Vaishnav M A <[email protected]>

Jonathan Cameron (49):
iio:accel:da311: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:accel:da280: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:accel:dmard06: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:accel:dmard10: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:accel:mc3230: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:accel:mma7660: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:accel:mma9551: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:accel:mma9553: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:accel:stk8ba50: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:accel:kxsd9: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:adc:ab8500: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:adc:ad7606: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:adc:at91-adc: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:adc:exynos_adc: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:adc:palmas_gpadc: Switch from CONFIG_PM_SLEEP guards to
pm_ptr() /
__maybe_unused
iio:adc:stm32:Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:adc:rcar: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:adc:rockchip: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:adc:twl6030: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:adc:vf610: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:common:ssp: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:dac:vf610: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:apds9300: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:bh1780: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:light:cm3232: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:isl29018: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:isl29125: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:jsa1212: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:ltr501: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:stk3310: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:tcs3414: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:tcs3472: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:tsl2563: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:tsl4531: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:light:us5182: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:magn:ak8975: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:magn:hmc5843: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:magn:mag3110: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:magn:mmc35240: Switch from CONFIG_PM_SLEEP guards to pm_ptr() /
__maybe_unused
iio:pressure:mpl3115: Switch from CONFIG_PM_SLEEP guards to
pm_ptr() /
__maybe_unused
iio:pressure:bmp280: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:proximity:as3935: Switch from CONFIG_PM_SLEEP guards to
pm_ptr() /
__maybe_unused
iio:proximity:pulsedlight: Switch from CONFIG_PM guards to pm_ptr()
/
__maybe_unused
iio:proximity:rfd77492: Switch from CONFIG_PM_SLEEP guards to
pm_ptr()
/ __maybe_unused
iio:proximity:sx9500: Switch from CONFIG_PM_SLEEP guards to
pm_ptr() /
__maybe_unused
iio:temperature:tmp006: Switch from CONFIG_PM_SLEEP guards to
pm_ptr()
/ __maybe_unused
iio:temperature:tmp007: Switch from CONFIG_PM_SLEEP guards to
pm_ptr()
/ __maybe_unused
iio:gyro:mpu3050: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused
iio:chemical:atlas: Switch from CONFIG_PM guards to pm_ptr() /
__maybe_unused

 drivers/iio/accel/da280.c                        |  6 ++----
 drivers/iio/accel/da311.c                        |  8 +++-----
 drivers/iio/accel/dmard06.c                      | 12 ++++--------
 drivers/iio/accel/dmard10.c                      |  9 ++++-----
 drivers/iio/accel/kxsd9-i2c.c                    |  2 +-
 drivers/iio/accel/kxsd9-spi.c                    |  2 +-
 drivers/iio/accel/kxsd9.c                        |  8 +++-----
 drivers/iio/accel/mc3230.c                       |  8 +++-----
 drivers/iio/accel/mma7660.c                      | 12 +++---------
 drivers/iio/accel/mma9551.c                      | 16 
++++++----------
 drivers/iio/accel/mma9553.c                      | 16 
++++++----------
 drivers/iio/accel/stk8ba50.c                     | 12 +++---------
 drivers/iio/adc/ab8500-gpadc.c                   | 10 ++++------
 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 +-
 drivers/iio/adc/at91_adc.c                       |  8 +++-----
 drivers/iio/adc/exynos_adc.c                     |  8 +++-----
 drivers/iio/adc/palmas_gpadc.c                   | 14 ++++++--------
 drivers/iio/adc/rcar-gyroadc.c                   | 10 ++++------
 drivers/iio/adc/rockchip_saradc.c                |  8 +++-----
 drivers/iio/adc/stm32-adc-core.c                 | 12 +++++-------
 drivers/iio/adc/stm32-adc.c                      | 16 
++++++----------
 drivers/iio/adc/twl6030-gpadc.c                  |  8 +++-----
 drivers/iio/adc/vf610_adc.c                      |  8 +++-----
 drivers/iio/chemical/atlas-sensor.c              | 10 ++++------
 drivers/iio/common/ssp_sensors/ssp_dev.c         | 12 ++++--------
 drivers/iio/dac/vf610_dac.c                      |  8 +++-----
 drivers/iio/gyro/mpu3050-core.c                  |  8 +++-----
 drivers/iio/gyro/mpu3050-i2c.c                   |  2 +-
 drivers/iio/light/apds9300.c                     | 11 +++--------
 drivers/iio/light/bh1780.c                       | 10 ++++------
 drivers/iio/light/cm3232.c                       | 13 ++++---------
 drivers/iio/light/isl29018.c                     | 11 +++--------
 drivers/iio/light/isl29125.c                     |  8 +++-----
 drivers/iio/light/jsa1212.c                      | 12 +++---------
 drivers/iio/light/ltr501.c                       |  8 +++-----
 drivers/iio/light/stk3310.c                      | 12 +++---------
 drivers/iio/light/tcs3414.c                      |  8 +++-----
 drivers/iio/light/tcs3472.c                      |  8 +++-----
 drivers/iio/light/tsl2563.c                      | 11 +++--------
 drivers/iio/light/tsl4531.c                      | 11 +++--------
 drivers/iio/light/us5182d.c                      | 10 ++++------
 drivers/iio/magnetometer/ak8975.c                | 10 ++++------
 drivers/iio/magnetometer/hmc5843.h               |  5 -----
 drivers/iio/magnetometer/hmc5843_i2c.c           |  2 +-
 drivers/iio/magnetometer/hmc5843_spi.c           |  2 +-
 drivers/iio/magnetometer/mag3110.c               | 11 +++--------
 drivers/iio/magnetometer/mmc35240.c              | 12 ++++--------
 drivers/iio/pressure/bmp280-core.c               |  6 ++----
 drivers/iio/pressure/bmp280-i2c.c                |  2 +-
 drivers/iio/pressure/bmp280-spi.c                |  2 +-
 drivers/iio/pressure/mpl3115.c                   | 11 +++--------
 drivers/iio/proximity/as3935.c                   | 12 +++---------
 .../iio/proximity/pulsedlight-lidar-lite-v2.c    | 10 ++++------
 drivers/iio/proximity/rfd77402.c                 |  8 +++-----
 drivers/iio/proximity/sx9500.c                   | 12 ++++--------
 drivers/iio/temperature/tmp006.c                 |  8 +++-----
 drivers/iio/temperature/tmp007.c                 |  8 +++-----
 60 files changed, 180 insertions(+), 344 deletions(-)

--
2.34.0

author maintainer
#76 lore raw
In reply to Paul Cercueil
Quoted 67 lines · On Wed, 24 Nov 2021 15:10:06 +0000 Paul Cercueil <[email protected]> wrote:
Quoted 60 lines · Arnd Bergmann
Quoted 19 lines · Jonathan Cameron
Quoted 3 lines · On Wed, 24 Nov 2021 08:29:40 +0100 Arnd Bergmann <[email protected]> wrote:
Quoted 3 lines

The problem then is that the SET_*_PM_OPS macros are defined differently according to CONFIG_PM, so their definition would

need to

Quoted 1 line
Quoted 1 line

be changed to use the (redefined) pm_ptr() macro and a

corresponding

Quoted 1 line
Quoted 1 line

pm_sleep_ptr() macro. Unfortunately since the SET_*_PM_OPS

macros are

Quoted 1 line
Quoted 1 line

used everywhere with code wrapped around #ifdef CONFIG_PM

guards, it

Quoted 4 lines
Quoted 2 lines

wouldn't be easy to change them, and it would just be easier to introduce new macros.

Right, this is what we've discussed multiple times, and I think

everyone

Quoted 1 line

agreed we should do this, but so far we could not come up with a

name

Quoted 8 lines
Quoted 1 line

for the new macro, and changing the macro in place is not

practical unless

Quoted 1 line

we change hundreds of drivers in the same way as the iio series

first.

Nasty indeed and I'm not sure how scriptable either as lots of
subtle variants
unfortunately.

The minor variants (late, noirq) are actually the easy part, for the macros that
have fewer users, we can just have one patch per macro that changes it treewide.
For SET_SYSTEM_SLEEP_PM_OPS/SET_RUNTIME_PM_OPS and their DEV_PM_OPS variants, this would be a lot harder:

$ for i in SET_SYSTEM_SLEEP_PM_OPS SET_LATE_SYSTEM_SLEEP_PM_OPS
SET_NOIRQ_SYSTEM_SLEEP_PM_OPS SET_RUNTIME_PM_OPS SIMPLE_DEV_PM_OPS
UNIVERSAL_DEV_PM_OPS ; do echo `git grep -wl $i | wc  -l` $i ; done

459 SET_SYSTEM_SLEEP_PM_OPS
51 SET_LATE_SYSTEM_SLEEP_PM_OPS
59 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS
497 SET_RUNTIME_PM_OPS
797 SIMPLE_DEV_PM_OPS
20 UNIVERSAL_DEV_PM_OPS

About half of those actually use an #ifdef, while the other half does not:

$ git grep -wl 
'SET_SYSTEM_SLEEP_PM_OPS\|SET_RUNTIME_PM_OPS\|SIMPLE_DEV_PM_OPS\|UNIVERSAL_DEV_PM_OPS'
 | xargs grep -l CONFIG_PM | wc -l
712
$ git grep -wl 
'SET_SYSTEM_SLEEP_PM_OPS\|SET_RUNTIME_PM_OPS\|SIMPLE_DEV_PM_OPS\|UNIVERSAL_DEV_PM_OPS'
 | xargs grep -L CONFIG_PM | wc -l
745
Quoted 4 lines

If we rename the macros in the first half of this using a script, then we should
be able to change the behavior of the normal macros to use the new pm_ptr().

Quoted 5 lines

So you want to rename the current macros (to e.g. *_PM_OPS_LEGACY) everywhere so that new ones can be defined?

What about we introduce new macros, and just deprecate the old ones (with e.g. a checkpatch warning)? That would be way less work.

Sounds like a sensible approach to me. If Arnd is happy with that we can move forwards and get the bikshedding on the naming started.

As ever the true discussion won't start before there is a patch.

I'm happy to hold this series for a bit on the basis it'll be simpler without all those __maybe_unused additions, but I don't want to be sitting on it for multiple cycles if it turns out this will take a while to move forwards.

Thanks,

Jonathan

Quoted 4 lines

-Paul

#77 lore raw
Quoted 11 lines · Jonathan Cameron
Quoted 7 lines · On Wed, 24 Nov 2021 15:10:06 +0000 Paul Cercueil <[email protected]> wrote:

Le mer., nov. 24 2021 at 13:23:47 +0100, Arnd Bergmann <[email protected]>

So you want to rename the current macros (to e.g. *_PM_OPS_LEGACY) everywhere so that new ones can be defined?

What about we introduce new macros, and just deprecate the old ones (with e.g. a checkpatch warning)? That would be way less work.

Sounds like a sensible approach to me. If Arnd is happy with that we can move forwards and get the bikshedding on the naming started.

I suggested renaming the current macros as a way to avoid having to come up with new names. If you have an idea for a new name that makes sense in the long run, please just go ahead with that.

Arnd

#80 lore raw
In reply to Jonathan Cameron
Quoted 1 line · Jonathan Cameron

On Tue, 23 Nov 2021 22:11:08 +0000 Paul Cercueil <[email protected]> wrote:

?

Quoted 11 lines
Quoted 4 lines

The problem then is that the SET_*_PM_OPS macros are defined differently according to CONFIG_PM, so their definition would need to be changed to use the (redefined) pm_ptr() macro and a corresponding pm_sleep_ptr() macro.

Small question here. Why would these macros need to use pm_ptr() macro at all?

Why not just stop them being conditional on CONFIG_PM at all and let dead code removal kill them off for us? You might want to do something different for the CONFIG_PM_SLEEP ones though if we care about having it that fine grained.

Agreed, there is no need to use pm_ptr() inside of the new macros, it would just be convenient to define them this way.

The only requirement is to use a construct with the ?: operator that gets evaluated at compile time based on CONFIG_PM and CONFIG_PM_SLEEP so that DCE can do its magic.

Arnd

#81 lore raw

Hi,

Quoted 22 lines · Arnd Bergmann
Quoted 2 lines · Jonathan Cameron

On Tue, 23 Nov 2021 22:11:08 +0000 Paul Cercueil
<[email protected]> wrote:

?

Quoted 10 lines
Quoted 2 lines

The problem then is that the SET_*_PM_OPS macros are defined differently according to CONFIG_PM, so their definition would

need to

Quoted 1 line

be changed to use the (redefined) pm_ptr() macro and a

corresponding

Quoted 1 line

pm_sleep_ptr() macro.

Small question here. Why would these macros need to use pm_ptr()
macro at all?

Quoted 7 lines

Why not just stop them being conditional on CONFIG_PM at all and
let dead
code removal kill them off for us? You might want to do something
different
for the CONFIG_PM_SLEEP ones though if we care about having it that
fine
grained.

Quoted 2 lines

Agreed, there is no need to use pm_ptr() inside of the new macros, it would just be convenient to define them this way.

In that case all the callbacks of a dev_pm_ops will be compiled even though .suspend/.resume are only for CONFIG_PM_SLEEP.

The driver could do:
.dev.pm = pm_sleep_ptr(&my_pm_sleep_ops),

But that means the driver's dev needs to be aware that pm_sleep_ptr() is for simple PM, and pm_ptr() if runtime PM is used.

The alternative I suggested was to use pm_sleep_ptr() inside the SET_*_PM_OPS macros (and not pm_ptr() which wouldn't make much sense, I agree) so that the callbacks would be included only when CONFIG_PM_SLEEP is set; and the drivers would only ever use pm_ptr() for their .dev.pm.

I'm slightly in favor of the first solution, just because it would make the kernel smaller if !CONFIG_PM_SLEEP as you wouldn't have an empty dev_pm_ops struct.

Cheers,
-Paul

#78 lore raw
In reply to Arnd Bergmann

Hi Arnd, Jonathan,

Quoted 13 lines · Arnd Bergmann
Quoted 12 lines · Jonathan Cameron
Quoted 1 line · On Wed, 24 Nov 2021 15:10:06 +0000 Paul Cercueil <[email protected]> wrote:

Le mer., nov. 24 2021 at 13:23:47 +0100, Arnd Bergmann

<[email protected]>

Quoted 5 lines

So you want to rename the current macros (to e.g. *_PM_OPS_LEGACY) everywhere so that new ones can be defined?

What about we introduce new macros, and just deprecate the old

ones

Quoted 1 line

(with e.g. a checkpatch warning)? That would be way less work.

Quoted 6 lines
Quoted 2 lines

Sounds like a sensible approach to me. If Arnd is happy with that we can move forwards and get the bikshedding on the naming started.

I suggested renaming the current macros as a way to avoid having to come up with new names. If you have an idea for a new name that makes sense in the long run, please just go ahead with that.

Yes, I totally understand that. But renaming such a widespread macro sounds like a huge undertaking...

What about:

#define SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
.suspend = pm_sleep_ptr(suspend_fn), \
.resume = pm_sleep_ptr(resume_fn), \
...

#ifndef CONFIG_PM_SLEEP
#define SET_SYSTEM_SLEEP_PM_OPS(a, b) SYSTEM_SLEEP_PM_OPS(a, b) #else
#define SET_SYSTEM_SLEEP_PM_OPS(a, b)
#endif

#define DEFINE_SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
static const struct dev_pm_ops name = { \
SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn), \
}

SET_SYSTEM_SLEEP_PM_OPS -> SYSTEM_SLEEP_PM_OPS, with the old one now defined from the new one; SIMPLE_DEV_PM_OPS -> DEFINE_SIMPLE_DEV_PM_OPS.

Thoughts?

Cheers,
-Paul

#60 lore raw

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

In reply to Matt Ranostay
Quoted 8 lines · On Tue, 23 Nov 2021 14:22:46 -0800 Matt Ranostay <[email protected]>…
Quoted 7 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

Quoted 7 lines
Quoted 5 lines

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

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

Quoted 51 lines
Quoted 51 lines
---
 drivers/iio/proximity/pulsedlight-lidar-lite-v2.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/iio/proximity/pulsedlight-lidar-lite-v2.c +4 -7
index 27026c060ab9..6adc2a0c27cb 100644
@@ -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

author maintainer
#17 lore raw

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

In reply to Jonathan Cameron
Quoted 6 lines · On Tue, 23 Nov 2021 21:09:42 +0000 Jonathan Cameron <[email protected]> wrote:

From: Jonathan Cameron <[email protected]>

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.

Quoted 8 lines

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.

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

Quoted 82 lines
---
 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(-)
drivers/iio/adc/ad7606.c +2 -6
index 0a60ecc69d38..16a013aad20f 100644
@@ -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 <[email protected]>");
 MODULE_DESCRIPTION("Analog Devices AD7606 ADC");
 MODULE_LICENSE("GPL v2");
drivers/iio/adc/ad7606.h +0 -5
index 9350ef1f63b5..fd545836790e 100644
@@ -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_ */
drivers/iio/adc/ad7606_par.c +1 -1
index f732b3ac7878..60be3fb4ae39 100644
@@ -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,
 	},
 };
drivers/iio/adc/ad7606_spi.c +1 -1
index 29945ad07dca..8cc525b4b960 100644
@@ -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,
author maintainer
#23 lore raw

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

In reply to Jonathan Cameron
Quoted 60 lines · On Tue, 23 Nov 2021 21:09:45 +0000 Jonathan Cameron <[email protected]> wrote:

From: Jonathan Cameron <[email protected]>

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.

---
 drivers/iio/adc/palmas_gpadc.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/iio/adc/palmas_gpadc.c +4 -5
index f9c8385c72d3..98d7764e0662 100644
@@ -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);

drivers/iio/adc/palmas_gpadc.c static int palmas_gpadc_resume(struct device *dev) · line 828

Quoted 10 lines
drivers/iio/adc/palmas_gpadc.c +1 -2
@@ -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()

Quoted 9 lines
drivers/iio/adc/palmas_gpadc.c +1 -1
@@ -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,
 	},
 };
author maintainer
#49 lore raw

Re: [PATCH 37/49] iio:magn:hmc5843: Switch from CONFIG_PM_SLEEP guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron
Quoted 6 lines · On Tue, 23 Nov 2021 21:10:07 +0000 Jonathan Cameron <[email protected]> wrote:

From: Jonathan Cameron <[email protected]>

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.

Quoted 8 lines

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.

This one needs some more thought before any conversion to the new pm_sleep_ptr() etc as use of
DEFINE_SIMPLE_DEV_PM_OPS() leads to an unused warning for the _core.c module - which explains the original __maybe_unused under the ifdef.

I'll drop it for now.

Jonathan

Quoted 50 lines
---
 drivers/iio/magnetometer/hmc5843.h     | 5 -----
 drivers/iio/magnetometer/hmc5843_i2c.c | 2 +-
 drivers/iio/magnetometer/hmc5843_spi.c | 2 +-
 3 files changed, 2 insertions(+), 7 deletions(-)
drivers/iio/magnetometer/hmc5843.h +0 -5
index 9120c8bbf3dd..c3444f3ab1dc 100644
@@ -55,13 +55,8 @@ void hmc5843_common_remove(struct device *dev);
 int hmc5843_common_suspend(struct device *dev);
 int hmc5843_common_resume(struct device *dev);
 
-#ifdef CONFIG_PM_SLEEP
 static __maybe_unused SIMPLE_DEV_PM_OPS(hmc5843_pm_ops,
 					hmc5843_common_suspend,
 					hmc5843_common_resume);
-#define HMC5843_PM_OPS (&hmc5843_pm_ops)
-#else
-#define HMC5843_PM_OPS NULL
-#endif
 
 #endif /* HMC5843_CORE_H */
drivers/iio/magnetometer/hmc5843_i2c.c +1 -1
index bc6e12f1d521..a7359f439f10 100644
@@ -93,7 +93,7 @@ MODULE_DEVICE_TABLE(of, hmc5843_of_match);
 static struct i2c_driver hmc5843_driver = {
 	.driver = {
 		.name	= "hmc5843",
-		.pm	= HMC5843_PM_OPS,
+		.pm	= pm_ptr(&hmc5843_pm_ops),
 		.of_match_table = hmc5843_of_match,
 	},
 	.id_table	= hmc5843_id,
drivers/iio/magnetometer/hmc5843_spi.c +1 -1
index 89cf59a62c28..c1bd2ff3c64a 100644
@@ -90,7 +90,7 @@ MODULE_DEVICE_TABLE(spi, hmc5843_id);
 static struct spi_driver hmc5843_driver = {
 		.driver = {
 				.name = "hmc5843",
-				.pm = HMC5843_PM_OPS,
+				.pm = pm_ptr(&hmc5843_pm_ops),
 		},
 		.id_table = hmc5843_id,
 		.probe = hmc5843_spi_probe,
author maintainer
#55 lore raw

Re: [PATCH 41/49] iio:pressure:bmp280: Switch from CONFIG_PM guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron
Quoted 11 lines · On Tue, 23 Nov 2021 21:10:11 +0000 Jonathan Cameron <[email protected]> wrote:

From: Jonathan Cameron <[email protected]>

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.

Dropping this one for now because it has the same complexity around EXPORT_SYMBOL() and multiple modules so the compiler can't remove the functions automatically.

Will rethink if there is a way to handle these multi module cases at a later date.

Thanks,

Jonathan

Quoted 63 lines
---
 drivers/iio/pressure/bmp280-core.c | 6 ++----
 drivers/iio/pressure/bmp280-i2c.c  | 2 +-
 drivers/iio/pressure/bmp280-spi.c  | 2 +-
 3 files changed, 4 insertions(+), 6 deletions(-)
drivers/iio/pressure/bmp280-core.c +2 -4
index 6b7da40f99c8..0653e1ea88da 100644
@@ -1138,8 +1138,7 @@ int bmp280_common_probe(struct device *dev,
 }
 EXPORT_SYMBOL(bmp280_common_probe);
 
-#ifdef CONFIG_PM
-static int bmp280_runtime_suspend(struct device *dev)
+static __maybe_unused int bmp280_runtime_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct bmp280_data *data = iio_priv(indio_dev);
@@ -1147,7 +1146,7 @@ static int bmp280_runtime_suspend(struct device *dev)
 	return regulator_bulk_disable(BMP280_NUM_SUPPLIES, data->supplies);
 }
 
-static int bmp280_runtime_resume(struct device *dev)
+static __maybe_unused int bmp280_runtime_resume(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct bmp280_data *data = iio_priv(indio_dev);
@@ -1159,7 +1158,6 @@ static int bmp280_runtime_resume(struct device *dev)
 	usleep_range(data->start_up_time, data->start_up_time + 100);
 	return data->chip_info->chip_config(data);
 }
-#endif /* CONFIG_PM */
 
 const struct dev_pm_ops bmp280_dev_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
drivers/iio/pressure/bmp280-i2c.c +1 -1
index 8b03ea15c0d0..35045bd92846 100644
@@ -58,7 +58,7 @@ static struct i2c_driver bmp280_i2c_driver = {
 	.driver = {
 		.name	= "bmp280",
 		.of_match_table = bmp280_of_i2c_match,
-		.pm = &bmp280_dev_pm_ops,
+		.pm = pm_ptr(&bmp280_dev_pm_ops),
 	},
 	.probe		= bmp280_i2c_probe,
 	.id_table	= bmp280_i2c_id,
drivers/iio/pressure/bmp280-spi.c +1 -1
index 625b86878ad8..41f6cc56d229 100644
@@ -109,7 +109,7 @@ static struct spi_driver bmp280_spi_driver = {
 	.driver = {
 		.name = "bmp280",
 		.of_match_table = bmp280_of_spi_match,
-		.pm = &bmp280_dev_pm_ops,
+		.pm = pm_ptr(&bmp280_dev_pm_ops),
 	},
 	.id_table = bmp280_spi_id,
 	.probe = bmp280_spi_probe,
author maintainer
#67 lore raw

Re: [PATCH 48/49] iio:gyro:mpu3050: Switch from CONFIG_PM guards to pm_ptr() / __maybe_unused

In reply to Jonathan Cameron
Quoted 11 lines · On Tue, 23 Nov 2021 21:10:18 +0000 Jonathan Cameron <[email protected]> wrote:

From: Jonathan Cameron <[email protected]>

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.

Another one I'm going to drop for now because the multiple module nature of it means the compiler can't tell what it can remove.

Needs more thought.

Thanks,

Jonathan

Quoted 45 lines
---
 drivers/iio/gyro/mpu3050-core.c | 8 +++-----
 drivers/iio/gyro/mpu3050-i2c.c  | 2 +-
 2 files changed, 4 insertions(+), 6 deletions(-)
drivers/iio/gyro/mpu3050-core.c +3 -5
index ea387efab62d..4ec107b9e779 100644
@@ -1281,19 +1281,17 @@ int mpu3050_common_remove(struct device *dev)
 }
 EXPORT_SYMBOL(mpu3050_common_remove);
 
-#ifdef CONFIG_PM
-static int mpu3050_runtime_suspend(struct device *dev)
+static __maybe_unused int mpu3050_runtime_suspend(struct device *dev)
 {
 	return mpu3050_power_down(iio_priv(dev_get_drvdata(dev)));
 }
 
-static int mpu3050_runtime_resume(struct device *dev)
+static __maybe_unused int mpu3050_runtime_resume(struct device *dev)
 {
 	return mpu3050_power_up(iio_priv(dev_get_drvdata(dev)));
 }
-#endif /* CONFIG_PM */
 
-const struct dev_pm_ops mpu3050_dev_pm_ops = {
+const __maybe_unused struct dev_pm_ops mpu3050_dev_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
 				pm_runtime_force_resume)
 	SET_RUNTIME_PM_OPS(mpu3050_runtime_suspend,
drivers/iio/gyro/mpu3050-i2c.c +1 -1
index ef5bcbc4b45b..820133cad601 100644
@@ -114,7 +114,7 @@ static struct i2c_driver mpu3050_i2c_driver = {
 	.driver = {
 		.of_match_table = mpu3050_i2c_of_match,
 		.name = "mpu3050-i2c",
-		.pm = &mpu3050_dev_pm_ops,
+		.pm = pm_ptr(&mpu3050_dev_pm_ops),
 	},
 };
 module_i2c_driver(mpu3050_i2c_driver);