Skip to contentSkip to conversation

IIO: Where dev_pm_ops rework and namespaces meet (4-8)

PATCH RESEND In review Jonathan Cameron 2 participants 11 messages Jun 4, 2022 – Jun 11, 2022

Subsystems (3)
lore
Share & tools
lore

Jonathan Cameron

author maintainer
#0 lore raw

cover IIO: Where dev_pm_ops rework and namespaces meet (4-8)

From: Jonathan Cameron <[email protected]>

Resend as the first part of this series went via Rafael's tree and is now available in mainline.

Hence time to return to the remainder which didn't really get much review the first time around as focus was on the more interesting new macros in the first few patches.

Now we have NS specific EXPORT_NS[_GPL]_SIMPLE_DEV_PM_OPS() etc we can move these drivers over to their own namespaces reducing polution of the global namespace with exports that are only of interest within multi module drivers.

All comments welcome,

Thanks,

Jonathan

Jonathan Cameron (5):
iio:accel:kxsd9: Switch from CONFIG_PM guards to pm_ptr() etc
iio: humidity: hts221: Use EXPORT_SIMPLE_DEV_PM_OPS() to allow
compiler to remove dead code.
iio: humidity: hts221: Move symbol exports into IIO_HTS221 namespace
iio: imu: lsm6dsx: Use new pm_sleep_ptr() and
EXPORT_SIMPLE_DEV_PM_OPS()
iio: imu: lsm6dsx: Move exported symbols to the IIO_LSM6DSX namespace

 drivers/iio/accel/kxsd9-i2c.c                |  2 +-
 drivers/iio/accel/kxsd9-spi.c                |  2 +-
 drivers/iio/accel/kxsd9.c                    | 11 ++---------
 drivers/iio/humidity/hts221_core.c           | 12 +++++-------
 drivers/iio/humidity/hts221_i2c.c            |  3 ++-
 drivers/iio/humidity/hts221_spi.c            |  3 ++-
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 12 +++++-------
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c  |  3 ++-
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c  |  3 ++-
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c  |  3 ++-
 10 files changed, 24 insertions(+), 30 deletions(-)
Signature · 1 line
2.36.1
author maintainer
#1 lore raw

PATCH RESEND 1/5 iio:accel:kxsd9: Switch from CONFIG_PM guards to pm_ptr() etc

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     | 11 ++---------
 3 files changed, 4 insertions(+), 11 deletions(-)
drivers/iio/accel/kxsd9-i2c.c +1 -1
index c8dc52f11037..d57f264bd6c8 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 b7b5af45429e..07f14a9f22c7 100644
@@ -52,7 +52,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 +2 -9
index 3975860331a6..ba99649fe195 100644
@@ -492,7 +492,6 @@ void kxsd9_common_remove(struct device *dev)
 }
 EXPORT_SYMBOL_NS(kxsd9_common_remove, IIO_KXSD9);
 
-#ifdef CONFIG_PM
 static int kxsd9_runtime_suspend(struct device *dev)
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
@@ -508,15 +507,9 @@ static int kxsd9_runtime_resume(struct device *dev)
 
 	return kxsd9_power_up(st);
 }
-#endif /* CONFIG_PM */
 
-const 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,
-			   kxsd9_runtime_resume, NULL)
-};
-EXPORT_SYMBOL_NS(kxsd9_dev_pm_ops, IIO_KXSD9);
+EXPORT_NS_RUNTIME_DEV_PM_OPS(kxsd9_dev_pm_ops, kxsd9_runtime_suspend,
+			     kxsd9_runtime_resume, NULL, IIO_KXSD9);
 
 MODULE_AUTHOR("Jonathan Cameron <[email protected]>");
 MODULE_DESCRIPTION("Kionix KXSD9 driver");
Signature · 1 line
2.36.1
author maintainer
#2 lore raw

PATCH RESEND 2/5 iio: humidity: hts221: Use EXPORT_SIMPLE_DEV_PM_OPS() to allow compiler to remove dead code.

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

If CONFIG_PM_SLEEP is not defined using EXPORT_SIMPLE_DEV_PM_OPS() in conjunction with pm_sleep_ptr() allows the compiler to remove the unused code and data. This removes the need for __maybe_unused markings etc.

---
 drivers/iio/humidity/hts221_core.c | 9 +++------
 drivers/iio/humidity/hts221_i2c.c  | 2 +-
 drivers/iio/humidity/hts221_spi.c  | 2 +-
 3 files changed, 5 insertions(+), 8 deletions(-)
drivers/iio/humidity/hts221_core.c +3 -6
index 6a39615b6961..da9c08432ef2 100644
@@ -670,7 +670,7 @@ int hts221_probe(struct device *dev, int irq, const char *name,
 }
 EXPORT_SYMBOL(hts221_probe);
 
-static int __maybe_unused hts221_suspend(struct device *dev)
+static int hts221_suspend(struct device *dev)
 {
 	struct iio_dev *iio_dev = dev_get_drvdata(dev);
 	struct hts221_hw *hw = iio_priv(iio_dev);
@@ -680,7 +680,7 @@ static int __maybe_unused hts221_suspend(struct device *dev)
 				  FIELD_PREP(HTS221_ENABLE_MASK, false));
 }
 
-static int __maybe_unused hts221_resume(struct device *dev)
+static int hts221_resume(struct device *dev)
 {
 	struct iio_dev *iio_dev = dev_get_drvdata(dev);
 	struct hts221_hw *hw = iio_priv(iio_dev);
@@ -694,10 +694,7 @@ static int __maybe_unused hts221_resume(struct device *dev)
 	return err;
 }
 
-const struct dev_pm_ops hts221_pm_ops = {
-	SET_SYSTEM_SLEEP_PM_OPS(hts221_suspend, hts221_resume)
-};
-EXPORT_SYMBOL(hts221_pm_ops);
+EXPORT_SIMPLE_DEV_PM_OPS(hts221_pm_ops, hts221_suspend, hts221_resume);
 
 MODULE_AUTHOR("Lorenzo Bianconi <[email protected]>");
 MODULE_DESCRIPTION("STMicroelectronics hts221 sensor driver");
drivers/iio/humidity/hts221_i2c.c +1 -1
index cab39c4756f8..933b05e4d972 100644
@@ -62,7 +62,7 @@ MODULE_DEVICE_TABLE(i2c, hts221_i2c_id_table);
 static struct i2c_driver hts221_driver = {
 	.driver = {
 		.name = "hts221_i2c",
-		.pm = &hts221_pm_ops,
+		.pm = pm_sleep_ptr(&hts221_pm_ops),
 		.of_match_table = hts221_i2c_of_match,
 		.acpi_match_table = ACPI_PTR(hts221_acpi_match),
 	},
drivers/iio/humidity/hts221_spi.c +1 -1
index 729e86e433b1..888c5eab944c 100644
@@ -55,7 +55,7 @@ MODULE_DEVICE_TABLE(spi, hts221_spi_id_table);
 static struct spi_driver hts221_driver = {
 	.driver = {
 		.name = "hts221_spi",
-		.pm = &hts221_pm_ops,
+		.pm = pm_sleep_ptr(&hts221_pm_ops),
 		.of_match_table = hts221_spi_of_match,
 	},
 	.probe = hts221_spi_probe,
Signature · 1 line
2.36.1
maintainer Acked-by on v1 2/5
#3 lore raw

Re: [RESEND PATCH 2/5] iio: humidity: hts221: Use EXPORT_SIMPLE_DEV_PM_OPS() to allow compiler to remove dead code.

Quoted 10 lines

From: Jonathan Cameron <[email protected]>

If CONFIG_PM_SLEEP is not defined using EXPORT_SIMPLE_DEV_PM_OPS() in conjunction with pm_sleep_ptr() allows the compiler to remove the unused code and data. This removes the need for __maybe_unused markings etc.

Quoted 69 lines
---
 drivers/iio/humidity/hts221_core.c | 9 +++------
 drivers/iio/humidity/hts221_i2c.c  | 2 +-
 drivers/iio/humidity/hts221_spi.c  | 2 +-
 3 files changed, 5 insertions(+), 8 deletions(-)
drivers/iio/humidity/hts221_core.c +3 -6
index 6a39615b6961..da9c08432ef2 100644
@@ -670,7 +670,7 @@ int hts221_probe(struct device *dev, int irq, const char *name,
 }
 EXPORT_SYMBOL(hts221_probe);
 
-static int __maybe_unused hts221_suspend(struct device *dev)
+static int hts221_suspend(struct device *dev)
 {
 	struct iio_dev *iio_dev = dev_get_drvdata(dev);
 	struct hts221_hw *hw = iio_priv(iio_dev);
@@ -680,7 +680,7 @@ static int __maybe_unused hts221_suspend(struct device *dev)
 				  FIELD_PREP(HTS221_ENABLE_MASK, false));
 }
 
-static int __maybe_unused hts221_resume(struct device *dev)
+static int hts221_resume(struct device *dev)
 {
 	struct iio_dev *iio_dev = dev_get_drvdata(dev);
 	struct hts221_hw *hw = iio_priv(iio_dev);
@@ -694,10 +694,7 @@ static int __maybe_unused hts221_resume(struct device *dev)
 	return err;
 }
 
-const struct dev_pm_ops hts221_pm_ops = {
-	SET_SYSTEM_SLEEP_PM_OPS(hts221_suspend, hts221_resume)
-};
-EXPORT_SYMBOL(hts221_pm_ops);
+EXPORT_SIMPLE_DEV_PM_OPS(hts221_pm_ops, hts221_suspend, hts221_resume);
 
 MODULE_AUTHOR("Lorenzo Bianconi <[email protected]>");
 MODULE_DESCRIPTION("STMicroelectronics hts221 sensor driver");
drivers/iio/humidity/hts221_i2c.c +1 -1
index cab39c4756f8..933b05e4d972 100644
@@ -62,7 +62,7 @@ MODULE_DEVICE_TABLE(i2c, hts221_i2c_id_table);
 static struct i2c_driver hts221_driver = {
 	.driver = {
 		.name = "hts221_i2c",
-		.pm = &hts221_pm_ops,
+		.pm = pm_sleep_ptr(&hts221_pm_ops),
 		.of_match_table = hts221_i2c_of_match,
 		.acpi_match_table = ACPI_PTR(hts221_acpi_match),
 	},
drivers/iio/humidity/hts221_spi.c +1 -1
index 729e86e433b1..888c5eab944c 100644
@@ -55,7 +55,7 @@ MODULE_DEVICE_TABLE(spi, hts221_spi_id_table);
 static struct spi_driver hts221_driver = {
 	.driver = {
 		.name = "hts221_spi",
-		.pm = &hts221_pm_ops,
+		.pm = pm_sleep_ptr(&hts221_pm_ops),
 		.of_match_table = hts221_spi_of_match,
 	},
 	.probe = hts221_spi_probe,
Signature · 1 line
2.36.1
author maintainer
#4 lore raw

PATCH RESEND 3/5 iio: humidity: hts221: Move symbol exports into IIO_HTS221 namespace

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Avoid unnecessary pollution of the global symbol namespace by moving library functions in to a specific namespace and import that into the drivers that make use of the functions.

For more info: https://lwn.net/Articles/760045/

---
 drivers/iio/humidity/hts221_core.c | 5 +++--
 drivers/iio/humidity/hts221_i2c.c  | 1 +
 drivers/iio/humidity/hts221_spi.c  | 1 +
 3 files changed, 5 insertions(+), 2 deletions(-)
drivers/iio/humidity/hts221_core.c +3 -2
index da9c08432ef2..517158307d8c 100644
@@ -668,7 +668,7 @@ int hts221_probe(struct device *dev, int irq, const char *name,
 
 	return devm_iio_device_register(hw->dev, iio_dev);
 }
-EXPORT_SYMBOL(hts221_probe);
+EXPORT_SYMBOL_NS(hts221_probe, IIO_HTS221);
 
 static int hts221_suspend(struct device *dev)
 {
@@ -694,7 +694,8 @@ static int hts221_resume(struct device *dev)
 	return err;
 }
 
-EXPORT_SIMPLE_DEV_PM_OPS(hts221_pm_ops, hts221_suspend, hts221_resume);
+EXPORT_NS_SIMPLE_DEV_PM_OPS(hts221_pm_ops, hts221_suspend, hts221_resume,
+			    IIO_HTS221);
 
 MODULE_AUTHOR("Lorenzo Bianconi <[email protected]>");
 MODULE_DESCRIPTION("STMicroelectronics hts221 sensor driver");
drivers/iio/humidity/hts221_i2c.c +1 -0
index 933b05e4d972..afbc611f7712 100644
@@ -74,3 +74,4 @@ module_i2c_driver(hts221_driver);
 MODULE_AUTHOR("Lorenzo Bianconi <[email protected]>");
 MODULE_DESCRIPTION("STMicroelectronics hts221 i2c driver");
 MODULE_LICENSE("GPL v2");
+MODULE_IMPORT_NS(IIO_HTS221);
drivers/iio/humidity/hts221_spi.c +1 -0
index 888c5eab944c..fc4adb68faf6 100644
@@ -66,3 +66,4 @@ module_spi_driver(hts221_driver);
 MODULE_AUTHOR("Lorenzo Bianconi <[email protected]>");
 MODULE_DESCRIPTION("STMicroelectronics hts221 spi driver");
 MODULE_LICENSE("GPL v2");
+MODULE_IMPORT_NS(IIO_HTS221);
Signature · 1 line
2.36.1
maintainer Acked-by on v1 3/5
#5 lore raw

Re: [RESEND PATCH 3/5] iio: humidity: hts221: Move symbol exports into IIO_HTS221 namespace

Quoted 7 lines

From: Jonathan Cameron <[email protected]>

Avoid unnecessary pollution of the global symbol namespace by moving library functions in to a specific namespace and import that into the drivers that make use of the functions.

For more info: https://lwn.net/Articles/760045/

Quoted 54 lines
---
 drivers/iio/humidity/hts221_core.c | 5 +++--
 drivers/iio/humidity/hts221_i2c.c  | 1 +
 drivers/iio/humidity/hts221_spi.c  | 1 +
 3 files changed, 5 insertions(+), 2 deletions(-)
drivers/iio/humidity/hts221_core.c +3 -2
index da9c08432ef2..517158307d8c 100644
@@ -668,7 +668,7 @@ int hts221_probe(struct device *dev, int irq, const char *name,
 
 	return devm_iio_device_register(hw->dev, iio_dev);
 }
-EXPORT_SYMBOL(hts221_probe);
+EXPORT_SYMBOL_NS(hts221_probe, IIO_HTS221);
 
 static int hts221_suspend(struct device *dev)
 {
@@ -694,7 +694,8 @@ static int hts221_resume(struct device *dev)
 	return err;
 }
 
-EXPORT_SIMPLE_DEV_PM_OPS(hts221_pm_ops, hts221_suspend, hts221_resume);
+EXPORT_NS_SIMPLE_DEV_PM_OPS(hts221_pm_ops, hts221_suspend, hts221_resume,
+			    IIO_HTS221);
 
 MODULE_AUTHOR("Lorenzo Bianconi <[email protected]>");
 MODULE_DESCRIPTION("STMicroelectronics hts221 sensor driver");
drivers/iio/humidity/hts221_i2c.c +1 -0
index 933b05e4d972..afbc611f7712 100644
@@ -74,3 +74,4 @@ module_i2c_driver(hts221_driver);
 MODULE_AUTHOR("Lorenzo Bianconi <[email protected]>");
 MODULE_DESCRIPTION("STMicroelectronics hts221 i2c driver");
 MODULE_LICENSE("GPL v2");
+MODULE_IMPORT_NS(IIO_HTS221);
drivers/iio/humidity/hts221_spi.c +1 -0
index 888c5eab944c..fc4adb68faf6 100644
@@ -66,3 +66,4 @@ module_spi_driver(hts221_driver);
 MODULE_AUTHOR("Lorenzo Bianconi <[email protected]>");
 MODULE_DESCRIPTION("STMicroelectronics hts221 spi driver");
 MODULE_LICENSE("GPL v2");
+MODULE_IMPORT_NS(IIO_HTS221);
Signature · 1 line
2.36.1
author maintainer
#6 lore raw

PATCH RESEND 4/5 iio: imu: lsm6dsx: Use new pm_sleep_ptr() and EXPORT_SIMPLE_DEV_PM_OPS()

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

These new functions move the burden of removing unused code when CONFIG_PM_SLEEP is not defined onto the compiler rather than requiring the use of CONFIG_PM guards and similar.

---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 10 ++++------
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c  |  2 +-
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c  |  2 +-
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c  |  2 +-
 4 files changed, 7 insertions(+), 9 deletions(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +4 -6
index 910397716833..9e4aa5c1c8d6 100644
@@ -2291,7 +2291,7 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
 }
 EXPORT_SYMBOL(st_lsm6dsx_probe);
 
-static int __maybe_unused st_lsm6dsx_suspend(struct device *dev)
+static int st_lsm6dsx_suspend(struct device *dev)
 {
 	struct st_lsm6dsx_hw *hw = dev_get_drvdata(dev);
 	struct st_lsm6dsx_sensor *sensor;
@@ -2330,7 +2330,7 @@ static int __maybe_unused st_lsm6dsx_suspend(struct device *dev)
 	return err;
 }
 
-static int __maybe_unused st_lsm6dsx_resume(struct device *dev)
+static int st_lsm6dsx_resume(struct device *dev)
 {
 	struct st_lsm6dsx_hw *hw = dev_get_drvdata(dev);
 	struct st_lsm6dsx_sensor *sensor;
@@ -2366,10 +2366,8 @@ static int __maybe_unused st_lsm6dsx_resume(struct device *dev)
 	return err;
 }
 
-const struct dev_pm_ops st_lsm6dsx_pm_ops = {
-	SET_SYSTEM_SLEEP_PM_OPS(st_lsm6dsx_suspend, st_lsm6dsx_resume)
-};
-EXPORT_SYMBOL(st_lsm6dsx_pm_ops);
+EXPORT_SIMPLE_DEV_PM_OPS(st_lsm6dsx_pm_ops, st_lsm6dsx_suspend,
+			 st_lsm6dsx_resume);
 
 MODULE_AUTHOR("Lorenzo Bianconi <[email protected]>");
 MODULE_AUTHOR("Denis Ciocca <[email protected]>");
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c +1 -1
index 715fbdc8190e..5bd565b93a8c 100644
@@ -134,7 +134,7 @@ MODULE_DEVICE_TABLE(i2c, st_lsm6dsx_i2c_id_table);
 static struct i2c_driver st_lsm6dsx_driver = {
 	.driver = {
 		.name = "st_lsm6dsx_i2c",
-		.pm = &st_lsm6dsx_pm_ops,
+		.pm = pm_sleep_ptr(&st_lsm6dsx_pm_ops),
 		.of_match_table = st_lsm6dsx_i2c_of_match,
 	},
 	.probe = st_lsm6dsx_i2c_probe,
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c +1 -1
index 35556cd04284..4df186499802 100644
@@ -44,7 +44,7 @@ static int st_lsm6dsx_i3c_probe(struct i3c_device *i3cdev)
 static struct i3c_driver st_lsm6dsx_driver = {
 	.driver = {
 		.name = "st_lsm6dsx_i3c",
-		.pm = &st_lsm6dsx_pm_ops,
+		.pm = pm_sleep_ptr(&st_lsm6dsx_pm_ops),
 	},
 	.probe = st_lsm6dsx_i3c_probe,
 	.id_table = st_lsm6dsx_i3c_ids,
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c +1 -1
index f5767cf76c1d..3a206fd4d92c 100644
@@ -134,7 +134,7 @@ MODULE_DEVICE_TABLE(spi, st_lsm6dsx_spi_id_table);
 static struct spi_driver st_lsm6dsx_driver = {
 	.driver = {
 		.name = "st_lsm6dsx_spi",
-		.pm = &st_lsm6dsx_pm_ops,
+		.pm = pm_sleep_ptr(&st_lsm6dsx_pm_ops),
 		.of_match_table = st_lsm6dsx_spi_of_match,
 	},
 	.probe = st_lsm6dsx_spi_probe,
Signature · 1 line
2.36.1
maintainer Acked-by on v1 4/5
#7 lore raw

Re: [RESEND PATCH 4/5] iio: imu: lsm6dsx: Use new pm_sleep_ptr() and EXPORT_SIMPLE_DEV_PM_OPS()

Quoted 5 lines

From: Jonathan Cameron <[email protected]>

These new functions move the burden of removing unused code when CONFIG_PM_SLEEP is not defined onto the compiler rather than requiring the use of CONFIG_PM guards and similar.

Quoted 87 lines
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 10 ++++------
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c  |  2 +-
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c  |  2 +-
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c  |  2 +-
 4 files changed, 7 insertions(+), 9 deletions(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +4 -6
index 910397716833..9e4aa5c1c8d6 100644
@@ -2291,7 +2291,7 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
 }
 EXPORT_SYMBOL(st_lsm6dsx_probe);
 
-static int __maybe_unused st_lsm6dsx_suspend(struct device *dev)
+static int st_lsm6dsx_suspend(struct device *dev)
 {
 	struct st_lsm6dsx_hw *hw = dev_get_drvdata(dev);
 	struct st_lsm6dsx_sensor *sensor;
@@ -2330,7 +2330,7 @@ static int __maybe_unused st_lsm6dsx_suspend(struct device *dev)
 	return err;
 }
 
-static int __maybe_unused st_lsm6dsx_resume(struct device *dev)
+static int st_lsm6dsx_resume(struct device *dev)
 {
 	struct st_lsm6dsx_hw *hw = dev_get_drvdata(dev);
 	struct st_lsm6dsx_sensor *sensor;
@@ -2366,10 +2366,8 @@ static int __maybe_unused st_lsm6dsx_resume(struct device *dev)
 	return err;
 }
 
-const struct dev_pm_ops st_lsm6dsx_pm_ops = {
-	SET_SYSTEM_SLEEP_PM_OPS(st_lsm6dsx_suspend, st_lsm6dsx_resume)
-};
-EXPORT_SYMBOL(st_lsm6dsx_pm_ops);
+EXPORT_SIMPLE_DEV_PM_OPS(st_lsm6dsx_pm_ops, st_lsm6dsx_suspend,
+			 st_lsm6dsx_resume);
 
 MODULE_AUTHOR("Lorenzo Bianconi <[email protected]>");
 MODULE_AUTHOR("Denis Ciocca <[email protected]>");
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c +1 -1
index 715fbdc8190e..5bd565b93a8c 100644
@@ -134,7 +134,7 @@ MODULE_DEVICE_TABLE(i2c, st_lsm6dsx_i2c_id_table);
 static struct i2c_driver st_lsm6dsx_driver = {
 	.driver = {
 		.name = "st_lsm6dsx_i2c",
-		.pm = &st_lsm6dsx_pm_ops,
+		.pm = pm_sleep_ptr(&st_lsm6dsx_pm_ops),
 		.of_match_table = st_lsm6dsx_i2c_of_match,
 	},
 	.probe = st_lsm6dsx_i2c_probe,
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c +1 -1
index 35556cd04284..4df186499802 100644
@@ -44,7 +44,7 @@ static int st_lsm6dsx_i3c_probe(struct i3c_device *i3cdev)
 static struct i3c_driver st_lsm6dsx_driver = {
 	.driver = {
 		.name = "st_lsm6dsx_i3c",
-		.pm = &st_lsm6dsx_pm_ops,
+		.pm = pm_sleep_ptr(&st_lsm6dsx_pm_ops),
 	},
 	.probe = st_lsm6dsx_i3c_probe,
 	.id_table = st_lsm6dsx_i3c_ids,
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c +1 -1
index f5767cf76c1d..3a206fd4d92c 100644
@@ -134,7 +134,7 @@ MODULE_DEVICE_TABLE(spi, st_lsm6dsx_spi_id_table);
 static struct spi_driver st_lsm6dsx_driver = {
 	.driver = {
 		.name = "st_lsm6dsx_spi",
-		.pm = &st_lsm6dsx_pm_ops,
+		.pm = pm_sleep_ptr(&st_lsm6dsx_pm_ops),
 		.of_match_table = st_lsm6dsx_spi_of_match,
 	},
 	.probe = st_lsm6dsx_spi_probe,
Signature · 1 line
2.36.1
author maintainer
#8 lore raw

PATCH RESEND 5/5 iio: imu: lsm6dsx: Move exported symbols to the IIO_LSM6DSX namespace

In reply to Jonathan Cameron

From: Jonathan Cameron <[email protected]>

Avoid unnecessary pollution of the global symbol namespace by moving library functions in to a specific namespace and import that into the drivers that make use of the functions.

For more info: https://lwn.net/Articles/760045/

---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 6 +++---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c  | 1 +
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c  | 1 +
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c  | 1 +
 4 files changed, 6 insertions(+), 3 deletions(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +3 -3
index 9e4aa5c1c8d6..6b268f1c5fc3 100644
@@ -2289,7 +2289,7 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
 
 	return 0;
 }
-EXPORT_SYMBOL(st_lsm6dsx_probe);
+EXPORT_SYMBOL_NS(st_lsm6dsx_probe, IIO_LSM6DSX);
 
 static int st_lsm6dsx_suspend(struct device *dev)
 {
@@ -2366,8 +2366,8 @@ static int st_lsm6dsx_resume(struct device *dev)
 	return err;
 }
 
-EXPORT_SIMPLE_DEV_PM_OPS(st_lsm6dsx_pm_ops, st_lsm6dsx_suspend,
-			 st_lsm6dsx_resume);
+EXPORT_NS_SIMPLE_DEV_PM_OPS(st_lsm6dsx_pm_ops, st_lsm6dsx_suspend,
+			    st_lsm6dsx_resume, IIO_LSM6DSX);
 
 MODULE_AUTHOR("Lorenzo Bianconi <[email protected]>");
 MODULE_AUTHOR("Denis Ciocca <[email protected]>");
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c +1 -0
index 5bd565b93a8c..2ea34c0d3a8c 100644
@@ -146,3 +146,4 @@ MODULE_AUTHOR("Lorenzo Bianconi <[email protected]>");
 MODULE_AUTHOR("Denis Ciocca <[email protected]>");
 MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx i2c driver");
 MODULE_LICENSE("GPL v2");
+MODULE_IMPORT_NS(IIO_LSM6DSX);
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c +1 -0
index 4df186499802..3b0c8b19c448 100644
@@ -54,3 +54,4 @@ module_i3c_driver(st_lsm6dsx_driver);
 MODULE_AUTHOR("Vitor Soares <[email protected]>");
 MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx i3c driver");
 MODULE_LICENSE("GPL v2");
+MODULE_IMPORT_NS(IIO_LSM6DSX);
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c +1 -0
index 3a206fd4d92c..6a8883f022a8 100644
@@ -146,3 +146,4 @@ MODULE_AUTHOR("Lorenzo Bianconi <[email protected]>");
 MODULE_AUTHOR("Denis Ciocca <[email protected]>");
 MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx spi driver");
 MODULE_LICENSE("GPL v2");
+MODULE_IMPORT_NS(IIO_LSM6DSX);
Signature · 1 line
2.36.1
maintainer Acked-by on v1 5/5
#9 lore raw

Re: [RESEND PATCH 5/5] iio: imu: lsm6dsx: Move exported symbols to the IIO_LSM6DSX namespace

Quoted 10 lines

From: Jonathan Cameron <[email protected]>

Avoid unnecessary pollution of the global symbol namespace by moving library functions in to a specific namespace and import that into the drivers that make use of the functions.

For more info: https://lwn.net/Articles/760045/

Quoted 61 lines
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 6 +++---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c  | 1 +
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c  | 1 +
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c  | 1 +
 4 files changed, 6 insertions(+), 3 deletions(-)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +3 -3
index 9e4aa5c1c8d6..6b268f1c5fc3 100644
@@ -2289,7 +2289,7 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
 
 	return 0;
 }
-EXPORT_SYMBOL(st_lsm6dsx_probe);
+EXPORT_SYMBOL_NS(st_lsm6dsx_probe, IIO_LSM6DSX);
 
 static int st_lsm6dsx_suspend(struct device *dev)
 {
@@ -2366,8 +2366,8 @@ static int st_lsm6dsx_resume(struct device *dev)
 	return err;
 }
 
-EXPORT_SIMPLE_DEV_PM_OPS(st_lsm6dsx_pm_ops, st_lsm6dsx_suspend,
-			 st_lsm6dsx_resume);
+EXPORT_NS_SIMPLE_DEV_PM_OPS(st_lsm6dsx_pm_ops, st_lsm6dsx_suspend,
+			    st_lsm6dsx_resume, IIO_LSM6DSX);
 
 MODULE_AUTHOR("Lorenzo Bianconi <[email protected]>");
 MODULE_AUTHOR("Denis Ciocca <[email protected]>");
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c +1 -0
index 5bd565b93a8c..2ea34c0d3a8c 100644
@@ -146,3 +146,4 @@ MODULE_AUTHOR("Lorenzo Bianconi <[email protected]>");
 MODULE_AUTHOR("Denis Ciocca <[email protected]>");
 MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx i2c driver");
 MODULE_LICENSE("GPL v2");
+MODULE_IMPORT_NS(IIO_LSM6DSX);
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c +1 -0
index 4df186499802..3b0c8b19c448 100644
@@ -54,3 +54,4 @@ module_i3c_driver(st_lsm6dsx_driver);
 MODULE_AUTHOR("Vitor Soares <[email protected]>");
 MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx i3c driver");
 MODULE_LICENSE("GPL v2");
+MODULE_IMPORT_NS(IIO_LSM6DSX);
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c +1 -0
index 3a206fd4d92c..6a8883f022a8 100644
@@ -146,3 +146,4 @@ MODULE_AUTHOR("Lorenzo Bianconi <[email protected]>");
 MODULE_AUTHOR("Denis Ciocca <[email protected]>");
 MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx spi driver");
 MODULE_LICENSE("GPL v2");
+MODULE_IMPORT_NS(IIO_LSM6DSX);
Signature · 1 line
2.36.1
author maintainer
#10 lore raw
In reply to Jonathan Cameron
Quoted 9 lines · On Sat, 4 Jun 2022 17:12:18 +0100 Jonathan Cameron <[email protected]> wrote:

From: Jonathan Cameron <[email protected]>

Resend as the first part of this series went via Rafael's tree and is now available in mainline.

Hence time to return to the remainder which didn't really get much review the first time around as focus was on the more interesting new macros in the first few patches.

4 out of 5 ain't bad. (remaining one is my driver so hard to lean on anyone else to review :)

Applied to the togreg branch of iio.git and pushed out as testing for all the normal reasons.

Thanks,

Jonathan

Quoted 36 lines

Now we have NS specific EXPORT_NS[_GPL]_SIMPLE_DEV_PM_OPS() etc we can move these drivers over to their own namespaces reducing polution of the global namespace with exports that are only of interest within multi module drivers.

All comments welcome,

Thanks,

Jonathan

Jonathan Cameron (5):
iio:accel:kxsd9: Switch from CONFIG_PM guards to pm_ptr() etc
iio: humidity: hts221: Use EXPORT_SIMPLE_DEV_PM_OPS() to allow
compiler to remove dead code.
iio: humidity: hts221: Move symbol exports into IIO_HTS221 namespace
iio: imu: lsm6dsx: Use new pm_sleep_ptr() and
EXPORT_SIMPLE_DEV_PM_OPS()
iio: imu: lsm6dsx: Move exported symbols to the IIO_LSM6DSX namespace

 drivers/iio/accel/kxsd9-i2c.c                |  2 +-
 drivers/iio/accel/kxsd9-spi.c                |  2 +-
 drivers/iio/accel/kxsd9.c                    | 11 ++---------
 drivers/iio/humidity/hts221_core.c           | 12 +++++-------
 drivers/iio/humidity/hts221_i2c.c            |  3 ++-
 drivers/iio/humidity/hts221_spi.c            |  3 ++-
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 12 +++++-------
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c  |  3 ++-
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c  |  3 ++-
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c  |  3 ++-
 10 files changed, 24 insertions(+), 30 deletions(-)