linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/9] iio: Move more things from iio_dev to iio_dev_opaque
@ 2021-04-26 17:49 Jonathan Cameron
  2021-04-26 17:49 ` [PATCH 1/9] iio: core: move @id from struct iio_dev to struct iio_dev_opaque Jonathan Cameron
                   ` (9 more replies)
  0 siblings, 10 replies; 27+ messages in thread
From: Jonathan Cameron @ 2021-04-26 17:49 UTC (permalink / raw)
  To: linux-iio; +Cc: Alexandru Ardelean, Jonathan Cameron

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Intent here is to clear out the low hanging fruit so we can focus on the
more interesting elements.

Hopefully this set are all uncontroversial. Lightly tested only but
all fairly mechanical so hopefully I didn't mess up.

As for the others my current thinking is as follows

mlock: Still some instances to clear out of this being used to protect things
it should not be used for. Long run we definitely want to move this one.

scan_timestamp: Can easily use a look up function in drivers that access this
directly, but that feels like an unwanted level of indirection in
iio_push_to_buffers_with_timestamp().  Perhaps worth doing anyway.
scan_bytes is also used in this function.

active_scan_mask and masklength: Both used in valid ways inside drivers.
Could be wrapped up in access functions, but it does seem a little
convoluted.

trig: This is used correctly in lots of drivers, so should stay in
struct iio_dev.

Jonathan Cameron (9):
  iio: core: move @id from struct iio_dev to struct iio_dev_opaque
  iio: avoid shadowing of variable name in to_iio_dev_opaque()
  iio: core: move @driver_module from struct iio_dev to struct
    iio_dev_opaque
  iio: core: move @trig_readonly from struct iio_dev to struct
    iio_dev_opaque
  iio: core: move @scan_index_timestamp to struct iio_dev_opaque
  iio: core: move @info_exist_lock to struct iio_dev_opaque
  iio: core: move @chrdev from struct iio_dev to struct iio_dev_opaque
  iio: core: move @flags from struct iio_dev to struct iio_dev_opaque
  iio: core: move @clock_id from struct iio_dev to struct iio_dev_opaque

 drivers/iio/accel/adxl372.c                   |  4 +-
 drivers/iio/accel/bma180.c                    |  2 +-
 drivers/iio/accel/bmc150-accel-core.c         |  4 +-
 drivers/iio/accel/kxcjk-1013.c                |  4 +-
 drivers/iio/accel/mma8452.c                   |  2 +-
 drivers/iio/accel/mxc4005.c                   |  2 +-
 drivers/iio/accel/stk8312.c                   |  2 +-
 drivers/iio/accel/stk8ba50.c                  |  2 +-
 drivers/iio/adc/ad7606.c                      |  3 +-
 drivers/iio/adc/ad7766.c                      |  3 +-
 drivers/iio/adc/ad7768-1.c                    |  3 +-
 drivers/iio/adc/ad_sigma_delta.c              |  2 +-
 drivers/iio/adc/at91_adc.c                    |  4 +-
 drivers/iio/adc/dln2-adc.c                    |  3 +-
 drivers/iio/adc/ina2xx-adc.c                  |  3 +-
 drivers/iio/adc/ti-ads131e08.c                |  2 +-
 drivers/iio/adc/xilinx-xadc-core.c            |  2 +-
 .../buffer/industrialio-triggered-buffer.c    |  2 +-
 drivers/iio/chemical/atlas-sensor.c           |  2 +-
 drivers/iio/chemical/ccs811.c                 |  2 +-
 drivers/iio/chemical/scd30_core.c             |  3 +-
 .../common/hid-sensors/hid-sensor-trigger.c   |  2 +-
 drivers/iio/gyro/adxrs290.c                   |  2 +-
 drivers/iio/gyro/bmg160_core.c                |  4 +-
 drivers/iio/gyro/fxas21002c_core.c            |  2 +-
 drivers/iio/gyro/itg3200_buffer.c             |  2 +-
 drivers/iio/gyro/mpu3050-core.c               |  2 +-
 drivers/iio/health/afe4403.c                  |  2 +-
 drivers/iio/health/afe4404.c                  |  2 +-
 drivers/iio/imu/adis_trigger.c                |  3 +-
 drivers/iio/imu/bmi160/bmi160_core.c          |  3 +-
 drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c |  2 +-
 drivers/iio/imu/kmx61.c                       |  2 +-
 drivers/iio/industrialio-buffer.c             | 12 ++-
 drivers/iio/industrialio-core.c               | 76 +++++++++++++------
 drivers/iio/industrialio-trigger.c            | 19 +++--
 drivers/iio/industrialio-triggered-event.c    |  2 +-
 drivers/iio/inkern.c                          | 46 ++++++-----
 drivers/iio/light/acpi-als.c                  |  3 +-
 drivers/iio/light/rpr0521.c                   |  2 +-
 drivers/iio/light/si1145.c                    |  2 +-
 drivers/iio/light/vcnl4000.c                  |  3 +-
 drivers/iio/light/vcnl4035.c                  |  2 +-
 drivers/iio/magnetometer/bmc150_magn.c        |  2 +-
 drivers/iio/magnetometer/rm3100-core.c        |  2 +-
 drivers/iio/potentiostat/lmp91000.c           |  3 +-
 drivers/iio/pressure/zpa2326.c                |  3 +-
 drivers/iio/proximity/as3935.c                |  3 +-
 drivers/iio/proximity/sx9310.c                |  2 +-
 drivers/iio/proximity/sx9500.c                |  2 +-
 include/linux/iio/iio-opaque.h                | 22 +++++-
 include/linux/iio/iio.h                       | 29 +------
 52 files changed, 188 insertions(+), 131 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 1/9] iio: core: move @id from struct iio_dev to struct iio_dev_opaque
  2021-04-26 17:49 [PATCH 0/9] iio: Move more things from iio_dev to iio_dev_opaque Jonathan Cameron
@ 2021-04-26 17:49 ` Jonathan Cameron
  2021-04-27  7:44   ` Alexandru Ardelean
  2021-05-03 11:42   ` Jonathan Cameron
  2021-04-26 17:49 ` [PATCH 2/9] iio: avoid shadowing of variable name in to_iio_dev_opaque() Jonathan Cameron
                   ` (8 subsequent siblings)
  9 siblings, 2 replies; 27+ messages in thread
From: Jonathan Cameron @ 2021-04-26 17:49 UTC (permalink / raw)
  To: linux-iio; +Cc: Alexandru Ardelean, Jonathan Cameron

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Continuing from Alexandru Ardelean's introduction of the split between
driver modifiable fields and those that should only be set by the core.

This could have been done in two steps to make the actual move after
introducing iio_device_id() but there seemed limited point to that
given how mechanical the majority of the patch is.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 drivers/iio/accel/adxl372.c                   |  4 ++--
 drivers/iio/accel/bma180.c                    |  2 +-
 drivers/iio/accel/bmc150-accel-core.c         |  4 ++--
 drivers/iio/accel/kxcjk-1013.c                |  4 ++--
 drivers/iio/accel/mma8452.c                   |  2 +-
 drivers/iio/accel/mxc4005.c                   |  2 +-
 drivers/iio/accel/stk8312.c                   |  2 +-
 drivers/iio/accel/stk8ba50.c                  |  2 +-
 drivers/iio/adc/ad7606.c                      |  3 ++-
 drivers/iio/adc/ad7766.c                      |  3 ++-
 drivers/iio/adc/ad7768-1.c                    |  3 ++-
 drivers/iio/adc/ad_sigma_delta.c              |  2 +-
 drivers/iio/adc/at91_adc.c                    |  4 ++--
 drivers/iio/adc/dln2-adc.c                    |  3 ++-
 drivers/iio/adc/ina2xx-adc.c                  |  3 ++-
 drivers/iio/adc/ti-ads131e08.c                |  2 +-
 drivers/iio/adc/xilinx-xadc-core.c            |  2 +-
 .../buffer/industrialio-triggered-buffer.c    |  2 +-
 drivers/iio/chemical/atlas-sensor.c           |  2 +-
 drivers/iio/chemical/ccs811.c                 |  2 +-
 drivers/iio/chemical/scd30_core.c             |  3 ++-
 .../common/hid-sensors/hid-sensor-trigger.c   |  2 +-
 drivers/iio/gyro/adxrs290.c                   |  2 +-
 drivers/iio/gyro/bmg160_core.c                |  4 ++--
 drivers/iio/gyro/fxas21002c_core.c            |  2 +-
 drivers/iio/gyro/itg3200_buffer.c             |  2 +-
 drivers/iio/gyro/mpu3050-core.c               |  2 +-
 drivers/iio/health/afe4403.c                  |  2 +-
 drivers/iio/health/afe4404.c                  |  2 +-
 drivers/iio/imu/adis_trigger.c                |  3 ++-
 drivers/iio/imu/bmi160/bmi160_core.c          |  3 ++-
 drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c |  2 +-
 drivers/iio/imu/kmx61.c                       |  2 +-
 drivers/iio/industrialio-core.c               | 24 +++++++++++++++----
 drivers/iio/industrialio-triggered-event.c    |  2 +-
 drivers/iio/light/acpi-als.c                  |  3 ++-
 drivers/iio/light/rpr0521.c                   |  2 +-
 drivers/iio/light/si1145.c                    |  2 +-
 drivers/iio/light/vcnl4000.c                  |  3 ++-
 drivers/iio/light/vcnl4035.c                  |  2 +-
 drivers/iio/magnetometer/bmc150_magn.c        |  2 +-
 drivers/iio/magnetometer/rm3100-core.c        |  2 +-
 drivers/iio/potentiostat/lmp91000.c           |  3 ++-
 drivers/iio/pressure/zpa2326.c                |  3 ++-
 drivers/iio/proximity/as3935.c                |  3 ++-
 drivers/iio/proximity/sx9310.c                |  2 +-
 drivers/iio/proximity/sx9500.c                |  2 +-
 include/linux/iio/iio-opaque.h                |  2 ++
 include/linux/iio/iio.h                       |  4 ++--
 49 files changed, 87 insertions(+), 58 deletions(-)

diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c
index 9c9a896a872a..fc9592407717 100644
--- a/drivers/iio/accel/adxl372.c
+++ b/drivers/iio/accel/adxl372.c
@@ -1223,14 +1223,14 @@ int adxl372_probe(struct device *dev, struct regmap *regmap,
 		st->dready_trig = devm_iio_trigger_alloc(dev,
 							 "%s-dev%d",
 							 indio_dev->name,
-							 indio_dev->id);
+							 iio_device_id(indio_dev));
 		if (st->dready_trig == NULL)
 			return -ENOMEM;
 
 		st->peak_datardy_trig = devm_iio_trigger_alloc(dev,
 							       "%s-dev%d-peak",
 							       indio_dev->name,
-							       indio_dev->id);
+							       iio_device_id(indio_dev));
 		if (!st->peak_datardy_trig)
 			return -ENOMEM;
 
diff --git a/drivers/iio/accel/bma180.c b/drivers/iio/accel/bma180.c
index b8a7469cdae4..68d91a70de03 100644
--- a/drivers/iio/accel/bma180.c
+++ b/drivers/iio/accel/bma180.c
@@ -1045,7 +1045,7 @@ static int bma180_probe(struct i2c_client *client,
 
 	if (client->irq > 0) {
 		data->trig = iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name,
-			indio_dev->id);
+					       iio_device_id(indio_dev));
 		if (!data->trig) {
 			ret = -ENOMEM;
 			goto err_chip_disable;
diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
index 04d85ce34e9f..62a164a7b852 100644
--- a/drivers/iio/accel/bmc150-accel-core.c
+++ b/drivers/iio/accel/bmc150-accel-core.c
@@ -1470,9 +1470,9 @@ static int bmc150_accel_triggers_setup(struct iio_dev *indio_dev,
 		struct bmc150_accel_trigger *t = &data->triggers[i];
 
 		t->indio_trig = devm_iio_trigger_alloc(dev,
-					bmc150_accel_triggers[i].name,
+						       bmc150_accel_triggers[i].name,
 						       indio_dev->name,
-						       indio_dev->id);
+						       iio_device_id(indio_dev));
 		if (!t->indio_trig) {
 			ret = -ENOMEM;
 			break;
diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c
index ff724bc17a45..283e6a3feffc 100644
--- a/drivers/iio/accel/kxcjk-1013.c
+++ b/drivers/iio/accel/kxcjk-1013.c
@@ -1404,7 +1404,7 @@ static int kxcjk1013_probe(struct i2c_client *client,
 		data->dready_trig = devm_iio_trigger_alloc(&client->dev,
 							   "%s-dev%d",
 							   indio_dev->name,
-							   indio_dev->id);
+							   iio_device_id(indio_dev));
 		if (!data->dready_trig) {
 			ret = -ENOMEM;
 			goto err_poweroff;
@@ -1413,7 +1413,7 @@ static int kxcjk1013_probe(struct i2c_client *client,
 		data->motion_trig = devm_iio_trigger_alloc(&client->dev,
 							  "%s-any-motion-dev%d",
 							  indio_dev->name,
-							  indio_dev->id);
+							  iio_device_id(indio_dev));
 		if (!data->motion_trig) {
 			ret = -ENOMEM;
 			goto err_poweroff;
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index 4d307dfb9169..464a6bfe6746 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -1461,7 +1461,7 @@ static int mma8452_trigger_setup(struct iio_dev *indio_dev)
 
 	trig = devm_iio_trigger_alloc(&data->client->dev, "%s-dev%d",
 				      indio_dev->name,
-				      indio_dev->id);
+				      iio_device_id(indio_dev));
 	if (!trig)
 		return -ENOMEM;
 
diff --git a/drivers/iio/accel/mxc4005.c b/drivers/iio/accel/mxc4005.c
index fb3cbaa62bd8..98c7f5f59011 100644
--- a/drivers/iio/accel/mxc4005.c
+++ b/drivers/iio/accel/mxc4005.c
@@ -433,7 +433,7 @@ static int mxc4005_probe(struct i2c_client *client,
 		data->dready_trig = devm_iio_trigger_alloc(&client->dev,
 							   "%s-dev%d",
 							   indio_dev->name,
-							   indio_dev->id);
+							   iio_device_id(indio_dev));
 		if (!data->dready_trig)
 			return -ENOMEM;
 
diff --git a/drivers/iio/accel/stk8312.c b/drivers/iio/accel/stk8312.c
index 60aecfa9fd92..aeab108c457d 100644
--- a/drivers/iio/accel/stk8312.c
+++ b/drivers/iio/accel/stk8312.c
@@ -552,7 +552,7 @@ static int stk8312_probe(struct i2c_client *client,
 		data->dready_trig = devm_iio_trigger_alloc(&client->dev,
 							   "%s-dev%d",
 							   indio_dev->name,
-							   indio_dev->id);
+							   iio_device_id(indio_dev));
 		if (!data->dready_trig) {
 			ret = -ENOMEM;
 			goto err_power_off;
diff --git a/drivers/iio/accel/stk8ba50.c b/drivers/iio/accel/stk8ba50.c
index 7cf9cb7e8666..3e7cf23be7e1 100644
--- a/drivers/iio/accel/stk8ba50.c
+++ b/drivers/iio/accel/stk8ba50.c
@@ -448,7 +448,7 @@ static int stk8ba50_probe(struct i2c_client *client,
 		data->dready_trig = devm_iio_trigger_alloc(&client->dev,
 							   "%s-dev%d",
 							   indio_dev->name,
-							   indio_dev->id);
+							   iio_device_id(indio_dev));
 		if (!data->dready_trig) {
 			ret = -ENOMEM;
 			goto err_power_off;
diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
index 0af0bb4d5a7f..0a60ecc69d38 100644
--- a/drivers/iio/adc/ad7606.c
+++ b/drivers/iio/adc/ad7606.c
@@ -663,7 +663,8 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
 	}
 
 	st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
-					  indio_dev->name, indio_dev->id);
+					  indio_dev->name,
+					  iio_device_id(indio_dev));
 	if (!st->trig)
 		return -ENOMEM;
 
diff --git a/drivers/iio/adc/ad7766.c b/drivers/iio/adc/ad7766.c
index 1e41759f3ee5..236a455aaa18 100644
--- a/drivers/iio/adc/ad7766.c
+++ b/drivers/iio/adc/ad7766.c
@@ -248,7 +248,8 @@ static int ad7766_probe(struct spi_device *spi)
 
 	if (spi->irq > 0) {
 		ad7766->trig = devm_iio_trigger_alloc(&spi->dev, "%s-dev%d",
-			indio_dev->name, indio_dev->id);
+						      indio_dev->name,
+						      iio_device_id(indio_dev));
 		if (!ad7766->trig)
 			return -ENOMEM;
 
diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c
index c945f1349623..41752777e96c 100644
--- a/drivers/iio/adc/ad7768-1.c
+++ b/drivers/iio/adc/ad7768-1.c
@@ -626,7 +626,8 @@ static int ad7768_probe(struct spi_device *spi)
 	}
 
 	st->trig = devm_iio_trigger_alloc(&spi->dev, "%s-dev%d",
-					  indio_dev->name, indio_dev->id);
+					  indio_dev->name,
+					  iio_device_id(indio_dev));
 	if (!st->trig)
 		return -ENOMEM;
 
diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index e777ec718973..69b979331ccd 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -477,7 +477,7 @@ static int ad_sd_probe_trigger(struct iio_dev *indio_dev)
 
 	sigma_delta->trig = iio_trigger_alloc(&sigma_delta->spi->dev,
 					      "%s-dev%d", indio_dev->name,
-					      indio_dev->id);
+					      iio_device_id(indio_dev));
 	if (sigma_delta->trig == NULL) {
 		ret = -ENOMEM;
 		goto error_ret;
diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index 0b5f0c91d0d7..5a7d3a3a5fa8 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -547,7 +547,7 @@ static int at91_adc_get_trigger_value_by_name(struct iio_dev *idev,
 		char *name = kasprintf(GFP_KERNEL,
 				"%s-dev%d-%s",
 				idev->name,
-				idev->id,
+				iio_device_id(idev),
 				triggers[i].name);
 		if (!name)
 			return -ENOMEM;
@@ -626,7 +626,7 @@ static struct iio_trigger *at91_adc_allocate_trigger(struct iio_dev *idev,
 	int ret;
 
 	trig = iio_trigger_alloc(idev->dev.parent, "%s-dev%d-%s", idev->name,
-				 idev->id, trigger->name);
+				 iio_device_id(idev), trigger->name);
 	if (trig == NULL)
 		return NULL;
 
diff --git a/drivers/iio/adc/dln2-adc.c b/drivers/iio/adc/dln2-adc.c
index 0d53ef18e045..16407664182c 100644
--- a/drivers/iio/adc/dln2-adc.c
+++ b/drivers/iio/adc/dln2-adc.c
@@ -649,7 +649,8 @@ static int dln2_adc_probe(struct platform_device *pdev)
 	indio_dev->setup_ops = &dln2_adc_buffer_setup_ops;
 
 	dln2->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
-					    indio_dev->name, indio_dev->id);
+					    indio_dev->name,
+					    iio_device_id(indio_dev));
 	if (!dln2->trig) {
 		dev_err(dev, "failed to allocate trigger\n");
 		return -ENOMEM;
diff --git a/drivers/iio/adc/ina2xx-adc.c b/drivers/iio/adc/ina2xx-adc.c
index 2ae54258b221..a4b2ff9e0dd5 100644
--- a/drivers/iio/adc/ina2xx-adc.c
+++ b/drivers/iio/adc/ina2xx-adc.c
@@ -843,7 +843,8 @@ static int ina2xx_buffer_enable(struct iio_dev *indio_dev)
 		chip->allow_async_readout);
 
 	task = kthread_create(ina2xx_capture_thread, (void *)indio_dev,
-			      "%s:%d-%uus", indio_dev->name, indio_dev->id,
+			      "%s:%d-%uus", indio_dev->name,
+			      iio_device_id(indio_dev),
 			      sampling_us);
 	if (IS_ERR(task))
 		return PTR_ERR(task);
diff --git a/drivers/iio/adc/ti-ads131e08.c b/drivers/iio/adc/ti-ads131e08.c
index 0060d5f0abb0..5dcf1e9294d7 100644
--- a/drivers/iio/adc/ti-ads131e08.c
+++ b/drivers/iio/adc/ti-ads131e08.c
@@ -844,7 +844,7 @@ static int ads131e08_probe(struct spi_device *spi)
 	}
 
 	st->trig = devm_iio_trigger_alloc(&spi->dev, "%s-dev%d",
-		indio_dev->name, indio_dev->id);
+		indio_dev->name, iio_device_id(indio_dev));
 	if (!st->trig) {
 		dev_err(&spi->dev, "failed to allocate IIO trigger\n");
 		return -ENOMEM;
diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c
index 6914c1900ed0..198d2916266d 100644
--- a/drivers/iio/adc/xilinx-xadc-core.c
+++ b/drivers/iio/adc/xilinx-xadc-core.c
@@ -743,7 +743,7 @@ static struct iio_trigger *xadc_alloc_trigger(struct iio_dev *indio_dev,
 	int ret;
 
 	trig = devm_iio_trigger_alloc(dev, "%s%d-%s", indio_dev->name,
-				      indio_dev->id, name);
+				      iio_device_id(indio_dev), name);
 	if (trig == NULL)
 		return ERR_PTR(-ENOMEM);
 
diff --git a/drivers/iio/buffer/industrialio-triggered-buffer.c b/drivers/iio/buffer/industrialio-triggered-buffer.c
index ebb4520ac291..f77c4538141e 100644
--- a/drivers/iio/buffer/industrialio-triggered-buffer.c
+++ b/drivers/iio/buffer/industrialio-triggered-buffer.c
@@ -56,7 +56,7 @@ int iio_triggered_buffer_setup_ext(struct iio_dev *indio_dev,
 						 indio_dev,
 						 "%s_consumer%d",
 						 indio_dev->name,
-						 indio_dev->id);
+						 iio_device_id(indio_dev));
 	if (indio_dev->pollfunc == NULL) {
 		ret = -ENOMEM;
 		goto error_kfifo_free;
diff --git a/drivers/iio/chemical/atlas-sensor.c b/drivers/iio/chemical/atlas-sensor.c
index 56ba6c82b501..d10f921b233a 100644
--- a/drivers/iio/chemical/atlas-sensor.c
+++ b/drivers/iio/chemical/atlas-sensor.c
@@ -640,7 +640,7 @@ static int atlas_probe(struct i2c_client *client,
 	indio_dev->modes = INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE;
 
 	trig = devm_iio_trigger_alloc(&client->dev, "%s-dev%d",
-				      indio_dev->name, indio_dev->id);
+				      indio_dev->name, iio_device_id(indio_dev));
 
 	if (!trig)
 		return -ENOMEM;
diff --git a/drivers/iio/chemical/ccs811.c b/drivers/iio/chemical/ccs811.c
index 886e96496dbf..847194fa1e46 100644
--- a/drivers/iio/chemical/ccs811.c
+++ b/drivers/iio/chemical/ccs811.c
@@ -491,7 +491,7 @@ static int ccs811_probe(struct i2c_client *client,
 		data->drdy_trig = devm_iio_trigger_alloc(&client->dev,
 							 "%s-dev%d",
 							 indio_dev->name,
-							 indio_dev->id);
+							 iio_device_id(indio_dev));
 		if (!data->drdy_trig) {
 			ret = -ENOMEM;
 			goto err_poweroff;
diff --git a/drivers/iio/chemical/scd30_core.c b/drivers/iio/chemical/scd30_core.c
index d89f117dd0ef..9fe6bbe9ee04 100644
--- a/drivers/iio/chemical/scd30_core.c
+++ b/drivers/iio/chemical/scd30_core.c
@@ -640,7 +640,8 @@ static int scd30_setup_trigger(struct iio_dev *indio_dev)
 	struct iio_trigger *trig;
 	int ret;
 
-	trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, indio_dev->id);
+	trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name,
+				      iio_device_id(indio_dev));
 	if (!trig) {
 		dev_err(dev, "failed to allocate trigger\n");
 		return -ENOMEM;
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
index 95ddccb44f1c..5a7b3e253e58 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
@@ -256,7 +256,7 @@ int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
 	}
 
 	trig = iio_trigger_alloc(indio_dev->dev.parent,
-				 "%s-dev%d", name, indio_dev->id);
+				 "%s-dev%d", name, iio_device_id(indio_dev));
 	if (trig == NULL) {
 		dev_err(&indio_dev->dev, "Trigger Allocate Failed\n");
 		ret = -ENOMEM;
diff --git a/drivers/iio/gyro/adxrs290.c b/drivers/iio/gyro/adxrs290.c
index cec5e1f17c22..3e0734ddafe3 100644
--- a/drivers/iio/gyro/adxrs290.c
+++ b/drivers/iio/gyro/adxrs290.c
@@ -589,7 +589,7 @@ static int adxrs290_probe_trigger(struct iio_dev *indio_dev)
 
 	st->dready_trig = devm_iio_trigger_alloc(&st->spi->dev, "%s-dev%d",
 						 indio_dev->name,
-						 indio_dev->id);
+						 iio_device_id(indio_dev));
 	if (!st->dready_trig)
 		return -ENOMEM;
 
diff --git a/drivers/iio/gyro/bmg160_core.c b/drivers/iio/gyro/bmg160_core.c
index b11ebd9bb7a4..26a9ed5770c6 100644
--- a/drivers/iio/gyro/bmg160_core.c
+++ b/drivers/iio/gyro/bmg160_core.c
@@ -1137,14 +1137,14 @@ int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq,
 		data->dready_trig = devm_iio_trigger_alloc(dev,
 							   "%s-dev%d",
 							   indio_dev->name,
-							   indio_dev->id);
+							   iio_device_id(indio_dev));
 		if (!data->dready_trig)
 			return -ENOMEM;
 
 		data->motion_trig = devm_iio_trigger_alloc(dev,
 							  "%s-any-motion-dev%d",
 							  indio_dev->name,
-							  indio_dev->id);
+							  iio_device_id(indio_dev));
 		if (!data->motion_trig)
 			return -ENOMEM;
 
diff --git a/drivers/iio/gyro/fxas21002c_core.c b/drivers/iio/gyro/fxas21002c_core.c
index 1a20c6b88e7d..5af7b48ff01a 100644
--- a/drivers/iio/gyro/fxas21002c_core.c
+++ b/drivers/iio/gyro/fxas21002c_core.c
@@ -852,7 +852,7 @@ static int fxas21002c_trigger_probe(struct fxas21002c_data *data)
 
 	data->dready_trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
 						   indio_dev->name,
-						   indio_dev->id);
+						   iio_device_id(indio_dev));
 	if (!data->dready_trig)
 		return -ENOMEM;
 
diff --git a/drivers/iio/gyro/itg3200_buffer.c b/drivers/iio/gyro/itg3200_buffer.c
index af0aaa146f0c..04dd6a7969ea 100644
--- a/drivers/iio/gyro/itg3200_buffer.c
+++ b/drivers/iio/gyro/itg3200_buffer.c
@@ -114,7 +114,7 @@ int itg3200_probe_trigger(struct iio_dev *indio_dev)
 	struct itg3200 *st = iio_priv(indio_dev);
 
 	st->trig = iio_trigger_alloc(&st->i2c->dev, "%s-dev%d", indio_dev->name,
-				     indio_dev->id);
+				     iio_device_id(indio_dev));
 	if (!st->trig)
 		return -ENOMEM;
 
diff --git a/drivers/iio/gyro/mpu3050-core.c b/drivers/iio/gyro/mpu3050-core.c
index ac90be03332a..131e6f54948e 100644
--- a/drivers/iio/gyro/mpu3050-core.c
+++ b/drivers/iio/gyro/mpu3050-core.c
@@ -1049,7 +1049,7 @@ static int mpu3050_trigger_probe(struct iio_dev *indio_dev, int irq)
 	mpu3050->trig = devm_iio_trigger_alloc(&indio_dev->dev,
 					       "%s-dev%d",
 					       indio_dev->name,
-					       indio_dev->id);
+					       iio_device_id(indio_dev));
 	if (!mpu3050->trig)
 		return -ENOMEM;
 
diff --git a/drivers/iio/health/afe4403.c b/drivers/iio/health/afe4403.c
index 1fa8d51d5080..d4921385aaf7 100644
--- a/drivers/iio/health/afe4403.c
+++ b/drivers/iio/health/afe4403.c
@@ -521,7 +521,7 @@ static int afe4403_probe(struct spi_device *spi)
 		afe->trig = devm_iio_trigger_alloc(afe->dev,
 						   "%s-dev%d",
 						   indio_dev->name,
-						   indio_dev->id);
+						   iio_device_id(indio_dev));
 		if (!afe->trig) {
 			dev_err(afe->dev, "Unable to allocate IIO trigger\n");
 			ret = -ENOMEM;
diff --git a/drivers/iio/health/afe4404.c b/drivers/iio/health/afe4404.c
index e1476bf79fe2..d8a27dfe074a 100644
--- a/drivers/iio/health/afe4404.c
+++ b/drivers/iio/health/afe4404.c
@@ -528,7 +528,7 @@ static int afe4404_probe(struct i2c_client *client,
 		afe->trig = devm_iio_trigger_alloc(afe->dev,
 						   "%s-dev%d",
 						   indio_dev->name,
-						   indio_dev->id);
+						   iio_device_id(indio_dev));
 		if (!afe->trig) {
 			dev_err(afe->dev, "Unable to allocate IIO trigger\n");
 			ret = -ENOMEM;
diff --git a/drivers/iio/imu/adis_trigger.c b/drivers/iio/imu/adis_trigger.c
index fa5540fabacc..48eedc29b28a 100644
--- a/drivers/iio/imu/adis_trigger.c
+++ b/drivers/iio/imu/adis_trigger.c
@@ -62,7 +62,8 @@ int devm_adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev)
 	int ret;
 
 	adis->trig = devm_iio_trigger_alloc(&adis->spi->dev, "%s-dev%d",
-					    indio_dev->name, indio_dev->id);
+					    indio_dev->name,
+					    iio_device_id(indio_dev));
 	if (!adis->trig)
 		return -ENOMEM;
 
diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c
index 290b5ef83f77..b63bd7e5e5e5 100644
--- a/drivers/iio/imu/bmi160/bmi160_core.c
+++ b/drivers/iio/imu/bmi160/bmi160_core.c
@@ -785,7 +785,8 @@ int bmi160_probe_trigger(struct iio_dev *indio_dev, int irq, u32 irq_type)
 	int ret;
 
 	data->trig = devm_iio_trigger_alloc(&indio_dev->dev, "%s-dev%d",
-					    indio_dev->name, indio_dev->id);
+					    indio_dev->name,
+					    iio_device_id(indio_dev));
 
 	if (data->trig == NULL)
 		return -ENOMEM;
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
index de8ed1446d60..e21ba778595a 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
@@ -238,7 +238,7 @@ int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev, int irq_type)
 	st->trig = devm_iio_trigger_alloc(&indio_dev->dev,
 					  "%s-dev%d",
 					  indio_dev->name,
-					  indio_dev->id);
+					  iio_device_id(indio_dev));
 	if (!st->trig)
 		return -ENOMEM;
 
diff --git a/drivers/iio/imu/kmx61.c b/drivers/iio/imu/kmx61.c
index fc5a60fcfec0..d3e06ce99c1e 100644
--- a/drivers/iio/imu/kmx61.c
+++ b/drivers/iio/imu/kmx61.c
@@ -1264,7 +1264,7 @@ static struct iio_trigger *kmx61_trigger_setup(struct kmx61_data *data,
 				      "%s-%s-dev%d",
 				      indio_dev->name,
 				      tag,
-				      indio_dev->id);
+				      iio_device_id(indio_dev));
 	if (!trig)
 		return ERR_PTR(-ENOMEM);
 
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 022198c32e32..c16b8f344c93 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -169,6 +169,20 @@ static const char * const iio_chan_info_postfix[] = {
 	[IIO_CHAN_INFO_THERMOCOUPLE_TYPE] = "thermocouple_type",
 	[IIO_CHAN_INFO_CALIBAMBIENT] = "calibambient",
 };
+/**
+ * iio_device_id() - query the unique ID for the device
+ * @indio_dev:		Device structure whose ID is being queried
+ *
+ * The IIO device ID is a unique index used for example for the naming
+ * of the character device /dev/iio\:device[ID]
+ */
+int iio_device_id(struct iio_dev *indio_dev)
+{
+	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
+
+	return iio_dev_opaque->id;
+}
+EXPORT_SYMBOL_GPL(iio_device_id);
 
 /**
  * iio_sysfs_match_string_with_gaps - matches given string in an array with gaps
@@ -1588,7 +1602,7 @@ static void iio_dev_release(struct device *device)
 
 	iio_device_detach_buffers(indio_dev);
 
-	ida_simple_remove(&iio_ida, indio_dev->id);
+	ida_simple_remove(&iio_ida, iio_dev_opaque->id);
 	kfree(iio_dev_opaque);
 }
 
@@ -1631,14 +1645,14 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)
 	mutex_init(&indio_dev->info_exist_lock);
 	INIT_LIST_HEAD(&iio_dev_opaque->channel_attr_list);
 
-	indio_dev->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL);
-	if (indio_dev->id < 0) {
+	iio_dev_opaque->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL);
+	if (iio_dev_opaque->id < 0) {
 		/* cannot use a dev_err as the name isn't available */
 		pr_err("failed to get device id\n");
 		kfree(iio_dev_opaque);
 		return NULL;
 	}
-	dev_set_name(&indio_dev->dev, "iio:device%d", indio_dev->id);
+	dev_set_name(&indio_dev->dev, "iio:device%d", iio_dev_opaque->id);
 	INIT_LIST_HEAD(&iio_dev_opaque->buffer_list);
 	INIT_LIST_HEAD(&iio_dev_opaque->ioctl_handlers);
 
@@ -1892,7 +1906,7 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod)
 		cdev_init(&indio_dev->chrdev, &iio_event_fileops);
 
 	if (iio_dev_opaque->attached_buffers_cnt || iio_dev_opaque->event_interface) {
-		indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), indio_dev->id);
+		indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), iio_dev_opaque->id);
 		indio_dev->chrdev.owner = this_mod;
 	}
 
diff --git a/drivers/iio/industrialio-triggered-event.c b/drivers/iio/industrialio-triggered-event.c
index 53da9ab17a62..4bedc65c9fe3 100644
--- a/drivers/iio/industrialio-triggered-event.c
+++ b/drivers/iio/industrialio-triggered-event.c
@@ -37,7 +37,7 @@ int iio_triggered_event_setup(struct iio_dev *indio_dev,
 						       indio_dev,
 						       "%s_consumer%d",
 						       indio_dev->name,
-						       indio_dev->id);
+						       iio_device_id(indio_dev));
 	if (indio_dev->pollfunc_event == NULL)
 		return -ENOMEM;
 
diff --git a/drivers/iio/light/acpi-als.c b/drivers/iio/light/acpi-als.c
index 30393f08e082..260f96ea5f3c 100644
--- a/drivers/iio/light/acpi-als.c
+++ b/drivers/iio/light/acpi-als.c
@@ -206,7 +206,8 @@ static int acpi_als_add(struct acpi_device *device)
 	indio_dev->channels = acpi_als_channels;
 	indio_dev->num_channels = ARRAY_SIZE(acpi_als_channels);
 
-	als->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, indio_dev->id);
+	als->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name,
+					   iio_device_id(indio_dev));
 	if (!als->trig)
 		return -ENOMEM;
 
diff --git a/drivers/iio/light/rpr0521.c b/drivers/iio/light/rpr0521.c
index 033578f444e4..7e332de0e6a5 100644
--- a/drivers/iio/light/rpr0521.c
+++ b/drivers/iio/light/rpr0521.c
@@ -985,7 +985,7 @@ static int rpr0521_probe(struct i2c_client *client,
 		/* Trigger0 producer setup */
 		data->drdy_trigger0 = devm_iio_trigger_alloc(
 			indio_dev->dev.parent,
-			"%s-dev%d", indio_dev->name, indio_dev->id);
+			"%s-dev%d", indio_dev->name, iio_device_id(indio_dev));
 		if (!data->drdy_trigger0) {
 			ret = -ENOMEM;
 			goto err_pm_disable;
diff --git a/drivers/iio/light/si1145.c b/drivers/iio/light/si1145.c
index 9b5c99823943..3fb52402fcc3 100644
--- a/drivers/iio/light/si1145.c
+++ b/drivers/iio/light/si1145.c
@@ -1243,7 +1243,7 @@ static int si1145_probe_trigger(struct iio_dev *indio_dev)
 	int ret;
 
 	trig = devm_iio_trigger_alloc(&client->dev,
-			"%s-dev%d", indio_dev->name, indio_dev->id);
+			"%s-dev%d", indio_dev->name, iio_device_id(indio_dev));
 	if (!trig)
 		return -ENOMEM;
 
diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
index 2f7916f95689..4a61865d01cd 100644
--- a/drivers/iio/light/vcnl4000.c
+++ b/drivers/iio/light/vcnl4000.c
@@ -998,7 +998,8 @@ static int vcnl4010_probe_trigger(struct iio_dev *indio_dev)
 	struct iio_trigger *trigger;
 
 	trigger = devm_iio_trigger_alloc(&client->dev, "%s-dev%d",
-					 indio_dev->name, indio_dev->id);
+					 indio_dev->name,
+					 iio_device_id(indio_dev));
 	if (!trigger)
 		return -ENOMEM;
 
diff --git a/drivers/iio/light/vcnl4035.c b/drivers/iio/light/vcnl4035.c
index ae87740d9cef..691a54b763e1 100644
--- a/drivers/iio/light/vcnl4035.c
+++ b/drivers/iio/light/vcnl4035.c
@@ -507,7 +507,7 @@ static int vcnl4035_probe_trigger(struct iio_dev *indio_dev)
 
 	data->drdy_trigger0 = devm_iio_trigger_alloc(
 			indio_dev->dev.parent,
-			"%s-dev%d", indio_dev->name, indio_dev->id);
+			"%s-dev%d", indio_dev->name, iio_device_id(indio_dev));
 	if (!data->drdy_trigger0)
 		return -ENOMEM;
 
diff --git a/drivers/iio/magnetometer/bmc150_magn.c b/drivers/iio/magnetometer/bmc150_magn.c
index 00f9766bad5c..d75b437a43f2 100644
--- a/drivers/iio/magnetometer/bmc150_magn.c
+++ b/drivers/iio/magnetometer/bmc150_magn.c
@@ -915,7 +915,7 @@ int bmc150_magn_probe(struct device *dev, struct regmap *regmap,
 		data->dready_trig = devm_iio_trigger_alloc(dev,
 							   "%s-dev%d",
 							   indio_dev->name,
-							   indio_dev->id);
+							   iio_device_id(indio_dev));
 		if (!data->dready_trig) {
 			ret = -ENOMEM;
 			dev_err(dev, "iio trigger alloc failed\n");
diff --git a/drivers/iio/magnetometer/rm3100-core.c b/drivers/iio/magnetometer/rm3100-core.c
index dd811da9cb6d..4df5887fd04c 100644
--- a/drivers/iio/magnetometer/rm3100-core.c
+++ b/drivers/iio/magnetometer/rm3100-core.c
@@ -575,7 +575,7 @@ int rm3100_common_probe(struct device *dev, struct regmap *regmap, int irq)
 
 		data->drdy_trig = devm_iio_trigger_alloc(dev, "%s-drdy%d",
 							 indio_dev->name,
-							 indio_dev->id);
+							 iio_device_id(indio_dev));
 		if (!data->drdy_trig)
 			return -ENOMEM;
 
diff --git a/drivers/iio/potentiostat/lmp91000.c b/drivers/iio/potentiostat/lmp91000.c
index 8a9c576616ee..1948e2d22c27 100644
--- a/drivers/iio/potentiostat/lmp91000.c
+++ b/drivers/iio/potentiostat/lmp91000.c
@@ -323,7 +323,8 @@ static int lmp91000_probe(struct i2c_client *client,
 	}
 
 	data->trig = devm_iio_trigger_alloc(dev, "%s-mux%d",
-					    indio_dev->name, indio_dev->id);
+					    indio_dev->name,
+					    iio_device_id(indio_dev));
 	if (!data->trig) {
 		dev_err(dev, "cannot allocate iio trigger.\n");
 		return -ENOMEM;
diff --git a/drivers/iio/pressure/zpa2326.c b/drivers/iio/pressure/zpa2326.c
index a93411216aee..89295c90f801 100644
--- a/drivers/iio/pressure/zpa2326.c
+++ b/drivers/iio/pressure/zpa2326.c
@@ -1408,7 +1408,8 @@ static int zpa2326_init_managed_trigger(struct device          *parent,
 		return 0;
 
 	trigger = devm_iio_trigger_alloc(parent, "%s-dev%d",
-					 indio_dev->name, indio_dev->id);
+					 indio_dev->name,
+					 iio_device_id(indio_dev));
 	if (!trigger)
 		return -ENOMEM;
 
diff --git a/drivers/iio/proximity/as3935.c b/drivers/iio/proximity/as3935.c
index edc4a35ae66d..dc20fe81232c 100644
--- a/drivers/iio/proximity/as3935.c
+++ b/drivers/iio/proximity/as3935.c
@@ -404,7 +404,8 @@ static int as3935_probe(struct spi_device *spi)
 	indio_dev->info = &as3935_info;
 
 	trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
-				      indio_dev->name, indio_dev->id);
+				      indio_dev->name,
+				      iio_device_id(indio_dev));
 
 	if (!trig)
 		return -ENOMEM;
diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c
index 327ebb7ddbb9..175f3b7c61d7 100644
--- a/drivers/iio/proximity/sx9310.c
+++ b/drivers/iio/proximity/sx9310.c
@@ -1473,7 +1473,7 @@ static int sx9310_probe(struct i2c_client *client)
 
 		data->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
 						    indio_dev->name,
-						    indio_dev->id);
+						    iio_device_id(indio_dev));
 		if (!data->trig)
 			return -ENOMEM;
 
diff --git a/drivers/iio/proximity/sx9500.c b/drivers/iio/proximity/sx9500.c
index a87f4a8e4327..3e4ddb2e8c2b 100644
--- a/drivers/iio/proximity/sx9500.c
+++ b/drivers/iio/proximity/sx9500.c
@@ -946,7 +946,7 @@ static int sx9500_probe(struct i2c_client *client,
 			return ret;
 
 		data->trig = devm_iio_trigger_alloc(&client->dev,
-				"%s-dev%d", indio_dev->name, indio_dev->id);
+				"%s-dev%d", indio_dev->name, iio_device_id(indio_dev));
 		if (!data->trig)
 			return -ENOMEM;
 
diff --git a/include/linux/iio/iio-opaque.h b/include/linux/iio/iio-opaque.h
index 32addd5e790e..e66b029d99de 100644
--- a/include/linux/iio/iio-opaque.h
+++ b/include/linux/iio/iio-opaque.h
@@ -6,6 +6,7 @@
 /**
  * struct iio_dev_opaque - industrial I/O device opaque information
  * @indio_dev:			public industrial I/O device information
+ * @id:			used to identify device internally
  * @event_interface:		event chrdevs associated with interrupt lines
  * @attached_buffers:		array of buffers statically attached by the driver
  * @attached_buffers_cnt:	number of buffers in the array of statically attached buffers
@@ -26,6 +27,7 @@
  */
 struct iio_dev_opaque {
 	struct iio_dev			indio_dev;
+	int				id;
 	struct iio_event_interface	*event_interface;
 	struct iio_buffer		**attached_buffers;
 	unsigned int			attached_buffers_cnt;
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index f2d65e2e88b6..569861d5887a 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -488,7 +488,6 @@ struct iio_buffer_setup_ops {
 
 /**
  * struct iio_dev - industrial I/O device
- * @id:			[INTERN] used to identify device internally
  * @driver_module:	[INTERN] used to make it harder to undercut users
  * @modes:		[DRIVER] operating modes supported by device
  * @currentmode:	[DRIVER] current operating mode
@@ -523,7 +522,6 @@ struct iio_buffer_setup_ops {
  *			**MUST** be accessed **ONLY** via iio_priv() helper
  */
 struct iio_dev {
-	int				id;
 	struct module			*driver_module;
 
 	int				modes;
@@ -559,6 +557,8 @@ struct iio_dev {
 	void				*priv;
 };
 
+int iio_device_id(struct iio_dev *indio_dev);
+
 const struct iio_chan_spec
 *iio_find_channel_from_si(struct iio_dev *indio_dev, int si);
 /**
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 2/9] iio: avoid shadowing of variable name in to_iio_dev_opaque()
  2021-04-26 17:49 [PATCH 0/9] iio: Move more things from iio_dev to iio_dev_opaque Jonathan Cameron
  2021-04-26 17:49 ` [PATCH 1/9] iio: core: move @id from struct iio_dev to struct iio_dev_opaque Jonathan Cameron
@ 2021-04-26 17:49 ` Jonathan Cameron
  2021-04-27  7:45   ` Alexandru Ardelean
  2021-04-26 17:49 ` [PATCH 3/9] iio: core: move @driver_module from struct iio_dev to struct iio_dev_opaque Jonathan Cameron
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 27+ messages in thread
From: Jonathan Cameron @ 2021-04-26 17:49 UTC (permalink / raw)
  To: linux-iio; +Cc: Alexandru Ardelean, Jonathan Cameron

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

indio_dev was both the macro input parameter and the field name
in this macro.  That causes trouble if the instance of
struct iio_dev passed in is not called indio_dev.

Whilst a fix of sorts, no need to backport as it seems we never
hit this previously due to some very consistent naming in IIO.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 include/linux/iio/iio-opaque.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/iio/iio-opaque.h b/include/linux/iio/iio-opaque.h
index e66b029d99de..f876e3aede2c 100644
--- a/include/linux/iio/iio-opaque.h
+++ b/include/linux/iio/iio-opaque.h
@@ -48,7 +48,7 @@ struct iio_dev_opaque {
 #endif
 };
 
-#define to_iio_dev_opaque(indio_dev)		\
-	container_of(indio_dev, struct iio_dev_opaque, indio_dev)
+#define to_iio_dev_opaque(_indio_dev)		\
+	container_of((_indio_dev), struct iio_dev_opaque, indio_dev)
 
 #endif
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 3/9] iio: core: move @driver_module from struct iio_dev to struct iio_dev_opaque
  2021-04-26 17:49 [PATCH 0/9] iio: Move more things from iio_dev to iio_dev_opaque Jonathan Cameron
  2021-04-26 17:49 ` [PATCH 1/9] iio: core: move @id from struct iio_dev to struct iio_dev_opaque Jonathan Cameron
  2021-04-26 17:49 ` [PATCH 2/9] iio: avoid shadowing of variable name in to_iio_dev_opaque() Jonathan Cameron
@ 2021-04-26 17:49 ` Jonathan Cameron
  2021-04-28  6:55   ` Alexandru Ardelean
  2021-04-26 17:49 ` [PATCH 4/9] iio: core: move @trig_readonly " Jonathan Cameron
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 27+ messages in thread
From: Jonathan Cameron @ 2021-04-26 17:49 UTC (permalink / raw)
  To: linux-iio; +Cc: Alexandru Ardelean, Jonathan Cameron

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Continuing move to hide internal elements from drivers, move this structure
element over.  It's only accessed from iio core files so this one was
straight forward and no accessor functions are needed.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 drivers/iio/industrialio-core.c    | 2 +-
 drivers/iio/industrialio-trigger.c | 9 ++++++---
 include/linux/iio/iio-opaque.h     | 2 ++
 include/linux/iio/iio.h            | 3 ---
 4 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index c16b8f344c93..8c38f1f6e075 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -1859,7 +1859,7 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod)
 	if (!indio_dev->info)
 		return -EINVAL;
 
-	indio_dev->driver_module = this_mod;
+	iio_dev_opaque->driver_module = this_mod;
 	/* If the calling driver did not initialize of_node, do it here */
 	if (!indio_dev->dev.of_node && indio_dev->dev.parent)
 		indio_dev->dev.of_node = indio_dev->dev.parent->of_node;
diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
index 3236647b2c37..b489eeeb0004 100644
--- a/drivers/iio/industrialio-trigger.c
+++ b/drivers/iio/industrialio-trigger.c
@@ -13,6 +13,7 @@
 #include <linux/slab.h>
 
 #include <linux/iio/iio.h>
+#include <linux/iio/iio-opaque.h>
 #include <linux/iio/trigger.h>
 #include "iio_core.h"
 #include "iio_core_trigger.h"
@@ -240,12 +241,13 @@ static void iio_trigger_put_irq(struct iio_trigger *trig, int irq)
 int iio_trigger_attach_poll_func(struct iio_trigger *trig,
 				 struct iio_poll_func *pf)
 {
+	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(pf->indio_dev);
 	bool notinuse =
 		bitmap_empty(trig->pool, CONFIG_IIO_CONSUMERS_PER_TRIGGER);
 	int ret = 0;
 
 	/* Prevent the module from being removed whilst attached to a trigger */
-	__module_get(pf->indio_dev->driver_module);
+	__module_get(iio_dev_opaque->driver_module);
 
 	/* Get irq number */
 	pf->irq = iio_trigger_get_irq(trig);
@@ -284,13 +286,14 @@ int iio_trigger_attach_poll_func(struct iio_trigger *trig,
 out_put_irq:
 	iio_trigger_put_irq(trig, pf->irq);
 out_put_module:
-	module_put(pf->indio_dev->driver_module);
+	module_put(iio_dev_opaque->driver_module);
 	return ret;
 }
 
 int iio_trigger_detach_poll_func(struct iio_trigger *trig,
 				 struct iio_poll_func *pf)
 {
+	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(pf->indio_dev);
 	bool no_other_users =
 		bitmap_weight(trig->pool, CONFIG_IIO_CONSUMERS_PER_TRIGGER) == 1;
 	int ret = 0;
@@ -304,7 +307,7 @@ int iio_trigger_detach_poll_func(struct iio_trigger *trig,
 		trig->attached_own_device = false;
 	iio_trigger_put_irq(trig, pf->irq);
 	free_irq(pf->irq, pf);
-	module_put(pf->indio_dev->driver_module);
+	module_put(iio_dev_opaque->driver_module);
 
 	return ret;
 }
diff --git a/include/linux/iio/iio-opaque.h b/include/linux/iio/iio-opaque.h
index f876e3aede2c..96dd265103d0 100644
--- a/include/linux/iio/iio-opaque.h
+++ b/include/linux/iio/iio-opaque.h
@@ -7,6 +7,7 @@
  * struct iio_dev_opaque - industrial I/O device opaque information
  * @indio_dev:			public industrial I/O device information
  * @id:			used to identify device internally
+ * @driver_module:		used to make it harder to undercut users
  * @event_interface:		event chrdevs associated with interrupt lines
  * @attached_buffers:		array of buffers statically attached by the driver
  * @attached_buffers_cnt:	number of buffers in the array of statically attached buffers
@@ -28,6 +29,7 @@
 struct iio_dev_opaque {
 	struct iio_dev			indio_dev;
 	int				id;
+	struct module			*driver_module;
 	struct iio_event_interface	*event_interface;
 	struct iio_buffer		**attached_buffers;
 	unsigned int			attached_buffers_cnt;
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index 569861d5887a..9e8e1358a032 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -488,7 +488,6 @@ struct iio_buffer_setup_ops {
 
 /**
  * struct iio_dev - industrial I/O device
- * @driver_module:	[INTERN] used to make it harder to undercut users
  * @modes:		[DRIVER] operating modes supported by device
  * @currentmode:	[DRIVER] current operating mode
  * @dev:		[DRIVER] device structure, should be assigned a parent
@@ -522,8 +521,6 @@ struct iio_buffer_setup_ops {
  *			**MUST** be accessed **ONLY** via iio_priv() helper
  */
 struct iio_dev {
-	struct module			*driver_module;
-
 	int				modes;
 	int				currentmode;
 	struct device			dev;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 4/9] iio: core: move @trig_readonly from struct iio_dev to struct iio_dev_opaque
  2021-04-26 17:49 [PATCH 0/9] iio: Move more things from iio_dev to iio_dev_opaque Jonathan Cameron
                   ` (2 preceding siblings ...)
  2021-04-26 17:49 ` [PATCH 3/9] iio: core: move @driver_module from struct iio_dev to struct iio_dev_opaque Jonathan Cameron
@ 2021-04-26 17:49 ` Jonathan Cameron
  2021-04-27  8:03   ` Alexandru Ardelean
  2021-04-26 17:49 ` [PATCH 5/9] iio: core: move @scan_index_timestamp " Jonathan Cameron
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 27+ messages in thread
From: Jonathan Cameron @ 2021-04-26 17:49 UTC (permalink / raw)
  To: linux-iio; +Cc: Alexandru Ardelean, Jonathan Cameron

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

This is only set via the iio_trig_set_immutable() call and later used
by the IIO core so there is no benefit in drivers being able to access
it.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 drivers/iio/industrialio-trigger.c | 10 +++++++---
 include/linux/iio/iio-opaque.h     |  2 ++
 include/linux/iio/iio.h            |  2 --
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
index b489eeeb0004..b23caa2f2aa1 100644
--- a/drivers/iio/industrialio-trigger.c
+++ b/drivers/iio/industrialio-trigger.c
@@ -117,14 +117,17 @@ EXPORT_SYMBOL(iio_trigger_unregister);
 
 int iio_trigger_set_immutable(struct iio_dev *indio_dev, struct iio_trigger *trig)
 {
+	struct iio_dev_opaque *iio_dev_opaque;
+
 	if (!indio_dev || !trig)
 		return -EINVAL;
 
+	iio_dev_opaque = to_iio_dev_opaque(indio_dev);
 	mutex_lock(&indio_dev->mlock);
-	WARN_ON(indio_dev->trig_readonly);
+	WARN_ON(iio_dev_opaque->trig_readonly);
 
 	indio_dev->trig = iio_trigger_get(trig);
-	indio_dev->trig_readonly = true;
+	iio_dev_opaque->trig_readonly = true;
 	mutex_unlock(&indio_dev->mlock);
 
 	return 0;
@@ -402,6 +405,7 @@ static ssize_t iio_trigger_write_current(struct device *dev,
 					 size_t len)
 {
 	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
 	struct iio_trigger *oldtrig = indio_dev->trig;
 	struct iio_trigger *trig;
 	int ret;
@@ -411,7 +415,7 @@ static ssize_t iio_trigger_write_current(struct device *dev,
 		mutex_unlock(&indio_dev->mlock);
 		return -EBUSY;
 	}
-	if (indio_dev->trig_readonly) {
+	if (iio_dev_opaque->trig_readonly) {
 		mutex_unlock(&indio_dev->mlock);
 		return -EPERM;
 	}
diff --git a/include/linux/iio/iio-opaque.h b/include/linux/iio/iio-opaque.h
index 96dd265103d0..10aa97239117 100644
--- a/include/linux/iio/iio-opaque.h
+++ b/include/linux/iio/iio-opaque.h
@@ -8,6 +8,7 @@
  * @indio_dev:			public industrial I/O device information
  * @id:			used to identify device internally
  * @driver_module:		used to make it harder to undercut users
+ * @trig_readonly:		mark the current trigger immutable
  * @event_interface:		event chrdevs associated with interrupt lines
  * @attached_buffers:		array of buffers statically attached by the driver
  * @attached_buffers_cnt:	number of buffers in the array of statically attached buffers
@@ -30,6 +31,7 @@ struct iio_dev_opaque {
 	struct iio_dev			indio_dev;
 	int				id;
 	struct module			*driver_module;
+	bool				trig_readonly;
 	struct iio_event_interface	*event_interface;
 	struct iio_buffer		**attached_buffers;
 	unsigned int			attached_buffers_cnt;
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index 9e8e1358a032..672f141f74c5 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -503,7 +503,6 @@ struct iio_buffer_setup_ops {
  * @scan_timestamp:	[INTERN] set if any buffers have requested timestamp
  * @scan_index_timestamp:[INTERN] cache of the index to the timestamp
  * @trig:		[INTERN] current device trigger (buffer modes)
- * @trig_readonly:	[INTERN] mark the current trigger immutable
  * @pollfunc:		[DRIVER] function run on trigger being received
  * @pollfunc_event:	[DRIVER] function run on events trigger being received
  * @channels:		[DRIVER] channel specification structure table
@@ -535,7 +534,6 @@ struct iio_dev {
 	bool				scan_timestamp;
 	unsigned			scan_index_timestamp;
 	struct iio_trigger		*trig;
-	bool				trig_readonly;
 	struct iio_poll_func		*pollfunc;
 	struct iio_poll_func		*pollfunc_event;
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 5/9] iio: core: move @scan_index_timestamp to struct iio_dev_opaque
  2021-04-26 17:49 [PATCH 0/9] iio: Move more things from iio_dev to iio_dev_opaque Jonathan Cameron
                   ` (3 preceding siblings ...)
  2021-04-26 17:49 ` [PATCH 4/9] iio: core: move @trig_readonly " Jonathan Cameron
@ 2021-04-26 17:49 ` Jonathan Cameron
  2021-04-27  8:03   ` Alexandru Ardelean
  2021-04-26 17:49 ` [PATCH 6/9] iio: core: move @info_exist_lock " Jonathan Cameron
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 27+ messages in thread
From: Jonathan Cameron @ 2021-04-26 17:49 UTC (permalink / raw)
  To: linux-iio; +Cc: Alexandru Ardelean, Jonathan Cameron

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

No reason for this cached value to be exposed to drivers so move it
to the opaque structure.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 drivers/iio/industrialio-buffer.c | 7 +++++--
 include/linux/iio/iio-opaque.h    | 4 ++++
 include/linux/iio/iio.h           | 2 --
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index 9a8e16c7e9af..9ecb3c58d94c 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -601,8 +601,10 @@ static unsigned int iio_storage_bytes_for_si(struct iio_dev *indio_dev,
 
 static unsigned int iio_storage_bytes_for_timestamp(struct iio_dev *indio_dev)
 {
+	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
+
 	return iio_storage_bytes_for_si(indio_dev,
-					indio_dev->scan_index_timestamp);
+					iio_dev_opaque->scan_index_timestamp);
 }
 
 static int iio_compute_scan_bytes(struct iio_dev *indio_dev,
@@ -1469,6 +1471,7 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer,
 					     struct iio_dev *indio_dev,
 					     int index)
 {
+	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
 	struct iio_dev_attr *p;
 	struct attribute **attr;
 	int ret, i, attrn, scan_el_attrcount, buffer_attrcount;
@@ -1495,7 +1498,7 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer,
 				goto error_cleanup_dynamic;
 			scan_el_attrcount += ret;
 			if (channels[i].type == IIO_TIMESTAMP)
-				indio_dev->scan_index_timestamp =
+				iio_dev_opaque->scan_index_timestamp =
 					channels[i].scan_index;
 		}
 		if (indio_dev->masklength && buffer->scan_mask == NULL) {
diff --git a/include/linux/iio/iio-opaque.h b/include/linux/iio/iio-opaque.h
index 10aa97239117..02038fb2d291 100644
--- a/include/linux/iio/iio-opaque.h
+++ b/include/linux/iio/iio-opaque.h
@@ -22,6 +22,7 @@
  * @groupcounter:		index of next attribute group
  * @legacy_scan_el_group:	attribute group for legacy scan elements attribute group
  * @legacy_buffer_group:	attribute group for legacy buffer attributes group
+ * @scan_index_timestamp:	cache of the index to the timestamp
  * @debugfs_dentry:		device specific debugfs dentry
  * @cached_reg_addr:		cached register address for debugfs reads
  * @read_buf:			read buffer to be used for the initial reg read
@@ -44,6 +45,9 @@ struct iio_dev_opaque {
 	int				groupcounter;
 	struct attribute_group		legacy_scan_el_group;
 	struct attribute_group		legacy_buffer_group;
+
+	unsigned int			scan_index_timestamp;
+
 #if defined(CONFIG_DEBUG_FS)
 	struct dentry			*debugfs_dentry;
 	unsigned			cached_reg_addr;
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index 672f141f74c5..cbc9e9ece0a6 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -501,7 +501,6 @@ struct iio_buffer_setup_ops {
  *			channels
  * @active_scan_mask:	[INTERN] union of all scan masks requested by buffers
  * @scan_timestamp:	[INTERN] set if any buffers have requested timestamp
- * @scan_index_timestamp:[INTERN] cache of the index to the timestamp
  * @trig:		[INTERN] current device trigger (buffer modes)
  * @pollfunc:		[DRIVER] function run on trigger being received
  * @pollfunc_event:	[DRIVER] function run on events trigger being received
@@ -532,7 +531,6 @@ struct iio_dev {
 	unsigned			masklength;
 	const unsigned long		*active_scan_mask;
 	bool				scan_timestamp;
-	unsigned			scan_index_timestamp;
 	struct iio_trigger		*trig;
 	struct iio_poll_func		*pollfunc;
 	struct iio_poll_func		*pollfunc_event;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 6/9] iio: core: move @info_exist_lock to struct iio_dev_opaque
  2021-04-26 17:49 [PATCH 0/9] iio: Move more things from iio_dev to iio_dev_opaque Jonathan Cameron
                   ` (4 preceding siblings ...)
  2021-04-26 17:49 ` [PATCH 5/9] iio: core: move @scan_index_timestamp " Jonathan Cameron
@ 2021-04-26 17:49 ` Jonathan Cameron
  2021-04-27  8:04   ` Alexandru Ardelean
  2021-04-26 17:49 ` [PATCH 7/9] iio: core: move @chrdev from struct iio_dev " Jonathan Cameron
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 27+ messages in thread
From: Jonathan Cameron @ 2021-04-26 17:49 UTC (permalink / raw)
  To: linux-iio; +Cc: Alexandru Ardelean, Jonathan Cameron

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

This lock is only of interest to the IIO core, so make it only
visible there.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 drivers/iio/industrialio-buffer.c |  5 ++--
 drivers/iio/industrialio-core.c   | 10 +++----
 drivers/iio/inkern.c              | 46 +++++++++++++++++++------------
 include/linux/iio/iio-opaque.h    |  2 ++
 include/linux/iio/iio.h           |  2 --
 5 files changed, 38 insertions(+), 27 deletions(-)

diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index 9ecb3c58d94c..10923b40c76d 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -1150,12 +1150,13 @@ int iio_update_buffers(struct iio_dev *indio_dev,
 		       struct iio_buffer *insert_buffer,
 		       struct iio_buffer *remove_buffer)
 {
+	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
 	int ret;
 
 	if (insert_buffer == remove_buffer)
 		return 0;
 
-	mutex_lock(&indio_dev->info_exist_lock);
+	mutex_lock(&iio_dev_opaque->info_exist_lock);
 	mutex_lock(&indio_dev->mlock);
 
 	if (insert_buffer && iio_buffer_is_active(insert_buffer))
@@ -1178,7 +1179,7 @@ int iio_update_buffers(struct iio_dev *indio_dev,
 
 out_unlock:
 	mutex_unlock(&indio_dev->mlock);
-	mutex_unlock(&indio_dev->info_exist_lock);
+	mutex_unlock(&iio_dev_opaque->info_exist_lock);
 
 	return ret;
 }
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 8c38f1f6e075..f3b38d69b7e1 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -1642,7 +1642,7 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)
 	device_initialize(&indio_dev->dev);
 	iio_device_set_drvdata(indio_dev, (void *)indio_dev);
 	mutex_init(&indio_dev->mlock);
-	mutex_init(&indio_dev->info_exist_lock);
+	mutex_init(&iio_dev_opaque->info_exist_lock);
 	INIT_LIST_HEAD(&iio_dev_opaque->channel_attr_list);
 
 	iio_dev_opaque->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL);
@@ -1779,7 +1779,7 @@ static long iio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 	struct iio_ioctl_handler *h;
 	int ret = -ENODEV;
 
-	mutex_lock(&indio_dev->info_exist_lock);
+	mutex_lock(&iio_dev_opaque->info_exist_lock);
 
 	/**
 	 * The NULL check here is required to prevent crashing when a device
@@ -1800,7 +1800,7 @@ static long iio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 		ret = -EINVAL;
 
 out_unlock:
-	mutex_unlock(&indio_dev->info_exist_lock);
+	mutex_unlock(&iio_dev_opaque->info_exist_lock);
 
 	return ret;
 }
@@ -1942,7 +1942,7 @@ void iio_device_unregister(struct iio_dev *indio_dev)
 
 	cdev_device_del(&indio_dev->chrdev, &indio_dev->dev);
 
-	mutex_lock(&indio_dev->info_exist_lock);
+	mutex_lock(&iio_dev_opaque->info_exist_lock);
 
 	iio_device_unregister_debugfs(indio_dev);
 
@@ -1956,7 +1956,7 @@ void iio_device_unregister(struct iio_dev *indio_dev)
 	iio_device_wakeup_eventset(indio_dev);
 	iio_buffer_wakeup_poll(indio_dev);
 
-	mutex_unlock(&indio_dev->info_exist_lock);
+	mutex_unlock(&iio_dev_opaque->info_exist_lock);
 
 	iio_buffers_free_sysfs_and_mask(indio_dev);
 }
diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
index 5aa740cea661..391a3380a1d1 100644
--- a/drivers/iio/inkern.c
+++ b/drivers/iio/inkern.c
@@ -10,6 +10,7 @@
 #include <linux/of.h>
 
 #include <linux/iio/iio.h>
+#include <linux/iio/iio-opaque.h>
 #include "iio_core.h"
 #include <linux/iio/machine.h>
 #include <linux/iio/driver.h>
@@ -538,9 +539,10 @@ static int iio_channel_read(struct iio_channel *chan, int *val, int *val2,
 
 int iio_read_channel_raw(struct iio_channel *chan, int *val)
 {
+	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
 	int ret;
 
-	mutex_lock(&chan->indio_dev->info_exist_lock);
+	mutex_lock(&iio_dev_opaque->info_exist_lock);
 	if (chan->indio_dev->info == NULL) {
 		ret = -ENODEV;
 		goto err_unlock;
@@ -548,7 +550,7 @@ int iio_read_channel_raw(struct iio_channel *chan, int *val)
 
 	ret = iio_channel_read(chan, val, NULL, IIO_CHAN_INFO_RAW);
 err_unlock:
-	mutex_unlock(&chan->indio_dev->info_exist_lock);
+	mutex_unlock(&iio_dev_opaque->info_exist_lock);
 
 	return ret;
 }
@@ -556,9 +558,10 @@ EXPORT_SYMBOL_GPL(iio_read_channel_raw);
 
 int iio_read_channel_average_raw(struct iio_channel *chan, int *val)
 {
+	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
 	int ret;
 
-	mutex_lock(&chan->indio_dev->info_exist_lock);
+	mutex_lock(&iio_dev_opaque->info_exist_lock);
 	if (chan->indio_dev->info == NULL) {
 		ret = -ENODEV;
 		goto err_unlock;
@@ -566,7 +569,7 @@ int iio_read_channel_average_raw(struct iio_channel *chan, int *val)
 
 	ret = iio_channel_read(chan, val, NULL, IIO_CHAN_INFO_AVERAGE_RAW);
 err_unlock:
-	mutex_unlock(&chan->indio_dev->info_exist_lock);
+	mutex_unlock(&iio_dev_opaque->info_exist_lock);
 
 	return ret;
 }
@@ -631,9 +634,10 @@ static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan,
 int iio_convert_raw_to_processed(struct iio_channel *chan, int raw,
 	int *processed, unsigned int scale)
 {
+	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
 	int ret;
 
-	mutex_lock(&chan->indio_dev->info_exist_lock);
+	mutex_lock(&iio_dev_opaque->info_exist_lock);
 	if (chan->indio_dev->info == NULL) {
 		ret = -ENODEV;
 		goto err_unlock;
@@ -642,7 +646,7 @@ int iio_convert_raw_to_processed(struct iio_channel *chan, int raw,
 	ret = iio_convert_raw_to_processed_unlocked(chan, raw, processed,
 							scale);
 err_unlock:
-	mutex_unlock(&chan->indio_dev->info_exist_lock);
+	mutex_unlock(&iio_dev_opaque->info_exist_lock);
 
 	return ret;
 }
@@ -651,9 +655,10 @@ EXPORT_SYMBOL_GPL(iio_convert_raw_to_processed);
 int iio_read_channel_attribute(struct iio_channel *chan, int *val, int *val2,
 			       enum iio_chan_info_enum attribute)
 {
+	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
 	int ret;
 
-	mutex_lock(&chan->indio_dev->info_exist_lock);
+	mutex_lock(&iio_dev_opaque->info_exist_lock);
 	if (chan->indio_dev->info == NULL) {
 		ret = -ENODEV;
 		goto err_unlock;
@@ -661,7 +666,7 @@ int iio_read_channel_attribute(struct iio_channel *chan, int *val, int *val2,
 
 	ret = iio_channel_read(chan, val, val2, attribute);
 err_unlock:
-	mutex_unlock(&chan->indio_dev->info_exist_lock);
+	mutex_unlock(&iio_dev_opaque->info_exist_lock);
 
 	return ret;
 }
@@ -676,9 +681,10 @@ EXPORT_SYMBOL_GPL(iio_read_channel_offset);
 int iio_read_channel_processed_scale(struct iio_channel *chan, int *val,
 				     unsigned int scale)
 {
+	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
 	int ret;
 
-	mutex_lock(&chan->indio_dev->info_exist_lock);
+	mutex_lock(&iio_dev_opaque->info_exist_lock);
 	if (chan->indio_dev->info == NULL) {
 		ret = -ENODEV;
 		goto err_unlock;
@@ -699,7 +705,7 @@ int iio_read_channel_processed_scale(struct iio_channel *chan, int *val,
 	}
 
 err_unlock:
-	mutex_unlock(&chan->indio_dev->info_exist_lock);
+	mutex_unlock(&iio_dev_opaque->info_exist_lock);
 
 	return ret;
 }
@@ -733,9 +739,10 @@ int iio_read_avail_channel_attribute(struct iio_channel *chan,
 				     const int **vals, int *type, int *length,
 				     enum iio_chan_info_enum attribute)
 {
+	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
 	int ret;
 
-	mutex_lock(&chan->indio_dev->info_exist_lock);
+	mutex_lock(&iio_dev_opaque->info_exist_lock);
 	if (!chan->indio_dev->info) {
 		ret = -ENODEV;
 		goto err_unlock;
@@ -743,7 +750,7 @@ int iio_read_avail_channel_attribute(struct iio_channel *chan,
 
 	ret = iio_channel_read_avail(chan, vals, type, length, attribute);
 err_unlock:
-	mutex_unlock(&chan->indio_dev->info_exist_lock);
+	mutex_unlock(&iio_dev_opaque->info_exist_lock);
 
 	return ret;
 }
@@ -815,10 +822,11 @@ static int iio_channel_read_max(struct iio_channel *chan,
 
 int iio_read_max_channel_raw(struct iio_channel *chan, int *val)
 {
+	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
 	int ret;
 	int type;
 
-	mutex_lock(&chan->indio_dev->info_exist_lock);
+	mutex_lock(&iio_dev_opaque->info_exist_lock);
 	if (!chan->indio_dev->info) {
 		ret = -ENODEV;
 		goto err_unlock;
@@ -826,7 +834,7 @@ int iio_read_max_channel_raw(struct iio_channel *chan, int *val)
 
 	ret = iio_channel_read_max(chan, val, NULL, &type, IIO_CHAN_INFO_RAW);
 err_unlock:
-	mutex_unlock(&chan->indio_dev->info_exist_lock);
+	mutex_unlock(&iio_dev_opaque->info_exist_lock);
 
 	return ret;
 }
@@ -834,10 +842,11 @@ EXPORT_SYMBOL_GPL(iio_read_max_channel_raw);
 
 int iio_get_channel_type(struct iio_channel *chan, enum iio_chan_type *type)
 {
+	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
 	int ret = 0;
 	/* Need to verify underlying driver has not gone away */
 
-	mutex_lock(&chan->indio_dev->info_exist_lock);
+	mutex_lock(&iio_dev_opaque->info_exist_lock);
 	if (chan->indio_dev->info == NULL) {
 		ret = -ENODEV;
 		goto err_unlock;
@@ -845,7 +854,7 @@ int iio_get_channel_type(struct iio_channel *chan, enum iio_chan_type *type)
 
 	*type = chan->channel->type;
 err_unlock:
-	mutex_unlock(&chan->indio_dev->info_exist_lock);
+	mutex_unlock(&iio_dev_opaque->info_exist_lock);
 
 	return ret;
 }
@@ -861,9 +870,10 @@ static int iio_channel_write(struct iio_channel *chan, int val, int val2,
 int iio_write_channel_attribute(struct iio_channel *chan, int val, int val2,
 				enum iio_chan_info_enum attribute)
 {
+	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
 	int ret;
 
-	mutex_lock(&chan->indio_dev->info_exist_lock);
+	mutex_lock(&iio_dev_opaque->info_exist_lock);
 	if (chan->indio_dev->info == NULL) {
 		ret = -ENODEV;
 		goto err_unlock;
@@ -871,7 +881,7 @@ int iio_write_channel_attribute(struct iio_channel *chan, int val, int val2,
 
 	ret = iio_channel_write(chan, val, val2, attribute);
 err_unlock:
-	mutex_unlock(&chan->indio_dev->info_exist_lock);
+	mutex_unlock(&iio_dev_opaque->info_exist_lock);
 
 	return ret;
 }
diff --git a/include/linux/iio/iio-opaque.h b/include/linux/iio/iio-opaque.h
index 02038fb2d291..538b4b5ef1a9 100644
--- a/include/linux/iio/iio-opaque.h
+++ b/include/linux/iio/iio-opaque.h
@@ -8,6 +8,7 @@
  * @indio_dev:			public industrial I/O device information
  * @id:			used to identify device internally
  * @driver_module:		used to make it harder to undercut users
+ * @info_exist_lock:		lock to prevent use during removal
  * @trig_readonly:		mark the current trigger immutable
  * @event_interface:		event chrdevs associated with interrupt lines
  * @attached_buffers:		array of buffers statically attached by the driver
@@ -32,6 +33,7 @@ struct iio_dev_opaque {
 	struct iio_dev			indio_dev;
 	int				id;
 	struct module			*driver_module;
+	struct mutex			info_exist_lock;
 	bool				trig_readonly;
 	struct iio_event_interface	*event_interface;
 	struct iio_buffer		**attached_buffers;
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index cbc9e9ece0a6..a12bbd8b1e74 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -510,7 +510,6 @@ struct iio_buffer_setup_ops {
  * @label:              [DRIVER] unique name to identify which device this is
  * @info:		[DRIVER] callbacks and constant info from driver
  * @clock_id:		[INTERN] timestamping clock posix identifier
- * @info_exist_lock:	[INTERN] lock to prevent use during removal
  * @setup_ops:		[DRIVER] callbacks to call before and after buffer
  *			enable/disable
  * @chrdev:		[INTERN] associated character device
@@ -542,7 +541,6 @@ struct iio_dev {
 	const char			*label;
 	const struct iio_info		*info;
 	clockid_t			clock_id;
-	struct mutex			info_exist_lock;
 	const struct iio_buffer_setup_ops	*setup_ops;
 	struct cdev			chrdev;
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 7/9] iio: core: move @chrdev from struct iio_dev to struct iio_dev_opaque
  2021-04-26 17:49 [PATCH 0/9] iio: Move more things from iio_dev to iio_dev_opaque Jonathan Cameron
                   ` (5 preceding siblings ...)
  2021-04-26 17:49 ` [PATCH 6/9] iio: core: move @info_exist_lock " Jonathan Cameron
@ 2021-04-26 17:49 ` Jonathan Cameron
  2021-04-27  8:06   ` Alexandru Ardelean
  2021-04-26 17:49 ` [PATCH 8/9] iio: core: move @flags " Jonathan Cameron
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 27+ messages in thread
From: Jonathan Cameron @ 2021-04-26 17:49 UTC (permalink / raw)
  To: linux-iio; +Cc: Alexandru Ardelean, Jonathan Cameron

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

No reason for this to be exposed to the drivers, so lets move it to the
opaque structure.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 drivers/iio/industrialio-core.c | 20 +++++++++++---------
 include/linux/iio/iio-opaque.h  |  2 ++
 include/linux/iio/iio.h         |  2 --
 3 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index f3b38d69b7e1..6fbe29f0b1de 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -1715,8 +1715,9 @@ EXPORT_SYMBOL_GPL(devm_iio_device_alloc);
  **/
 static int iio_chrdev_open(struct inode *inode, struct file *filp)
 {
-	struct iio_dev *indio_dev = container_of(inode->i_cdev,
-						struct iio_dev, chrdev);
+	struct iio_dev_opaque *iio_dev_opaque =
+		container_of(inode->i_cdev, struct iio_dev_opaque, chrdev);
+	struct iio_dev *indio_dev = &iio_dev_opaque->indio_dev;
 	struct iio_dev_buffer_pair *ib;
 
 	if (test_and_set_bit(IIO_BUSY_BIT_POS, &indio_dev->flags))
@@ -1749,8 +1750,9 @@ static int iio_chrdev_open(struct inode *inode, struct file *filp)
 static int iio_chrdev_release(struct inode *inode, struct file *filp)
 {
 	struct iio_dev_buffer_pair *ib = filp->private_data;
-	struct iio_dev *indio_dev = container_of(inode->i_cdev,
-						struct iio_dev, chrdev);
+	struct iio_dev_opaque *iio_dev_opaque =
+		container_of(inode->i_cdev, struct iio_dev_opaque, chrdev);
+	struct iio_dev *indio_dev = &iio_dev_opaque->indio_dev;
 	kfree(ib);
 	clear_bit(IIO_BUSY_BIT_POS, &indio_dev->flags);
 	iio_device_put(indio_dev);
@@ -1901,19 +1903,19 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod)
 		indio_dev->setup_ops = &noop_ring_setup_ops;
 
 	if (iio_dev_opaque->attached_buffers_cnt)
-		cdev_init(&indio_dev->chrdev, &iio_buffer_fileops);
+		cdev_init(&iio_dev_opaque->chrdev, &iio_buffer_fileops);
 	else if (iio_dev_opaque->event_interface)
-		cdev_init(&indio_dev->chrdev, &iio_event_fileops);
+		cdev_init(&iio_dev_opaque->chrdev, &iio_event_fileops);
 
 	if (iio_dev_opaque->attached_buffers_cnt || iio_dev_opaque->event_interface) {
 		indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), iio_dev_opaque->id);
-		indio_dev->chrdev.owner = this_mod;
+		iio_dev_opaque->chrdev.owner = this_mod;
 	}
 
 	/* assign device groups now; they should be all registered now */
 	indio_dev->dev.groups = iio_dev_opaque->groups;
 
-	ret = cdev_device_add(&indio_dev->chrdev, &indio_dev->dev);
+	ret = cdev_device_add(&iio_dev_opaque->chrdev, &indio_dev->dev);
 	if (ret < 0)
 		goto error_unreg_eventset;
 
@@ -1940,7 +1942,7 @@ void iio_device_unregister(struct iio_dev *indio_dev)
 	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
 	struct iio_ioctl_handler *h, *t;
 
-	cdev_device_del(&indio_dev->chrdev, &indio_dev->dev);
+	cdev_device_del(&iio_dev_opaque->chrdev, &indio_dev->dev);
 
 	mutex_lock(&iio_dev_opaque->info_exist_lock);
 
diff --git a/include/linux/iio/iio-opaque.h b/include/linux/iio/iio-opaque.h
index 538b4b5ef1a9..2f8ef5d15a66 100644
--- a/include/linux/iio/iio-opaque.h
+++ b/include/linux/iio/iio-opaque.h
@@ -24,6 +24,7 @@
  * @legacy_scan_el_group:	attribute group for legacy scan elements attribute group
  * @legacy_buffer_group:	attribute group for legacy buffer attributes group
  * @scan_index_timestamp:	cache of the index to the timestamp
+ * @chrdev:			associated character device
  * @debugfs_dentry:		device specific debugfs dentry
  * @cached_reg_addr:		cached register address for debugfs reads
  * @read_buf:			read buffer to be used for the initial reg read
@@ -49,6 +50,7 @@ struct iio_dev_opaque {
 	struct attribute_group		legacy_buffer_group;
 
 	unsigned int			scan_index_timestamp;
+	struct cdev			chrdev;
 
 #if defined(CONFIG_DEBUG_FS)
 	struct dentry			*debugfs_dentry;
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index a12bbd8b1e74..586e2dc4fbf3 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -512,7 +512,6 @@ struct iio_buffer_setup_ops {
  * @clock_id:		[INTERN] timestamping clock posix identifier
  * @setup_ops:		[DRIVER] callbacks to call before and after buffer
  *			enable/disable
- * @chrdev:		[INTERN] associated character device
  * @flags:		[INTERN] file ops related flags including busy flag.
  * @priv:		[DRIVER] reference to driver's private information
  *			**MUST** be accessed **ONLY** via iio_priv() helper
@@ -542,7 +541,6 @@ struct iio_dev {
 	const struct iio_info		*info;
 	clockid_t			clock_id;
 	const struct iio_buffer_setup_ops	*setup_ops;
-	struct cdev			chrdev;
 
 	unsigned long			flags;
 	void				*priv;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 8/9] iio: core: move @flags from struct iio_dev to struct iio_dev_opaque
  2021-04-26 17:49 [PATCH 0/9] iio: Move more things from iio_dev to iio_dev_opaque Jonathan Cameron
                   ` (6 preceding siblings ...)
  2021-04-26 17:49 ` [PATCH 7/9] iio: core: move @chrdev from struct iio_dev " Jonathan Cameron
@ 2021-04-26 17:49 ` Jonathan Cameron
  2021-04-27  8:07   ` Alexandru Ardelean
  2021-04-26 17:49 ` [PATCH 9/9] iio: core: move @clock_id " Jonathan Cameron
  2021-04-27  8:08 ` [PATCH 0/9] iio: Move more things from iio_dev to iio_dev_opaque Alexandru Ardelean
  9 siblings, 1 reply; 27+ messages in thread
From: Jonathan Cameron @ 2021-04-26 17:49 UTC (permalink / raw)
  To: linux-iio; +Cc: Alexandru Ardelean, Jonathan Cameron

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

No reason any driver should ever need access to this field, so hide it.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 drivers/iio/industrialio-core.c | 6 +++---
 include/linux/iio/iio-opaque.h  | 2 ++
 include/linux/iio/iio.h         | 2 --
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 6fbe29f0b1de..4a4c02fea152 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -1720,7 +1720,7 @@ static int iio_chrdev_open(struct inode *inode, struct file *filp)
 	struct iio_dev *indio_dev = &iio_dev_opaque->indio_dev;
 	struct iio_dev_buffer_pair *ib;
 
-	if (test_and_set_bit(IIO_BUSY_BIT_POS, &indio_dev->flags))
+	if (test_and_set_bit(IIO_BUSY_BIT_POS, &iio_dev_opaque->flags))
 		return -EBUSY;
 
 	iio_device_get(indio_dev);
@@ -1728,7 +1728,7 @@ static int iio_chrdev_open(struct inode *inode, struct file *filp)
 	ib = kmalloc(sizeof(*ib), GFP_KERNEL);
 	if (!ib) {
 		iio_device_put(indio_dev);
-		clear_bit(IIO_BUSY_BIT_POS, &indio_dev->flags);
+		clear_bit(IIO_BUSY_BIT_POS, &iio_dev_opaque->flags);
 		return -ENOMEM;
 	}
 
@@ -1754,7 +1754,7 @@ static int iio_chrdev_release(struct inode *inode, struct file *filp)
 		container_of(inode->i_cdev, struct iio_dev_opaque, chrdev);
 	struct iio_dev *indio_dev = &iio_dev_opaque->indio_dev;
 	kfree(ib);
-	clear_bit(IIO_BUSY_BIT_POS, &indio_dev->flags);
+	clear_bit(IIO_BUSY_BIT_POS, &iio_dev_opaque->flags);
 	iio_device_put(indio_dev);
 
 	return 0;
diff --git a/include/linux/iio/iio-opaque.h b/include/linux/iio/iio-opaque.h
index 2f8ef5d15a66..d7c3036861ac 100644
--- a/include/linux/iio/iio-opaque.h
+++ b/include/linux/iio/iio-opaque.h
@@ -25,6 +25,7 @@
  * @legacy_buffer_group:	attribute group for legacy buffer attributes group
  * @scan_index_timestamp:	cache of the index to the timestamp
  * @chrdev:			associated character device
+ * @flags:			file ops related flags including busy flag.
  * @debugfs_dentry:		device specific debugfs dentry
  * @cached_reg_addr:		cached register address for debugfs reads
  * @read_buf:			read buffer to be used for the initial reg read
@@ -51,6 +52,7 @@ struct iio_dev_opaque {
 
 	unsigned int			scan_index_timestamp;
 	struct cdev			chrdev;
+	unsigned long			flags;
 
 #if defined(CONFIG_DEBUG_FS)
 	struct dentry			*debugfs_dentry;
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index 586e2dc4fbf3..ed0537015eee 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -512,7 +512,6 @@ struct iio_buffer_setup_ops {
  * @clock_id:		[INTERN] timestamping clock posix identifier
  * @setup_ops:		[DRIVER] callbacks to call before and after buffer
  *			enable/disable
- * @flags:		[INTERN] file ops related flags including busy flag.
  * @priv:		[DRIVER] reference to driver's private information
  *			**MUST** be accessed **ONLY** via iio_priv() helper
  */
@@ -542,7 +541,6 @@ struct iio_dev {
 	clockid_t			clock_id;
 	const struct iio_buffer_setup_ops	*setup_ops;
 
-	unsigned long			flags;
 	void				*priv;
 };
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 9/9] iio: core: move @clock_id from struct iio_dev to struct iio_dev_opaque
  2021-04-26 17:49 [PATCH 0/9] iio: Move more things from iio_dev to iio_dev_opaque Jonathan Cameron
                   ` (7 preceding siblings ...)
  2021-04-26 17:49 ` [PATCH 8/9] iio: core: move @flags " Jonathan Cameron
@ 2021-04-26 17:49 ` Jonathan Cameron
  2021-04-27  8:02   ` Alexandru Ardelean
  2021-04-27  8:08 ` [PATCH 0/9] iio: Move more things from iio_dev to iio_dev_opaque Alexandru Ardelean
  9 siblings, 1 reply; 27+ messages in thread
From: Jonathan Cameron @ 2021-04-26 17:49 UTC (permalink / raw)
  To: linux-iio; +Cc: Alexandru Ardelean, Jonathan Cameron

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

There is already an acessor function used to access it, making this
move straight forward.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 drivers/iio/industrialio-core.c | 14 +++++++++++++-
 include/linux/iio/iio-opaque.h  |  2 ++
 include/linux/iio/iio.h         | 12 +-----------
 3 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 4a4c02fea152..efb4cf91c9e4 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -271,13 +271,25 @@ int iio_device_set_clock(struct iio_dev *indio_dev, clockid_t clock_id)
 		mutex_unlock(&indio_dev->mlock);
 		return -EBUSY;
 	}
-	indio_dev->clock_id = clock_id;
+	iio_dev_opaque->clock_id = clock_id;
 	mutex_unlock(&indio_dev->mlock);
 
 	return 0;
 }
 EXPORT_SYMBOL(iio_device_set_clock);
 
+/**
+ * iio_device_get_clock() - Retrieve current timestamping clock for the device
+ * @indio_dev: IIO device structure containing the device
+ */
+clockid_t iio_device_get_clock(const struct iio_dev *indio_dev)
+{
+	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
+
+	return iio_dev_opaque->clock_id;
+}
+EXPORT_SYMBOL(iio_device_get_clock);
+
 /**
  * iio_get_time_ns() - utility function to get a time stamp for events etc
  * @indio_dev: device
diff --git a/include/linux/iio/iio-opaque.h b/include/linux/iio/iio-opaque.h
index d7c3036861ac..c9504e9da571 100644
--- a/include/linux/iio/iio-opaque.h
+++ b/include/linux/iio/iio-opaque.h
@@ -24,6 +24,7 @@
  * @legacy_scan_el_group:	attribute group for legacy scan elements attribute group
  * @legacy_buffer_group:	attribute group for legacy buffer attributes group
  * @scan_index_timestamp:	cache of the index to the timestamp
+ * @clock_id:			timestamping clock posix identifier
  * @chrdev:			associated character device
  * @flags:			file ops related flags including busy flag.
  * @debugfs_dentry:		device specific debugfs dentry
@@ -51,6 +52,7 @@ struct iio_dev_opaque {
 	struct attribute_group		legacy_buffer_group;
 
 	unsigned int			scan_index_timestamp;
+	clockid_t			clock_id;
 	struct cdev			chrdev;
 	unsigned long			flags;
 
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index ed0537015eee..5606a3f4c4cb 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -509,7 +509,6 @@ struct iio_buffer_setup_ops {
  * @name:		[DRIVER] name of the device.
  * @label:              [DRIVER] unique name to identify which device this is
  * @info:		[DRIVER] callbacks and constant info from driver
- * @clock_id:		[INTERN] timestamping clock posix identifier
  * @setup_ops:		[DRIVER] callbacks to call before and after buffer
  *			enable/disable
  * @priv:		[DRIVER] reference to driver's private information
@@ -538,7 +537,6 @@ struct iio_dev {
 	const char			*name;
 	const char			*label;
 	const struct iio_info		*info;
-	clockid_t			clock_id;
 	const struct iio_buffer_setup_ops	*setup_ops;
 
 	void				*priv;
@@ -589,15 +587,7 @@ static inline void iio_device_put(struct iio_dev *indio_dev)
 		put_device(&indio_dev->dev);
 }
 
-/**
- * iio_device_get_clock() - Retrieve current timestamping clock for the device
- * @indio_dev: IIO device structure containing the device
- */
-static inline clockid_t iio_device_get_clock(const struct iio_dev *indio_dev)
-{
-	return indio_dev->clock_id;
-}
-
+clockid_t iio_device_get_clock(const struct iio_dev *indio_dev);
 int iio_device_set_clock(struct iio_dev *indio_dev, clockid_t clock_id);
 
 /**
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/9] iio: core: move @id from struct iio_dev to struct iio_dev_opaque
  2021-04-26 17:49 ` [PATCH 1/9] iio: core: move @id from struct iio_dev to struct iio_dev_opaque Jonathan Cameron
@ 2021-04-27  7:44   ` Alexandru Ardelean
  2021-04-27 17:16     ` Jonathan Cameron
  2021-05-03 11:42   ` Jonathan Cameron
  1 sibling, 1 reply; 27+ messages in thread
From: Alexandru Ardelean @ 2021-04-27  7:44 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Jonathan Cameron

On Mon, Apr 26, 2021 at 8:50 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> Continuing from Alexandru Ardelean's introduction of the split between
> driver modifiable fields and those that should only be set by the core.
>
> This could have been done in two steps to make the actual move after
> introducing iio_device_id() but there seemed limited point to that
> given how mechanical the majority of the patch is.
>

The way I was thinking [initially] about moving this, is to somehow
try to unify/generalize the {devm_}iio_trigger_alloc() function.
It looks like the IIO device ID is needed only there.
Maybe there is a good solution for this; maybe if we just provide the
fmt string, and have a convention that the IIO device name and ID are
filled in.
Though that's tricky.

But this iio_device_id() getter is also a good approach for now.

Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>

> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  drivers/iio/accel/adxl372.c                   |  4 ++--
>  drivers/iio/accel/bma180.c                    |  2 +-
>  drivers/iio/accel/bmc150-accel-core.c         |  4 ++--
>  drivers/iio/accel/kxcjk-1013.c                |  4 ++--
>  drivers/iio/accel/mma8452.c                   |  2 +-
>  drivers/iio/accel/mxc4005.c                   |  2 +-
>  drivers/iio/accel/stk8312.c                   |  2 +-
>  drivers/iio/accel/stk8ba50.c                  |  2 +-
>  drivers/iio/adc/ad7606.c                      |  3 ++-
>  drivers/iio/adc/ad7766.c                      |  3 ++-
>  drivers/iio/adc/ad7768-1.c                    |  3 ++-
>  drivers/iio/adc/ad_sigma_delta.c              |  2 +-
>  drivers/iio/adc/at91_adc.c                    |  4 ++--
>  drivers/iio/adc/dln2-adc.c                    |  3 ++-
>  drivers/iio/adc/ina2xx-adc.c                  |  3 ++-
>  drivers/iio/adc/ti-ads131e08.c                |  2 +-
>  drivers/iio/adc/xilinx-xadc-core.c            |  2 +-
>  .../buffer/industrialio-triggered-buffer.c    |  2 +-
>  drivers/iio/chemical/atlas-sensor.c           |  2 +-
>  drivers/iio/chemical/ccs811.c                 |  2 +-
>  drivers/iio/chemical/scd30_core.c             |  3 ++-
>  .../common/hid-sensors/hid-sensor-trigger.c   |  2 +-
>  drivers/iio/gyro/adxrs290.c                   |  2 +-
>  drivers/iio/gyro/bmg160_core.c                |  4 ++--
>  drivers/iio/gyro/fxas21002c_core.c            |  2 +-
>  drivers/iio/gyro/itg3200_buffer.c             |  2 +-
>  drivers/iio/gyro/mpu3050-core.c               |  2 +-
>  drivers/iio/health/afe4403.c                  |  2 +-
>  drivers/iio/health/afe4404.c                  |  2 +-
>  drivers/iio/imu/adis_trigger.c                |  3 ++-
>  drivers/iio/imu/bmi160/bmi160_core.c          |  3 ++-
>  drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c |  2 +-
>  drivers/iio/imu/kmx61.c                       |  2 +-
>  drivers/iio/industrialio-core.c               | 24 +++++++++++++++----
>  drivers/iio/industrialio-triggered-event.c    |  2 +-
>  drivers/iio/light/acpi-als.c                  |  3 ++-
>  drivers/iio/light/rpr0521.c                   |  2 +-
>  drivers/iio/light/si1145.c                    |  2 +-
>  drivers/iio/light/vcnl4000.c                  |  3 ++-
>  drivers/iio/light/vcnl4035.c                  |  2 +-
>  drivers/iio/magnetometer/bmc150_magn.c        |  2 +-
>  drivers/iio/magnetometer/rm3100-core.c        |  2 +-
>  drivers/iio/potentiostat/lmp91000.c           |  3 ++-
>  drivers/iio/pressure/zpa2326.c                |  3 ++-
>  drivers/iio/proximity/as3935.c                |  3 ++-
>  drivers/iio/proximity/sx9310.c                |  2 +-
>  drivers/iio/proximity/sx9500.c                |  2 +-
>  include/linux/iio/iio-opaque.h                |  2 ++
>  include/linux/iio/iio.h                       |  4 ++--
>  49 files changed, 87 insertions(+), 58 deletions(-)
>
> diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c
> index 9c9a896a872a..fc9592407717 100644
> --- a/drivers/iio/accel/adxl372.c
> +++ b/drivers/iio/accel/adxl372.c
> @@ -1223,14 +1223,14 @@ int adxl372_probe(struct device *dev, struct regmap *regmap,
>                 st->dready_trig = devm_iio_trigger_alloc(dev,
>                                                          "%s-dev%d",
>                                                          indio_dev->name,
> -                                                        indio_dev->id);
> +                                                        iio_device_id(indio_dev));
>                 if (st->dready_trig == NULL)
>                         return -ENOMEM;
>
>                 st->peak_datardy_trig = devm_iio_trigger_alloc(dev,
>                                                                "%s-dev%d-peak",
>                                                                indio_dev->name,
> -                                                              indio_dev->id);
> +                                                              iio_device_id(indio_dev));
>                 if (!st->peak_datardy_trig)
>                         return -ENOMEM;
>
> diff --git a/drivers/iio/accel/bma180.c b/drivers/iio/accel/bma180.c
> index b8a7469cdae4..68d91a70de03 100644
> --- a/drivers/iio/accel/bma180.c
> +++ b/drivers/iio/accel/bma180.c
> @@ -1045,7 +1045,7 @@ static int bma180_probe(struct i2c_client *client,
>
>         if (client->irq > 0) {
>                 data->trig = iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name,
> -                       indio_dev->id);
> +                                              iio_device_id(indio_dev));
>                 if (!data->trig) {
>                         ret = -ENOMEM;
>                         goto err_chip_disable;
> diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
> index 04d85ce34e9f..62a164a7b852 100644
> --- a/drivers/iio/accel/bmc150-accel-core.c
> +++ b/drivers/iio/accel/bmc150-accel-core.c
> @@ -1470,9 +1470,9 @@ static int bmc150_accel_triggers_setup(struct iio_dev *indio_dev,
>                 struct bmc150_accel_trigger *t = &data->triggers[i];
>
>                 t->indio_trig = devm_iio_trigger_alloc(dev,
> -                                       bmc150_accel_triggers[i].name,
> +                                                      bmc150_accel_triggers[i].name,
>                                                        indio_dev->name,
> -                                                      indio_dev->id);
> +                                                      iio_device_id(indio_dev));
>                 if (!t->indio_trig) {
>                         ret = -ENOMEM;
>                         break;
> diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c
> index ff724bc17a45..283e6a3feffc 100644
> --- a/drivers/iio/accel/kxcjk-1013.c
> +++ b/drivers/iio/accel/kxcjk-1013.c
> @@ -1404,7 +1404,7 @@ static int kxcjk1013_probe(struct i2c_client *client,
>                 data->dready_trig = devm_iio_trigger_alloc(&client->dev,
>                                                            "%s-dev%d",
>                                                            indio_dev->name,
> -                                                          indio_dev->id);
> +                                                          iio_device_id(indio_dev));
>                 if (!data->dready_trig) {
>                         ret = -ENOMEM;
>                         goto err_poweroff;
> @@ -1413,7 +1413,7 @@ static int kxcjk1013_probe(struct i2c_client *client,
>                 data->motion_trig = devm_iio_trigger_alloc(&client->dev,
>                                                           "%s-any-motion-dev%d",
>                                                           indio_dev->name,
> -                                                         indio_dev->id);
> +                                                         iio_device_id(indio_dev));
>                 if (!data->motion_trig) {
>                         ret = -ENOMEM;
>                         goto err_poweroff;
> diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
> index 4d307dfb9169..464a6bfe6746 100644
> --- a/drivers/iio/accel/mma8452.c
> +++ b/drivers/iio/accel/mma8452.c
> @@ -1461,7 +1461,7 @@ static int mma8452_trigger_setup(struct iio_dev *indio_dev)
>
>         trig = devm_iio_trigger_alloc(&data->client->dev, "%s-dev%d",
>                                       indio_dev->name,
> -                                     indio_dev->id);
> +                                     iio_device_id(indio_dev));
>         if (!trig)
>                 return -ENOMEM;
>
> diff --git a/drivers/iio/accel/mxc4005.c b/drivers/iio/accel/mxc4005.c
> index fb3cbaa62bd8..98c7f5f59011 100644
> --- a/drivers/iio/accel/mxc4005.c
> +++ b/drivers/iio/accel/mxc4005.c
> @@ -433,7 +433,7 @@ static int mxc4005_probe(struct i2c_client *client,
>                 data->dready_trig = devm_iio_trigger_alloc(&client->dev,
>                                                            "%s-dev%d",
>                                                            indio_dev->name,
> -                                                          indio_dev->id);
> +                                                          iio_device_id(indio_dev));
>                 if (!data->dready_trig)
>                         return -ENOMEM;
>
> diff --git a/drivers/iio/accel/stk8312.c b/drivers/iio/accel/stk8312.c
> index 60aecfa9fd92..aeab108c457d 100644
> --- a/drivers/iio/accel/stk8312.c
> +++ b/drivers/iio/accel/stk8312.c
> @@ -552,7 +552,7 @@ static int stk8312_probe(struct i2c_client *client,
>                 data->dready_trig = devm_iio_trigger_alloc(&client->dev,
>                                                            "%s-dev%d",
>                                                            indio_dev->name,
> -                                                          indio_dev->id);
> +                                                          iio_device_id(indio_dev));
>                 if (!data->dready_trig) {
>                         ret = -ENOMEM;
>                         goto err_power_off;
> diff --git a/drivers/iio/accel/stk8ba50.c b/drivers/iio/accel/stk8ba50.c
> index 7cf9cb7e8666..3e7cf23be7e1 100644
> --- a/drivers/iio/accel/stk8ba50.c
> +++ b/drivers/iio/accel/stk8ba50.c
> @@ -448,7 +448,7 @@ static int stk8ba50_probe(struct i2c_client *client,
>                 data->dready_trig = devm_iio_trigger_alloc(&client->dev,
>                                                            "%s-dev%d",
>                                                            indio_dev->name,
> -                                                          indio_dev->id);
> +                                                          iio_device_id(indio_dev));
>                 if (!data->dready_trig) {
>                         ret = -ENOMEM;
>                         goto err_power_off;
> diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
> index 0af0bb4d5a7f..0a60ecc69d38 100644
> --- a/drivers/iio/adc/ad7606.c
> +++ b/drivers/iio/adc/ad7606.c
> @@ -663,7 +663,8 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
>         }
>
>         st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
> -                                         indio_dev->name, indio_dev->id);
> +                                         indio_dev->name,
> +                                         iio_device_id(indio_dev));
>         if (!st->trig)
>                 return -ENOMEM;
>
> diff --git a/drivers/iio/adc/ad7766.c b/drivers/iio/adc/ad7766.c
> index 1e41759f3ee5..236a455aaa18 100644
> --- a/drivers/iio/adc/ad7766.c
> +++ b/drivers/iio/adc/ad7766.c
> @@ -248,7 +248,8 @@ static int ad7766_probe(struct spi_device *spi)
>
>         if (spi->irq > 0) {
>                 ad7766->trig = devm_iio_trigger_alloc(&spi->dev, "%s-dev%d",
> -                       indio_dev->name, indio_dev->id);
> +                                                     indio_dev->name,
> +                                                     iio_device_id(indio_dev));
>                 if (!ad7766->trig)
>                         return -ENOMEM;
>
> diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c
> index c945f1349623..41752777e96c 100644
> --- a/drivers/iio/adc/ad7768-1.c
> +++ b/drivers/iio/adc/ad7768-1.c
> @@ -626,7 +626,8 @@ static int ad7768_probe(struct spi_device *spi)
>         }
>
>         st->trig = devm_iio_trigger_alloc(&spi->dev, "%s-dev%d",
> -                                         indio_dev->name, indio_dev->id);
> +                                         indio_dev->name,
> +                                         iio_device_id(indio_dev));
>         if (!st->trig)
>                 return -ENOMEM;
>
> diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
> index e777ec718973..69b979331ccd 100644
> --- a/drivers/iio/adc/ad_sigma_delta.c
> +++ b/drivers/iio/adc/ad_sigma_delta.c
> @@ -477,7 +477,7 @@ static int ad_sd_probe_trigger(struct iio_dev *indio_dev)
>
>         sigma_delta->trig = iio_trigger_alloc(&sigma_delta->spi->dev,
>                                               "%s-dev%d", indio_dev->name,
> -                                             indio_dev->id);
> +                                             iio_device_id(indio_dev));
>         if (sigma_delta->trig == NULL) {
>                 ret = -ENOMEM;
>                 goto error_ret;
> diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
> index 0b5f0c91d0d7..5a7d3a3a5fa8 100644
> --- a/drivers/iio/adc/at91_adc.c
> +++ b/drivers/iio/adc/at91_adc.c
> @@ -547,7 +547,7 @@ static int at91_adc_get_trigger_value_by_name(struct iio_dev *idev,
>                 char *name = kasprintf(GFP_KERNEL,
>                                 "%s-dev%d-%s",
>                                 idev->name,
> -                               idev->id,
> +                               iio_device_id(idev),
>                                 triggers[i].name);
>                 if (!name)
>                         return -ENOMEM;
> @@ -626,7 +626,7 @@ static struct iio_trigger *at91_adc_allocate_trigger(struct iio_dev *idev,
>         int ret;
>
>         trig = iio_trigger_alloc(idev->dev.parent, "%s-dev%d-%s", idev->name,
> -                                idev->id, trigger->name);
> +                                iio_device_id(idev), trigger->name);
>         if (trig == NULL)
>                 return NULL;
>
> diff --git a/drivers/iio/adc/dln2-adc.c b/drivers/iio/adc/dln2-adc.c
> index 0d53ef18e045..16407664182c 100644
> --- a/drivers/iio/adc/dln2-adc.c
> +++ b/drivers/iio/adc/dln2-adc.c
> @@ -649,7 +649,8 @@ static int dln2_adc_probe(struct platform_device *pdev)
>         indio_dev->setup_ops = &dln2_adc_buffer_setup_ops;
>
>         dln2->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
> -                                           indio_dev->name, indio_dev->id);
> +                                           indio_dev->name,
> +                                           iio_device_id(indio_dev));
>         if (!dln2->trig) {
>                 dev_err(dev, "failed to allocate trigger\n");
>                 return -ENOMEM;
> diff --git a/drivers/iio/adc/ina2xx-adc.c b/drivers/iio/adc/ina2xx-adc.c
> index 2ae54258b221..a4b2ff9e0dd5 100644
> --- a/drivers/iio/adc/ina2xx-adc.c
> +++ b/drivers/iio/adc/ina2xx-adc.c
> @@ -843,7 +843,8 @@ static int ina2xx_buffer_enable(struct iio_dev *indio_dev)
>                 chip->allow_async_readout);
>
>         task = kthread_create(ina2xx_capture_thread, (void *)indio_dev,
> -                             "%s:%d-%uus", indio_dev->name, indio_dev->id,
> +                             "%s:%d-%uus", indio_dev->name,
> +                             iio_device_id(indio_dev),
>                               sampling_us);
>         if (IS_ERR(task))
>                 return PTR_ERR(task);
> diff --git a/drivers/iio/adc/ti-ads131e08.c b/drivers/iio/adc/ti-ads131e08.c
> index 0060d5f0abb0..5dcf1e9294d7 100644
> --- a/drivers/iio/adc/ti-ads131e08.c
> +++ b/drivers/iio/adc/ti-ads131e08.c
> @@ -844,7 +844,7 @@ static int ads131e08_probe(struct spi_device *spi)
>         }
>
>         st->trig = devm_iio_trigger_alloc(&spi->dev, "%s-dev%d",
> -               indio_dev->name, indio_dev->id);
> +               indio_dev->name, iio_device_id(indio_dev));
>         if (!st->trig) {
>                 dev_err(&spi->dev, "failed to allocate IIO trigger\n");
>                 return -ENOMEM;
> diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c
> index 6914c1900ed0..198d2916266d 100644
> --- a/drivers/iio/adc/xilinx-xadc-core.c
> +++ b/drivers/iio/adc/xilinx-xadc-core.c
> @@ -743,7 +743,7 @@ static struct iio_trigger *xadc_alloc_trigger(struct iio_dev *indio_dev,
>         int ret;
>
>         trig = devm_iio_trigger_alloc(dev, "%s%d-%s", indio_dev->name,
> -                                     indio_dev->id, name);
> +                                     iio_device_id(indio_dev), name);
>         if (trig == NULL)
>                 return ERR_PTR(-ENOMEM);
>
> diff --git a/drivers/iio/buffer/industrialio-triggered-buffer.c b/drivers/iio/buffer/industrialio-triggered-buffer.c
> index ebb4520ac291..f77c4538141e 100644
> --- a/drivers/iio/buffer/industrialio-triggered-buffer.c
> +++ b/drivers/iio/buffer/industrialio-triggered-buffer.c
> @@ -56,7 +56,7 @@ int iio_triggered_buffer_setup_ext(struct iio_dev *indio_dev,
>                                                  indio_dev,
>                                                  "%s_consumer%d",
>                                                  indio_dev->name,
> -                                                indio_dev->id);
> +                                                iio_device_id(indio_dev));
>         if (indio_dev->pollfunc == NULL) {
>                 ret = -ENOMEM;
>                 goto error_kfifo_free;
> diff --git a/drivers/iio/chemical/atlas-sensor.c b/drivers/iio/chemical/atlas-sensor.c
> index 56ba6c82b501..d10f921b233a 100644
> --- a/drivers/iio/chemical/atlas-sensor.c
> +++ b/drivers/iio/chemical/atlas-sensor.c
> @@ -640,7 +640,7 @@ static int atlas_probe(struct i2c_client *client,
>         indio_dev->modes = INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE;
>
>         trig = devm_iio_trigger_alloc(&client->dev, "%s-dev%d",
> -                                     indio_dev->name, indio_dev->id);
> +                                     indio_dev->name, iio_device_id(indio_dev));
>
>         if (!trig)
>                 return -ENOMEM;
> diff --git a/drivers/iio/chemical/ccs811.c b/drivers/iio/chemical/ccs811.c
> index 886e96496dbf..847194fa1e46 100644
> --- a/drivers/iio/chemical/ccs811.c
> +++ b/drivers/iio/chemical/ccs811.c
> @@ -491,7 +491,7 @@ static int ccs811_probe(struct i2c_client *client,
>                 data->drdy_trig = devm_iio_trigger_alloc(&client->dev,
>                                                          "%s-dev%d",
>                                                          indio_dev->name,
> -                                                        indio_dev->id);
> +                                                        iio_device_id(indio_dev));
>                 if (!data->drdy_trig) {
>                         ret = -ENOMEM;
>                         goto err_poweroff;
> diff --git a/drivers/iio/chemical/scd30_core.c b/drivers/iio/chemical/scd30_core.c
> index d89f117dd0ef..9fe6bbe9ee04 100644
> --- a/drivers/iio/chemical/scd30_core.c
> +++ b/drivers/iio/chemical/scd30_core.c
> @@ -640,7 +640,8 @@ static int scd30_setup_trigger(struct iio_dev *indio_dev)
>         struct iio_trigger *trig;
>         int ret;
>
> -       trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, indio_dev->id);
> +       trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name,
> +                                     iio_device_id(indio_dev));
>         if (!trig) {
>                 dev_err(dev, "failed to allocate trigger\n");
>                 return -ENOMEM;
> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
> index 95ddccb44f1c..5a7b3e253e58 100644
> --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
> +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
> @@ -256,7 +256,7 @@ int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
>         }
>
>         trig = iio_trigger_alloc(indio_dev->dev.parent,
> -                                "%s-dev%d", name, indio_dev->id);
> +                                "%s-dev%d", name, iio_device_id(indio_dev));
>         if (trig == NULL) {
>                 dev_err(&indio_dev->dev, "Trigger Allocate Failed\n");
>                 ret = -ENOMEM;
> diff --git a/drivers/iio/gyro/adxrs290.c b/drivers/iio/gyro/adxrs290.c
> index cec5e1f17c22..3e0734ddafe3 100644
> --- a/drivers/iio/gyro/adxrs290.c
> +++ b/drivers/iio/gyro/adxrs290.c
> @@ -589,7 +589,7 @@ static int adxrs290_probe_trigger(struct iio_dev *indio_dev)
>
>         st->dready_trig = devm_iio_trigger_alloc(&st->spi->dev, "%s-dev%d",
>                                                  indio_dev->name,
> -                                                indio_dev->id);
> +                                                iio_device_id(indio_dev));
>         if (!st->dready_trig)
>                 return -ENOMEM;
>
> diff --git a/drivers/iio/gyro/bmg160_core.c b/drivers/iio/gyro/bmg160_core.c
> index b11ebd9bb7a4..26a9ed5770c6 100644
> --- a/drivers/iio/gyro/bmg160_core.c
> +++ b/drivers/iio/gyro/bmg160_core.c
> @@ -1137,14 +1137,14 @@ int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq,
>                 data->dready_trig = devm_iio_trigger_alloc(dev,
>                                                            "%s-dev%d",
>                                                            indio_dev->name,
> -                                                          indio_dev->id);
> +                                                          iio_device_id(indio_dev));
>                 if (!data->dready_trig)
>                         return -ENOMEM;
>
>                 data->motion_trig = devm_iio_trigger_alloc(dev,
>                                                           "%s-any-motion-dev%d",
>                                                           indio_dev->name,
> -                                                         indio_dev->id);
> +                                                         iio_device_id(indio_dev));
>                 if (!data->motion_trig)
>                         return -ENOMEM;
>
> diff --git a/drivers/iio/gyro/fxas21002c_core.c b/drivers/iio/gyro/fxas21002c_core.c
> index 1a20c6b88e7d..5af7b48ff01a 100644
> --- a/drivers/iio/gyro/fxas21002c_core.c
> +++ b/drivers/iio/gyro/fxas21002c_core.c
> @@ -852,7 +852,7 @@ static int fxas21002c_trigger_probe(struct fxas21002c_data *data)
>
>         data->dready_trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
>                                                    indio_dev->name,
> -                                                  indio_dev->id);
> +                                                  iio_device_id(indio_dev));
>         if (!data->dready_trig)
>                 return -ENOMEM;
>
> diff --git a/drivers/iio/gyro/itg3200_buffer.c b/drivers/iio/gyro/itg3200_buffer.c
> index af0aaa146f0c..04dd6a7969ea 100644
> --- a/drivers/iio/gyro/itg3200_buffer.c
> +++ b/drivers/iio/gyro/itg3200_buffer.c
> @@ -114,7 +114,7 @@ int itg3200_probe_trigger(struct iio_dev *indio_dev)
>         struct itg3200 *st = iio_priv(indio_dev);
>
>         st->trig = iio_trigger_alloc(&st->i2c->dev, "%s-dev%d", indio_dev->name,
> -                                    indio_dev->id);
> +                                    iio_device_id(indio_dev));
>         if (!st->trig)
>                 return -ENOMEM;
>
> diff --git a/drivers/iio/gyro/mpu3050-core.c b/drivers/iio/gyro/mpu3050-core.c
> index ac90be03332a..131e6f54948e 100644
> --- a/drivers/iio/gyro/mpu3050-core.c
> +++ b/drivers/iio/gyro/mpu3050-core.c
> @@ -1049,7 +1049,7 @@ static int mpu3050_trigger_probe(struct iio_dev *indio_dev, int irq)
>         mpu3050->trig = devm_iio_trigger_alloc(&indio_dev->dev,
>                                                "%s-dev%d",
>                                                indio_dev->name,
> -                                              indio_dev->id);
> +                                              iio_device_id(indio_dev));
>         if (!mpu3050->trig)
>                 return -ENOMEM;
>
> diff --git a/drivers/iio/health/afe4403.c b/drivers/iio/health/afe4403.c
> index 1fa8d51d5080..d4921385aaf7 100644
> --- a/drivers/iio/health/afe4403.c
> +++ b/drivers/iio/health/afe4403.c
> @@ -521,7 +521,7 @@ static int afe4403_probe(struct spi_device *spi)
>                 afe->trig = devm_iio_trigger_alloc(afe->dev,
>                                                    "%s-dev%d",
>                                                    indio_dev->name,
> -                                                  indio_dev->id);
> +                                                  iio_device_id(indio_dev));
>                 if (!afe->trig) {
>                         dev_err(afe->dev, "Unable to allocate IIO trigger\n");
>                         ret = -ENOMEM;
> diff --git a/drivers/iio/health/afe4404.c b/drivers/iio/health/afe4404.c
> index e1476bf79fe2..d8a27dfe074a 100644
> --- a/drivers/iio/health/afe4404.c
> +++ b/drivers/iio/health/afe4404.c
> @@ -528,7 +528,7 @@ static int afe4404_probe(struct i2c_client *client,
>                 afe->trig = devm_iio_trigger_alloc(afe->dev,
>                                                    "%s-dev%d",
>                                                    indio_dev->name,
> -                                                  indio_dev->id);
> +                                                  iio_device_id(indio_dev));
>                 if (!afe->trig) {
>                         dev_err(afe->dev, "Unable to allocate IIO trigger\n");
>                         ret = -ENOMEM;
> diff --git a/drivers/iio/imu/adis_trigger.c b/drivers/iio/imu/adis_trigger.c
> index fa5540fabacc..48eedc29b28a 100644
> --- a/drivers/iio/imu/adis_trigger.c
> +++ b/drivers/iio/imu/adis_trigger.c
> @@ -62,7 +62,8 @@ int devm_adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev)
>         int ret;
>
>         adis->trig = devm_iio_trigger_alloc(&adis->spi->dev, "%s-dev%d",
> -                                           indio_dev->name, indio_dev->id);
> +                                           indio_dev->name,
> +                                           iio_device_id(indio_dev));
>         if (!adis->trig)
>                 return -ENOMEM;
>
> diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c
> index 290b5ef83f77..b63bd7e5e5e5 100644
> --- a/drivers/iio/imu/bmi160/bmi160_core.c
> +++ b/drivers/iio/imu/bmi160/bmi160_core.c
> @@ -785,7 +785,8 @@ int bmi160_probe_trigger(struct iio_dev *indio_dev, int irq, u32 irq_type)
>         int ret;
>
>         data->trig = devm_iio_trigger_alloc(&indio_dev->dev, "%s-dev%d",
> -                                           indio_dev->name, indio_dev->id);
> +                                           indio_dev->name,
> +                                           iio_device_id(indio_dev));
>
>         if (data->trig == NULL)
>                 return -ENOMEM;
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
> index de8ed1446d60..e21ba778595a 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
> @@ -238,7 +238,7 @@ int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev, int irq_type)
>         st->trig = devm_iio_trigger_alloc(&indio_dev->dev,
>                                           "%s-dev%d",
>                                           indio_dev->name,
> -                                         indio_dev->id);
> +                                         iio_device_id(indio_dev));
>         if (!st->trig)
>                 return -ENOMEM;
>
> diff --git a/drivers/iio/imu/kmx61.c b/drivers/iio/imu/kmx61.c
> index fc5a60fcfec0..d3e06ce99c1e 100644
> --- a/drivers/iio/imu/kmx61.c
> +++ b/drivers/iio/imu/kmx61.c
> @@ -1264,7 +1264,7 @@ static struct iio_trigger *kmx61_trigger_setup(struct kmx61_data *data,
>                                       "%s-%s-dev%d",
>                                       indio_dev->name,
>                                       tag,
> -                                     indio_dev->id);
> +                                     iio_device_id(indio_dev));
>         if (!trig)
>                 return ERR_PTR(-ENOMEM);
>
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 022198c32e32..c16b8f344c93 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -169,6 +169,20 @@ static const char * const iio_chan_info_postfix[] = {
>         [IIO_CHAN_INFO_THERMOCOUPLE_TYPE] = "thermocouple_type",
>         [IIO_CHAN_INFO_CALIBAMBIENT] = "calibambient",
>  };
> +/**
> + * iio_device_id() - query the unique ID for the device
> + * @indio_dev:         Device structure whose ID is being queried
> + *
> + * The IIO device ID is a unique index used for example for the naming
> + * of the character device /dev/iio\:device[ID]
> + */
> +int iio_device_id(struct iio_dev *indio_dev)
> +{
> +       struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
> +
> +       return iio_dev_opaque->id;
> +}
> +EXPORT_SYMBOL_GPL(iio_device_id);
>
>  /**
>   * iio_sysfs_match_string_with_gaps - matches given string in an array with gaps
> @@ -1588,7 +1602,7 @@ static void iio_dev_release(struct device *device)
>
>         iio_device_detach_buffers(indio_dev);
>
> -       ida_simple_remove(&iio_ida, indio_dev->id);
> +       ida_simple_remove(&iio_ida, iio_dev_opaque->id);
>         kfree(iio_dev_opaque);
>  }
>
> @@ -1631,14 +1645,14 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)
>         mutex_init(&indio_dev->info_exist_lock);
>         INIT_LIST_HEAD(&iio_dev_opaque->channel_attr_list);
>
> -       indio_dev->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL);
> -       if (indio_dev->id < 0) {
> +       iio_dev_opaque->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL);
> +       if (iio_dev_opaque->id < 0) {
>                 /* cannot use a dev_err as the name isn't available */
>                 pr_err("failed to get device id\n");
>                 kfree(iio_dev_opaque);
>                 return NULL;
>         }
> -       dev_set_name(&indio_dev->dev, "iio:device%d", indio_dev->id);
> +       dev_set_name(&indio_dev->dev, "iio:device%d", iio_dev_opaque->id);
>         INIT_LIST_HEAD(&iio_dev_opaque->buffer_list);
>         INIT_LIST_HEAD(&iio_dev_opaque->ioctl_handlers);
>
> @@ -1892,7 +1906,7 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod)
>                 cdev_init(&indio_dev->chrdev, &iio_event_fileops);
>
>         if (iio_dev_opaque->attached_buffers_cnt || iio_dev_opaque->event_interface) {
> -               indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), indio_dev->id);
> +               indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), iio_dev_opaque->id);
>                 indio_dev->chrdev.owner = this_mod;
>         }
>
> diff --git a/drivers/iio/industrialio-triggered-event.c b/drivers/iio/industrialio-triggered-event.c
> index 53da9ab17a62..4bedc65c9fe3 100644
> --- a/drivers/iio/industrialio-triggered-event.c
> +++ b/drivers/iio/industrialio-triggered-event.c
> @@ -37,7 +37,7 @@ int iio_triggered_event_setup(struct iio_dev *indio_dev,
>                                                        indio_dev,
>                                                        "%s_consumer%d",
>                                                        indio_dev->name,
> -                                                      indio_dev->id);
> +                                                      iio_device_id(indio_dev));
>         if (indio_dev->pollfunc_event == NULL)
>                 return -ENOMEM;
>
> diff --git a/drivers/iio/light/acpi-als.c b/drivers/iio/light/acpi-als.c
> index 30393f08e082..260f96ea5f3c 100644
> --- a/drivers/iio/light/acpi-als.c
> +++ b/drivers/iio/light/acpi-als.c
> @@ -206,7 +206,8 @@ static int acpi_als_add(struct acpi_device *device)
>         indio_dev->channels = acpi_als_channels;
>         indio_dev->num_channels = ARRAY_SIZE(acpi_als_channels);
>
> -       als->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, indio_dev->id);
> +       als->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name,
> +                                          iio_device_id(indio_dev));
>         if (!als->trig)
>                 return -ENOMEM;
>
> diff --git a/drivers/iio/light/rpr0521.c b/drivers/iio/light/rpr0521.c
> index 033578f444e4..7e332de0e6a5 100644
> --- a/drivers/iio/light/rpr0521.c
> +++ b/drivers/iio/light/rpr0521.c
> @@ -985,7 +985,7 @@ static int rpr0521_probe(struct i2c_client *client,
>                 /* Trigger0 producer setup */
>                 data->drdy_trigger0 = devm_iio_trigger_alloc(
>                         indio_dev->dev.parent,
> -                       "%s-dev%d", indio_dev->name, indio_dev->id);
> +                       "%s-dev%d", indio_dev->name, iio_device_id(indio_dev));
>                 if (!data->drdy_trigger0) {
>                         ret = -ENOMEM;
>                         goto err_pm_disable;
> diff --git a/drivers/iio/light/si1145.c b/drivers/iio/light/si1145.c
> index 9b5c99823943..3fb52402fcc3 100644
> --- a/drivers/iio/light/si1145.c
> +++ b/drivers/iio/light/si1145.c
> @@ -1243,7 +1243,7 @@ static int si1145_probe_trigger(struct iio_dev *indio_dev)
>         int ret;
>
>         trig = devm_iio_trigger_alloc(&client->dev,
> -                       "%s-dev%d", indio_dev->name, indio_dev->id);
> +                       "%s-dev%d", indio_dev->name, iio_device_id(indio_dev));
>         if (!trig)
>                 return -ENOMEM;
>
> diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
> index 2f7916f95689..4a61865d01cd 100644
> --- a/drivers/iio/light/vcnl4000.c
> +++ b/drivers/iio/light/vcnl4000.c
> @@ -998,7 +998,8 @@ static int vcnl4010_probe_trigger(struct iio_dev *indio_dev)
>         struct iio_trigger *trigger;
>
>         trigger = devm_iio_trigger_alloc(&client->dev, "%s-dev%d",
> -                                        indio_dev->name, indio_dev->id);
> +                                        indio_dev->name,
> +                                        iio_device_id(indio_dev));
>         if (!trigger)
>                 return -ENOMEM;
>
> diff --git a/drivers/iio/light/vcnl4035.c b/drivers/iio/light/vcnl4035.c
> index ae87740d9cef..691a54b763e1 100644
> --- a/drivers/iio/light/vcnl4035.c
> +++ b/drivers/iio/light/vcnl4035.c
> @@ -507,7 +507,7 @@ static int vcnl4035_probe_trigger(struct iio_dev *indio_dev)
>
>         data->drdy_trigger0 = devm_iio_trigger_alloc(
>                         indio_dev->dev.parent,
> -                       "%s-dev%d", indio_dev->name, indio_dev->id);
> +                       "%s-dev%d", indio_dev->name, iio_device_id(indio_dev));
>         if (!data->drdy_trigger0)
>                 return -ENOMEM;
>
> diff --git a/drivers/iio/magnetometer/bmc150_magn.c b/drivers/iio/magnetometer/bmc150_magn.c
> index 00f9766bad5c..d75b437a43f2 100644
> --- a/drivers/iio/magnetometer/bmc150_magn.c
> +++ b/drivers/iio/magnetometer/bmc150_magn.c
> @@ -915,7 +915,7 @@ int bmc150_magn_probe(struct device *dev, struct regmap *regmap,
>                 data->dready_trig = devm_iio_trigger_alloc(dev,
>                                                            "%s-dev%d",
>                                                            indio_dev->name,
> -                                                          indio_dev->id);
> +                                                          iio_device_id(indio_dev));
>                 if (!data->dready_trig) {
>                         ret = -ENOMEM;
>                         dev_err(dev, "iio trigger alloc failed\n");
> diff --git a/drivers/iio/magnetometer/rm3100-core.c b/drivers/iio/magnetometer/rm3100-core.c
> index dd811da9cb6d..4df5887fd04c 100644
> --- a/drivers/iio/magnetometer/rm3100-core.c
> +++ b/drivers/iio/magnetometer/rm3100-core.c
> @@ -575,7 +575,7 @@ int rm3100_common_probe(struct device *dev, struct regmap *regmap, int irq)
>
>                 data->drdy_trig = devm_iio_trigger_alloc(dev, "%s-drdy%d",
>                                                          indio_dev->name,
> -                                                        indio_dev->id);
> +                                                        iio_device_id(indio_dev));
>                 if (!data->drdy_trig)
>                         return -ENOMEM;
>
> diff --git a/drivers/iio/potentiostat/lmp91000.c b/drivers/iio/potentiostat/lmp91000.c
> index 8a9c576616ee..1948e2d22c27 100644
> --- a/drivers/iio/potentiostat/lmp91000.c
> +++ b/drivers/iio/potentiostat/lmp91000.c
> @@ -323,7 +323,8 @@ static int lmp91000_probe(struct i2c_client *client,
>         }
>
>         data->trig = devm_iio_trigger_alloc(dev, "%s-mux%d",
> -                                           indio_dev->name, indio_dev->id);
> +                                           indio_dev->name,
> +                                           iio_device_id(indio_dev));
>         if (!data->trig) {
>                 dev_err(dev, "cannot allocate iio trigger.\n");
>                 return -ENOMEM;
> diff --git a/drivers/iio/pressure/zpa2326.c b/drivers/iio/pressure/zpa2326.c
> index a93411216aee..89295c90f801 100644
> --- a/drivers/iio/pressure/zpa2326.c
> +++ b/drivers/iio/pressure/zpa2326.c
> @@ -1408,7 +1408,8 @@ static int zpa2326_init_managed_trigger(struct device          *parent,
>                 return 0;
>
>         trigger = devm_iio_trigger_alloc(parent, "%s-dev%d",
> -                                        indio_dev->name, indio_dev->id);
> +                                        indio_dev->name,
> +                                        iio_device_id(indio_dev));
>         if (!trigger)
>                 return -ENOMEM;
>
> diff --git a/drivers/iio/proximity/as3935.c b/drivers/iio/proximity/as3935.c
> index edc4a35ae66d..dc20fe81232c 100644
> --- a/drivers/iio/proximity/as3935.c
> +++ b/drivers/iio/proximity/as3935.c
> @@ -404,7 +404,8 @@ static int as3935_probe(struct spi_device *spi)
>         indio_dev->info = &as3935_info;
>
>         trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
> -                                     indio_dev->name, indio_dev->id);
> +                                     indio_dev->name,
> +                                     iio_device_id(indio_dev));
>
>         if (!trig)
>                 return -ENOMEM;
> diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c
> index 327ebb7ddbb9..175f3b7c61d7 100644
> --- a/drivers/iio/proximity/sx9310.c
> +++ b/drivers/iio/proximity/sx9310.c
> @@ -1473,7 +1473,7 @@ static int sx9310_probe(struct i2c_client *client)
>
>                 data->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
>                                                     indio_dev->name,
> -                                                   indio_dev->id);
> +                                                   iio_device_id(indio_dev));
>                 if (!data->trig)
>                         return -ENOMEM;
>
> diff --git a/drivers/iio/proximity/sx9500.c b/drivers/iio/proximity/sx9500.c
> index a87f4a8e4327..3e4ddb2e8c2b 100644
> --- a/drivers/iio/proximity/sx9500.c
> +++ b/drivers/iio/proximity/sx9500.c
> @@ -946,7 +946,7 @@ static int sx9500_probe(struct i2c_client *client,
>                         return ret;
>
>                 data->trig = devm_iio_trigger_alloc(&client->dev,
> -                               "%s-dev%d", indio_dev->name, indio_dev->id);
> +                               "%s-dev%d", indio_dev->name, iio_device_id(indio_dev));
>                 if (!data->trig)
>                         return -ENOMEM;
>
> diff --git a/include/linux/iio/iio-opaque.h b/include/linux/iio/iio-opaque.h
> index 32addd5e790e..e66b029d99de 100644
> --- a/include/linux/iio/iio-opaque.h
> +++ b/include/linux/iio/iio-opaque.h
> @@ -6,6 +6,7 @@
>  /**
>   * struct iio_dev_opaque - industrial I/O device opaque information
>   * @indio_dev:                 public industrial I/O device information
> + * @id:                        used to identify device internally
>   * @event_interface:           event chrdevs associated with interrupt lines
>   * @attached_buffers:          array of buffers statically attached by the driver
>   * @attached_buffers_cnt:      number of buffers in the array of statically attached buffers
> @@ -26,6 +27,7 @@
>   */
>  struct iio_dev_opaque {
>         struct iio_dev                  indio_dev;
> +       int                             id;
>         struct iio_event_interface      *event_interface;
>         struct iio_buffer               **attached_buffers;
>         unsigned int                    attached_buffers_cnt;
> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> index f2d65e2e88b6..569861d5887a 100644
> --- a/include/linux/iio/iio.h
> +++ b/include/linux/iio/iio.h
> @@ -488,7 +488,6 @@ struct iio_buffer_setup_ops {
>
>  /**
>   * struct iio_dev - industrial I/O device
> - * @id:                        [INTERN] used to identify device internally
>   * @driver_module:     [INTERN] used to make it harder to undercut users
>   * @modes:             [DRIVER] operating modes supported by device
>   * @currentmode:       [DRIVER] current operating mode
> @@ -523,7 +522,6 @@ struct iio_buffer_setup_ops {
>   *                     **MUST** be accessed **ONLY** via iio_priv() helper
>   */
>  struct iio_dev {
> -       int                             id;
>         struct module                   *driver_module;
>
>         int                             modes;
> @@ -559,6 +557,8 @@ struct iio_dev {
>         void                            *priv;
>  };
>
> +int iio_device_id(struct iio_dev *indio_dev);
> +
>  const struct iio_chan_spec
>  *iio_find_channel_from_si(struct iio_dev *indio_dev, int si);
>  /**
> --
> 2.31.1
>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 2/9] iio: avoid shadowing of variable name in to_iio_dev_opaque()
  2021-04-26 17:49 ` [PATCH 2/9] iio: avoid shadowing of variable name in to_iio_dev_opaque() Jonathan Cameron
@ 2021-04-27  7:45   ` Alexandru Ardelean
  0 siblings, 0 replies; 27+ messages in thread
From: Alexandru Ardelean @ 2021-04-27  7:45 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Jonathan Cameron

On Mon, Apr 26, 2021 at 8:50 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> indio_dev was both the macro input parameter and the field name
> in this macro.  That causes trouble if the instance of
> struct iio_dev passed in is not called indio_dev.
>
> Whilst a fix of sorts, no need to backport as it seems we never
> hit this previously due to some very consistent naming in IIO.
>

Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>

> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  include/linux/iio/iio-opaque.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/iio/iio-opaque.h b/include/linux/iio/iio-opaque.h
> index e66b029d99de..f876e3aede2c 100644
> --- a/include/linux/iio/iio-opaque.h
> +++ b/include/linux/iio/iio-opaque.h
> @@ -48,7 +48,7 @@ struct iio_dev_opaque {
>  #endif
>  };
>
> -#define to_iio_dev_opaque(indio_dev)           \
> -       container_of(indio_dev, struct iio_dev_opaque, indio_dev)
> +#define to_iio_dev_opaque(_indio_dev)          \
> +       container_of((_indio_dev), struct iio_dev_opaque, indio_dev)
>
>  #endif
> --
> 2.31.1
>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 9/9] iio: core: move @clock_id from struct iio_dev to struct iio_dev_opaque
  2021-04-26 17:49 ` [PATCH 9/9] iio: core: move @clock_id " Jonathan Cameron
@ 2021-04-27  8:02   ` Alexandru Ardelean
  2021-04-27 17:19     ` Jonathan Cameron
  0 siblings, 1 reply; 27+ messages in thread
From: Alexandru Ardelean @ 2021-04-27  8:02 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Jonathan Cameron

On Mon, Apr 26, 2021 at 8:50 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> There is already an acessor function used to access it, making this
> move straight forward.

Right now the iio_device_get_clock() helper is only being used in the
Chrome EC core sensor driver.
Maybe later if that can be reworked without this helper, then it could
be made private to IIO core.
Though, chances are some other driver may come along later and ask for
it to be public again.

Anyway.

Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>

>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  drivers/iio/industrialio-core.c | 14 +++++++++++++-
>  include/linux/iio/iio-opaque.h  |  2 ++
>  include/linux/iio/iio.h         | 12 +-----------
>  3 files changed, 16 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 4a4c02fea152..efb4cf91c9e4 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -271,13 +271,25 @@ int iio_device_set_clock(struct iio_dev *indio_dev, clockid_t clock_id)
>                 mutex_unlock(&indio_dev->mlock);
>                 return -EBUSY;
>         }
> -       indio_dev->clock_id = clock_id;
> +       iio_dev_opaque->clock_id = clock_id;
>         mutex_unlock(&indio_dev->mlock);
>
>         return 0;
>  }
>  EXPORT_SYMBOL(iio_device_set_clock);
>
> +/**
> + * iio_device_get_clock() - Retrieve current timestamping clock for the device
> + * @indio_dev: IIO device structure containing the device
> + */
> +clockid_t iio_device_get_clock(const struct iio_dev *indio_dev)
> +{
> +       struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
> +
> +       return iio_dev_opaque->clock_id;
> +}
> +EXPORT_SYMBOL(iio_device_get_clock);
> +
>  /**
>   * iio_get_time_ns() - utility function to get a time stamp for events etc
>   * @indio_dev: device
> diff --git a/include/linux/iio/iio-opaque.h b/include/linux/iio/iio-opaque.h
> index d7c3036861ac..c9504e9da571 100644
> --- a/include/linux/iio/iio-opaque.h
> +++ b/include/linux/iio/iio-opaque.h
> @@ -24,6 +24,7 @@
>   * @legacy_scan_el_group:      attribute group for legacy scan elements attribute group
>   * @legacy_buffer_group:       attribute group for legacy buffer attributes group
>   * @scan_index_timestamp:      cache of the index to the timestamp
> + * @clock_id:                  timestamping clock posix identifier
>   * @chrdev:                    associated character device
>   * @flags:                     file ops related flags including busy flag.
>   * @debugfs_dentry:            device specific debugfs dentry
> @@ -51,6 +52,7 @@ struct iio_dev_opaque {
>         struct attribute_group          legacy_buffer_group;
>
>         unsigned int                    scan_index_timestamp;
> +       clockid_t                       clock_id;
>         struct cdev                     chrdev;
>         unsigned long                   flags;
>
> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> index ed0537015eee..5606a3f4c4cb 100644
> --- a/include/linux/iio/iio.h
> +++ b/include/linux/iio/iio.h
> @@ -509,7 +509,6 @@ struct iio_buffer_setup_ops {
>   * @name:              [DRIVER] name of the device.
>   * @label:              [DRIVER] unique name to identify which device this is
>   * @info:              [DRIVER] callbacks and constant info from driver
> - * @clock_id:          [INTERN] timestamping clock posix identifier
>   * @setup_ops:         [DRIVER] callbacks to call before and after buffer
>   *                     enable/disable
>   * @priv:              [DRIVER] reference to driver's private information
> @@ -538,7 +537,6 @@ struct iio_dev {
>         const char                      *name;
>         const char                      *label;
>         const struct iio_info           *info;
> -       clockid_t                       clock_id;
>         const struct iio_buffer_setup_ops       *setup_ops;
>
>         void                            *priv;
> @@ -589,15 +587,7 @@ static inline void iio_device_put(struct iio_dev *indio_dev)
>                 put_device(&indio_dev->dev);
>  }
>
> -/**
> - * iio_device_get_clock() - Retrieve current timestamping clock for the device
> - * @indio_dev: IIO device structure containing the device
> - */
> -static inline clockid_t iio_device_get_clock(const struct iio_dev *indio_dev)
> -{
> -       return indio_dev->clock_id;
> -}
> -
> +clockid_t iio_device_get_clock(const struct iio_dev *indio_dev);
>  int iio_device_set_clock(struct iio_dev *indio_dev, clockid_t clock_id);
>
>  /**
> --
> 2.31.1
>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 4/9] iio: core: move @trig_readonly from struct iio_dev to struct iio_dev_opaque
  2021-04-26 17:49 ` [PATCH 4/9] iio: core: move @trig_readonly " Jonathan Cameron
@ 2021-04-27  8:03   ` Alexandru Ardelean
  0 siblings, 0 replies; 27+ messages in thread
From: Alexandru Ardelean @ 2021-04-27  8:03 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Jonathan Cameron

On Mon, Apr 26, 2021 at 8:50 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> This is only set via the iio_trig_set_immutable() call and later used
> by the IIO core so there is no benefit in drivers being able to access
> it.


Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>


>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  drivers/iio/industrialio-trigger.c | 10 +++++++---
>  include/linux/iio/iio-opaque.h     |  2 ++
>  include/linux/iio/iio.h            |  2 --
>  3 files changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
> index b489eeeb0004..b23caa2f2aa1 100644
> --- a/drivers/iio/industrialio-trigger.c
> +++ b/drivers/iio/industrialio-trigger.c
> @@ -117,14 +117,17 @@ EXPORT_SYMBOL(iio_trigger_unregister);
>
>  int iio_trigger_set_immutable(struct iio_dev *indio_dev, struct iio_trigger *trig)
>  {
> +       struct iio_dev_opaque *iio_dev_opaque;
> +
>         if (!indio_dev || !trig)
>                 return -EINVAL;
>
> +       iio_dev_opaque = to_iio_dev_opaque(indio_dev);
>         mutex_lock(&indio_dev->mlock);
> -       WARN_ON(indio_dev->trig_readonly);
> +       WARN_ON(iio_dev_opaque->trig_readonly);
>
>         indio_dev->trig = iio_trigger_get(trig);
> -       indio_dev->trig_readonly = true;
> +       iio_dev_opaque->trig_readonly = true;
>         mutex_unlock(&indio_dev->mlock);
>
>         return 0;
> @@ -402,6 +405,7 @@ static ssize_t iio_trigger_write_current(struct device *dev,
>                                          size_t len)
>  {
>         struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> +       struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
>         struct iio_trigger *oldtrig = indio_dev->trig;
>         struct iio_trigger *trig;
>         int ret;
> @@ -411,7 +415,7 @@ static ssize_t iio_trigger_write_current(struct device *dev,
>                 mutex_unlock(&indio_dev->mlock);
>                 return -EBUSY;
>         }
> -       if (indio_dev->trig_readonly) {
> +       if (iio_dev_opaque->trig_readonly) {
>                 mutex_unlock(&indio_dev->mlock);
>                 return -EPERM;
>         }
> diff --git a/include/linux/iio/iio-opaque.h b/include/linux/iio/iio-opaque.h
> index 96dd265103d0..10aa97239117 100644
> --- a/include/linux/iio/iio-opaque.h
> +++ b/include/linux/iio/iio-opaque.h
> @@ -8,6 +8,7 @@
>   * @indio_dev:                 public industrial I/O device information
>   * @id:                        used to identify device internally
>   * @driver_module:             used to make it harder to undercut users
> + * @trig_readonly:             mark the current trigger immutable
>   * @event_interface:           event chrdevs associated with interrupt lines
>   * @attached_buffers:          array of buffers statically attached by the driver
>   * @attached_buffers_cnt:      number of buffers in the array of statically attached buffers
> @@ -30,6 +31,7 @@ struct iio_dev_opaque {
>         struct iio_dev                  indio_dev;
>         int                             id;
>         struct module                   *driver_module;
> +       bool                            trig_readonly;
>         struct iio_event_interface      *event_interface;
>         struct iio_buffer               **attached_buffers;
>         unsigned int                    attached_buffers_cnt;
> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> index 9e8e1358a032..672f141f74c5 100644
> --- a/include/linux/iio/iio.h
> +++ b/include/linux/iio/iio.h
> @@ -503,7 +503,6 @@ struct iio_buffer_setup_ops {
>   * @scan_timestamp:    [INTERN] set if any buffers have requested timestamp
>   * @scan_index_timestamp:[INTERN] cache of the index to the timestamp
>   * @trig:              [INTERN] current device trigger (buffer modes)
> - * @trig_readonly:     [INTERN] mark the current trigger immutable
>   * @pollfunc:          [DRIVER] function run on trigger being received
>   * @pollfunc_event:    [DRIVER] function run on events trigger being received
>   * @channels:          [DRIVER] channel specification structure table
> @@ -535,7 +534,6 @@ struct iio_dev {
>         bool                            scan_timestamp;
>         unsigned                        scan_index_timestamp;
>         struct iio_trigger              *trig;
> -       bool                            trig_readonly;
>         struct iio_poll_func            *pollfunc;
>         struct iio_poll_func            *pollfunc_event;
>
> --
> 2.31.1
>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 5/9] iio: core: move @scan_index_timestamp to struct iio_dev_opaque
  2021-04-26 17:49 ` [PATCH 5/9] iio: core: move @scan_index_timestamp " Jonathan Cameron
@ 2021-04-27  8:03   ` Alexandru Ardelean
  0 siblings, 0 replies; 27+ messages in thread
From: Alexandru Ardelean @ 2021-04-27  8:03 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Jonathan Cameron

On Mon, Apr 26, 2021 at 8:50 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> No reason for this cached value to be exposed to drivers so move it
> to the opaque structure.
>


Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>


> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  drivers/iio/industrialio-buffer.c | 7 +++++--
>  include/linux/iio/iio-opaque.h    | 4 ++++
>  include/linux/iio/iio.h           | 2 --
>  3 files changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
> index 9a8e16c7e9af..9ecb3c58d94c 100644
> --- a/drivers/iio/industrialio-buffer.c
> +++ b/drivers/iio/industrialio-buffer.c
> @@ -601,8 +601,10 @@ static unsigned int iio_storage_bytes_for_si(struct iio_dev *indio_dev,
>
>  static unsigned int iio_storage_bytes_for_timestamp(struct iio_dev *indio_dev)
>  {
> +       struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
> +
>         return iio_storage_bytes_for_si(indio_dev,
> -                                       indio_dev->scan_index_timestamp);
> +                                       iio_dev_opaque->scan_index_timestamp);
>  }
>
>  static int iio_compute_scan_bytes(struct iio_dev *indio_dev,
> @@ -1469,6 +1471,7 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer,
>                                              struct iio_dev *indio_dev,
>                                              int index)
>  {
> +       struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
>         struct iio_dev_attr *p;
>         struct attribute **attr;
>         int ret, i, attrn, scan_el_attrcount, buffer_attrcount;
> @@ -1495,7 +1498,7 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer,
>                                 goto error_cleanup_dynamic;
>                         scan_el_attrcount += ret;
>                         if (channels[i].type == IIO_TIMESTAMP)
> -                               indio_dev->scan_index_timestamp =
> +                               iio_dev_opaque->scan_index_timestamp =
>                                         channels[i].scan_index;
>                 }
>                 if (indio_dev->masklength && buffer->scan_mask == NULL) {
> diff --git a/include/linux/iio/iio-opaque.h b/include/linux/iio/iio-opaque.h
> index 10aa97239117..02038fb2d291 100644
> --- a/include/linux/iio/iio-opaque.h
> +++ b/include/linux/iio/iio-opaque.h
> @@ -22,6 +22,7 @@
>   * @groupcounter:              index of next attribute group
>   * @legacy_scan_el_group:      attribute group for legacy scan elements attribute group
>   * @legacy_buffer_group:       attribute group for legacy buffer attributes group
> + * @scan_index_timestamp:      cache of the index to the timestamp
>   * @debugfs_dentry:            device specific debugfs dentry
>   * @cached_reg_addr:           cached register address for debugfs reads
>   * @read_buf:                  read buffer to be used for the initial reg read
> @@ -44,6 +45,9 @@ struct iio_dev_opaque {
>         int                             groupcounter;
>         struct attribute_group          legacy_scan_el_group;
>         struct attribute_group          legacy_buffer_group;
> +
> +       unsigned int                    scan_index_timestamp;
> +
>  #if defined(CONFIG_DEBUG_FS)
>         struct dentry                   *debugfs_dentry;
>         unsigned                        cached_reg_addr;
> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> index 672f141f74c5..cbc9e9ece0a6 100644
> --- a/include/linux/iio/iio.h
> +++ b/include/linux/iio/iio.h
> @@ -501,7 +501,6 @@ struct iio_buffer_setup_ops {
>   *                     channels
>   * @active_scan_mask:  [INTERN] union of all scan masks requested by buffers
>   * @scan_timestamp:    [INTERN] set if any buffers have requested timestamp
> - * @scan_index_timestamp:[INTERN] cache of the index to the timestamp
>   * @trig:              [INTERN] current device trigger (buffer modes)
>   * @pollfunc:          [DRIVER] function run on trigger being received
>   * @pollfunc_event:    [DRIVER] function run on events trigger being received
> @@ -532,7 +531,6 @@ struct iio_dev {
>         unsigned                        masklength;
>         const unsigned long             *active_scan_mask;
>         bool                            scan_timestamp;
> -       unsigned                        scan_index_timestamp;
>         struct iio_trigger              *trig;
>         struct iio_poll_func            *pollfunc;
>         struct iio_poll_func            *pollfunc_event;
> --
> 2.31.1
>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 6/9] iio: core: move @info_exist_lock to struct iio_dev_opaque
  2021-04-26 17:49 ` [PATCH 6/9] iio: core: move @info_exist_lock " Jonathan Cameron
@ 2021-04-27  8:04   ` Alexandru Ardelean
  0 siblings, 0 replies; 27+ messages in thread
From: Alexandru Ardelean @ 2021-04-27  8:04 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Jonathan Cameron

On Mon, Apr 26, 2021 at 8:50 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> This lock is only of interest to the IIO core, so make it only
> visible there.

This was on my list at some point, but I deferred it because it was
overlapping with the IIO buffer stuff.

Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>

>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  drivers/iio/industrialio-buffer.c |  5 ++--
>  drivers/iio/industrialio-core.c   | 10 +++----
>  drivers/iio/inkern.c              | 46 +++++++++++++++++++------------
>  include/linux/iio/iio-opaque.h    |  2 ++
>  include/linux/iio/iio.h           |  2 --
>  5 files changed, 38 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
> index 9ecb3c58d94c..10923b40c76d 100644
> --- a/drivers/iio/industrialio-buffer.c
> +++ b/drivers/iio/industrialio-buffer.c
> @@ -1150,12 +1150,13 @@ int iio_update_buffers(struct iio_dev *indio_dev,
>                        struct iio_buffer *insert_buffer,
>                        struct iio_buffer *remove_buffer)
>  {
> +       struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
>         int ret;
>
>         if (insert_buffer == remove_buffer)
>                 return 0;
>
> -       mutex_lock(&indio_dev->info_exist_lock);
> +       mutex_lock(&iio_dev_opaque->info_exist_lock);
>         mutex_lock(&indio_dev->mlock);
>
>         if (insert_buffer && iio_buffer_is_active(insert_buffer))
> @@ -1178,7 +1179,7 @@ int iio_update_buffers(struct iio_dev *indio_dev,
>
>  out_unlock:
>         mutex_unlock(&indio_dev->mlock);
> -       mutex_unlock(&indio_dev->info_exist_lock);
> +       mutex_unlock(&iio_dev_opaque->info_exist_lock);
>
>         return ret;
>  }
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 8c38f1f6e075..f3b38d69b7e1 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -1642,7 +1642,7 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)
>         device_initialize(&indio_dev->dev);
>         iio_device_set_drvdata(indio_dev, (void *)indio_dev);
>         mutex_init(&indio_dev->mlock);
> -       mutex_init(&indio_dev->info_exist_lock);
> +       mutex_init(&iio_dev_opaque->info_exist_lock);
>         INIT_LIST_HEAD(&iio_dev_opaque->channel_attr_list);
>
>         iio_dev_opaque->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL);
> @@ -1779,7 +1779,7 @@ static long iio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
>         struct iio_ioctl_handler *h;
>         int ret = -ENODEV;
>
> -       mutex_lock(&indio_dev->info_exist_lock);
> +       mutex_lock(&iio_dev_opaque->info_exist_lock);
>
>         /**
>          * The NULL check here is required to prevent crashing when a device
> @@ -1800,7 +1800,7 @@ static long iio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
>                 ret = -EINVAL;
>
>  out_unlock:
> -       mutex_unlock(&indio_dev->info_exist_lock);
> +       mutex_unlock(&iio_dev_opaque->info_exist_lock);
>
>         return ret;
>  }
> @@ -1942,7 +1942,7 @@ void iio_device_unregister(struct iio_dev *indio_dev)
>
>         cdev_device_del(&indio_dev->chrdev, &indio_dev->dev);
>
> -       mutex_lock(&indio_dev->info_exist_lock);
> +       mutex_lock(&iio_dev_opaque->info_exist_lock);
>
>         iio_device_unregister_debugfs(indio_dev);
>
> @@ -1956,7 +1956,7 @@ void iio_device_unregister(struct iio_dev *indio_dev)
>         iio_device_wakeup_eventset(indio_dev);
>         iio_buffer_wakeup_poll(indio_dev);
>
> -       mutex_unlock(&indio_dev->info_exist_lock);
> +       mutex_unlock(&iio_dev_opaque->info_exist_lock);
>
>         iio_buffers_free_sysfs_and_mask(indio_dev);
>  }
> diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
> index 5aa740cea661..391a3380a1d1 100644
> --- a/drivers/iio/inkern.c
> +++ b/drivers/iio/inkern.c
> @@ -10,6 +10,7 @@
>  #include <linux/of.h>
>
>  #include <linux/iio/iio.h>
> +#include <linux/iio/iio-opaque.h>
>  #include "iio_core.h"
>  #include <linux/iio/machine.h>
>  #include <linux/iio/driver.h>
> @@ -538,9 +539,10 @@ static int iio_channel_read(struct iio_channel *chan, int *val, int *val2,
>
>  int iio_read_channel_raw(struct iio_channel *chan, int *val)
>  {
> +       struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
>         int ret;
>
> -       mutex_lock(&chan->indio_dev->info_exist_lock);
> +       mutex_lock(&iio_dev_opaque->info_exist_lock);
>         if (chan->indio_dev->info == NULL) {
>                 ret = -ENODEV;
>                 goto err_unlock;
> @@ -548,7 +550,7 @@ int iio_read_channel_raw(struct iio_channel *chan, int *val)
>
>         ret = iio_channel_read(chan, val, NULL, IIO_CHAN_INFO_RAW);
>  err_unlock:
> -       mutex_unlock(&chan->indio_dev->info_exist_lock);
> +       mutex_unlock(&iio_dev_opaque->info_exist_lock);
>
>         return ret;
>  }
> @@ -556,9 +558,10 @@ EXPORT_SYMBOL_GPL(iio_read_channel_raw);
>
>  int iio_read_channel_average_raw(struct iio_channel *chan, int *val)
>  {
> +       struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
>         int ret;
>
> -       mutex_lock(&chan->indio_dev->info_exist_lock);
> +       mutex_lock(&iio_dev_opaque->info_exist_lock);
>         if (chan->indio_dev->info == NULL) {
>                 ret = -ENODEV;
>                 goto err_unlock;
> @@ -566,7 +569,7 @@ int iio_read_channel_average_raw(struct iio_channel *chan, int *val)
>
>         ret = iio_channel_read(chan, val, NULL, IIO_CHAN_INFO_AVERAGE_RAW);
>  err_unlock:
> -       mutex_unlock(&chan->indio_dev->info_exist_lock);
> +       mutex_unlock(&iio_dev_opaque->info_exist_lock);
>
>         return ret;
>  }
> @@ -631,9 +634,10 @@ static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan,
>  int iio_convert_raw_to_processed(struct iio_channel *chan, int raw,
>         int *processed, unsigned int scale)
>  {
> +       struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
>         int ret;
>
> -       mutex_lock(&chan->indio_dev->info_exist_lock);
> +       mutex_lock(&iio_dev_opaque->info_exist_lock);
>         if (chan->indio_dev->info == NULL) {
>                 ret = -ENODEV;
>                 goto err_unlock;
> @@ -642,7 +646,7 @@ int iio_convert_raw_to_processed(struct iio_channel *chan, int raw,
>         ret = iio_convert_raw_to_processed_unlocked(chan, raw, processed,
>                                                         scale);
>  err_unlock:
> -       mutex_unlock(&chan->indio_dev->info_exist_lock);
> +       mutex_unlock(&iio_dev_opaque->info_exist_lock);
>
>         return ret;
>  }
> @@ -651,9 +655,10 @@ EXPORT_SYMBOL_GPL(iio_convert_raw_to_processed);
>  int iio_read_channel_attribute(struct iio_channel *chan, int *val, int *val2,
>                                enum iio_chan_info_enum attribute)
>  {
> +       struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
>         int ret;
>
> -       mutex_lock(&chan->indio_dev->info_exist_lock);
> +       mutex_lock(&iio_dev_opaque->info_exist_lock);
>         if (chan->indio_dev->info == NULL) {
>                 ret = -ENODEV;
>                 goto err_unlock;
> @@ -661,7 +666,7 @@ int iio_read_channel_attribute(struct iio_channel *chan, int *val, int *val2,
>
>         ret = iio_channel_read(chan, val, val2, attribute);
>  err_unlock:
> -       mutex_unlock(&chan->indio_dev->info_exist_lock);
> +       mutex_unlock(&iio_dev_opaque->info_exist_lock);
>
>         return ret;
>  }
> @@ -676,9 +681,10 @@ EXPORT_SYMBOL_GPL(iio_read_channel_offset);
>  int iio_read_channel_processed_scale(struct iio_channel *chan, int *val,
>                                      unsigned int scale)
>  {
> +       struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
>         int ret;
>
> -       mutex_lock(&chan->indio_dev->info_exist_lock);
> +       mutex_lock(&iio_dev_opaque->info_exist_lock);
>         if (chan->indio_dev->info == NULL) {
>                 ret = -ENODEV;
>                 goto err_unlock;
> @@ -699,7 +705,7 @@ int iio_read_channel_processed_scale(struct iio_channel *chan, int *val,
>         }
>
>  err_unlock:
> -       mutex_unlock(&chan->indio_dev->info_exist_lock);
> +       mutex_unlock(&iio_dev_opaque->info_exist_lock);
>
>         return ret;
>  }
> @@ -733,9 +739,10 @@ int iio_read_avail_channel_attribute(struct iio_channel *chan,
>                                      const int **vals, int *type, int *length,
>                                      enum iio_chan_info_enum attribute)
>  {
> +       struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
>         int ret;
>
> -       mutex_lock(&chan->indio_dev->info_exist_lock);
> +       mutex_lock(&iio_dev_opaque->info_exist_lock);
>         if (!chan->indio_dev->info) {
>                 ret = -ENODEV;
>                 goto err_unlock;
> @@ -743,7 +750,7 @@ int iio_read_avail_channel_attribute(struct iio_channel *chan,
>
>         ret = iio_channel_read_avail(chan, vals, type, length, attribute);
>  err_unlock:
> -       mutex_unlock(&chan->indio_dev->info_exist_lock);
> +       mutex_unlock(&iio_dev_opaque->info_exist_lock);
>
>         return ret;
>  }
> @@ -815,10 +822,11 @@ static int iio_channel_read_max(struct iio_channel *chan,
>
>  int iio_read_max_channel_raw(struct iio_channel *chan, int *val)
>  {
> +       struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
>         int ret;
>         int type;
>
> -       mutex_lock(&chan->indio_dev->info_exist_lock);
> +       mutex_lock(&iio_dev_opaque->info_exist_lock);
>         if (!chan->indio_dev->info) {
>                 ret = -ENODEV;
>                 goto err_unlock;
> @@ -826,7 +834,7 @@ int iio_read_max_channel_raw(struct iio_channel *chan, int *val)
>
>         ret = iio_channel_read_max(chan, val, NULL, &type, IIO_CHAN_INFO_RAW);
>  err_unlock:
> -       mutex_unlock(&chan->indio_dev->info_exist_lock);
> +       mutex_unlock(&iio_dev_opaque->info_exist_lock);
>
>         return ret;
>  }
> @@ -834,10 +842,11 @@ EXPORT_SYMBOL_GPL(iio_read_max_channel_raw);
>
>  int iio_get_channel_type(struct iio_channel *chan, enum iio_chan_type *type)
>  {
> +       struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
>         int ret = 0;
>         /* Need to verify underlying driver has not gone away */
>
> -       mutex_lock(&chan->indio_dev->info_exist_lock);
> +       mutex_lock(&iio_dev_opaque->info_exist_lock);
>         if (chan->indio_dev->info == NULL) {
>                 ret = -ENODEV;
>                 goto err_unlock;
> @@ -845,7 +854,7 @@ int iio_get_channel_type(struct iio_channel *chan, enum iio_chan_type *type)
>
>         *type = chan->channel->type;
>  err_unlock:
> -       mutex_unlock(&chan->indio_dev->info_exist_lock);
> +       mutex_unlock(&iio_dev_opaque->info_exist_lock);
>
>         return ret;
>  }
> @@ -861,9 +870,10 @@ static int iio_channel_write(struct iio_channel *chan, int val, int val2,
>  int iio_write_channel_attribute(struct iio_channel *chan, int val, int val2,
>                                 enum iio_chan_info_enum attribute)
>  {
> +       struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(chan->indio_dev);
>         int ret;
>
> -       mutex_lock(&chan->indio_dev->info_exist_lock);
> +       mutex_lock(&iio_dev_opaque->info_exist_lock);
>         if (chan->indio_dev->info == NULL) {
>                 ret = -ENODEV;
>                 goto err_unlock;
> @@ -871,7 +881,7 @@ int iio_write_channel_attribute(struct iio_channel *chan, int val, int val2,
>
>         ret = iio_channel_write(chan, val, val2, attribute);
>  err_unlock:
> -       mutex_unlock(&chan->indio_dev->info_exist_lock);
> +       mutex_unlock(&iio_dev_opaque->info_exist_lock);
>
>         return ret;
>  }
> diff --git a/include/linux/iio/iio-opaque.h b/include/linux/iio/iio-opaque.h
> index 02038fb2d291..538b4b5ef1a9 100644
> --- a/include/linux/iio/iio-opaque.h
> +++ b/include/linux/iio/iio-opaque.h
> @@ -8,6 +8,7 @@
>   * @indio_dev:                 public industrial I/O device information
>   * @id:                        used to identify device internally
>   * @driver_module:             used to make it harder to undercut users
> + * @info_exist_lock:           lock to prevent use during removal
>   * @trig_readonly:             mark the current trigger immutable
>   * @event_interface:           event chrdevs associated with interrupt lines
>   * @attached_buffers:          array of buffers statically attached by the driver
> @@ -32,6 +33,7 @@ struct iio_dev_opaque {
>         struct iio_dev                  indio_dev;
>         int                             id;
>         struct module                   *driver_module;
> +       struct mutex                    info_exist_lock;
>         bool                            trig_readonly;
>         struct iio_event_interface      *event_interface;
>         struct iio_buffer               **attached_buffers;
> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> index cbc9e9ece0a6..a12bbd8b1e74 100644
> --- a/include/linux/iio/iio.h
> +++ b/include/linux/iio/iio.h
> @@ -510,7 +510,6 @@ struct iio_buffer_setup_ops {
>   * @label:              [DRIVER] unique name to identify which device this is
>   * @info:              [DRIVER] callbacks and constant info from driver
>   * @clock_id:          [INTERN] timestamping clock posix identifier
> - * @info_exist_lock:   [INTERN] lock to prevent use during removal
>   * @setup_ops:         [DRIVER] callbacks to call before and after buffer
>   *                     enable/disable
>   * @chrdev:            [INTERN] associated character device
> @@ -542,7 +541,6 @@ struct iio_dev {
>         const char                      *label;
>         const struct iio_info           *info;
>         clockid_t                       clock_id;
> -       struct mutex                    info_exist_lock;
>         const struct iio_buffer_setup_ops       *setup_ops;
>         struct cdev                     chrdev;
>
> --
> 2.31.1
>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 7/9] iio: core: move @chrdev from struct iio_dev to struct iio_dev_opaque
  2021-04-26 17:49 ` [PATCH 7/9] iio: core: move @chrdev from struct iio_dev " Jonathan Cameron
@ 2021-04-27  8:06   ` Alexandru Ardelean
  2021-04-27 17:17     ` Jonathan Cameron
  0 siblings, 1 reply; 27+ messages in thread
From: Alexandru Ardelean @ 2021-04-27  8:06 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Jonathan Cameron

On Mon, Apr 26, 2021 at 8:50 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> No reason for this to be exposed to the drivers, so lets move it to the
> opaque structure.

Even though this looks straightforward, I am paranoid about it.
Mostly because of all the chardev juggling that I tried.

Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>

>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  drivers/iio/industrialio-core.c | 20 +++++++++++---------
>  include/linux/iio/iio-opaque.h  |  2 ++
>  include/linux/iio/iio.h         |  2 --
>  3 files changed, 13 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index f3b38d69b7e1..6fbe29f0b1de 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -1715,8 +1715,9 @@ EXPORT_SYMBOL_GPL(devm_iio_device_alloc);
>   **/
>  static int iio_chrdev_open(struct inode *inode, struct file *filp)
>  {
> -       struct iio_dev *indio_dev = container_of(inode->i_cdev,
> -                                               struct iio_dev, chrdev);
> +       struct iio_dev_opaque *iio_dev_opaque =
> +               container_of(inode->i_cdev, struct iio_dev_opaque, chrdev);
> +       struct iio_dev *indio_dev = &iio_dev_opaque->indio_dev;
>         struct iio_dev_buffer_pair *ib;
>
>         if (test_and_set_bit(IIO_BUSY_BIT_POS, &indio_dev->flags))
> @@ -1749,8 +1750,9 @@ static int iio_chrdev_open(struct inode *inode, struct file *filp)
>  static int iio_chrdev_release(struct inode *inode, struct file *filp)
>  {
>         struct iio_dev_buffer_pair *ib = filp->private_data;
> -       struct iio_dev *indio_dev = container_of(inode->i_cdev,
> -                                               struct iio_dev, chrdev);
> +       struct iio_dev_opaque *iio_dev_opaque =
> +               container_of(inode->i_cdev, struct iio_dev_opaque, chrdev);
> +       struct iio_dev *indio_dev = &iio_dev_opaque->indio_dev;
>         kfree(ib);
>         clear_bit(IIO_BUSY_BIT_POS, &indio_dev->flags);
>         iio_device_put(indio_dev);
> @@ -1901,19 +1903,19 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod)
>                 indio_dev->setup_ops = &noop_ring_setup_ops;
>
>         if (iio_dev_opaque->attached_buffers_cnt)
> -               cdev_init(&indio_dev->chrdev, &iio_buffer_fileops);
> +               cdev_init(&iio_dev_opaque->chrdev, &iio_buffer_fileops);
>         else if (iio_dev_opaque->event_interface)
> -               cdev_init(&indio_dev->chrdev, &iio_event_fileops);
> +               cdev_init(&iio_dev_opaque->chrdev, &iio_event_fileops);
>
>         if (iio_dev_opaque->attached_buffers_cnt || iio_dev_opaque->event_interface) {
>                 indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), iio_dev_opaque->id);
> -               indio_dev->chrdev.owner = this_mod;
> +               iio_dev_opaque->chrdev.owner = this_mod;
>         }
>
>         /* assign device groups now; they should be all registered now */
>         indio_dev->dev.groups = iio_dev_opaque->groups;
>
> -       ret = cdev_device_add(&indio_dev->chrdev, &indio_dev->dev);
> +       ret = cdev_device_add(&iio_dev_opaque->chrdev, &indio_dev->dev);
>         if (ret < 0)
>                 goto error_unreg_eventset;
>
> @@ -1940,7 +1942,7 @@ void iio_device_unregister(struct iio_dev *indio_dev)
>         struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
>         struct iio_ioctl_handler *h, *t;
>
> -       cdev_device_del(&indio_dev->chrdev, &indio_dev->dev);
> +       cdev_device_del(&iio_dev_opaque->chrdev, &indio_dev->dev);
>
>         mutex_lock(&iio_dev_opaque->info_exist_lock);
>
> diff --git a/include/linux/iio/iio-opaque.h b/include/linux/iio/iio-opaque.h
> index 538b4b5ef1a9..2f8ef5d15a66 100644
> --- a/include/linux/iio/iio-opaque.h
> +++ b/include/linux/iio/iio-opaque.h
> @@ -24,6 +24,7 @@
>   * @legacy_scan_el_group:      attribute group for legacy scan elements attribute group
>   * @legacy_buffer_group:       attribute group for legacy buffer attributes group
>   * @scan_index_timestamp:      cache of the index to the timestamp
> + * @chrdev:                    associated character device
>   * @debugfs_dentry:            device specific debugfs dentry
>   * @cached_reg_addr:           cached register address for debugfs reads
>   * @read_buf:                  read buffer to be used for the initial reg read
> @@ -49,6 +50,7 @@ struct iio_dev_opaque {
>         struct attribute_group          legacy_buffer_group;
>
>         unsigned int                    scan_index_timestamp;
> +       struct cdev                     chrdev;
>
>  #if defined(CONFIG_DEBUG_FS)
>         struct dentry                   *debugfs_dentry;
> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> index a12bbd8b1e74..586e2dc4fbf3 100644
> --- a/include/linux/iio/iio.h
> +++ b/include/linux/iio/iio.h
> @@ -512,7 +512,6 @@ struct iio_buffer_setup_ops {
>   * @clock_id:          [INTERN] timestamping clock posix identifier
>   * @setup_ops:         [DRIVER] callbacks to call before and after buffer
>   *                     enable/disable
> - * @chrdev:            [INTERN] associated character device
>   * @flags:             [INTERN] file ops related flags including busy flag.
>   * @priv:              [DRIVER] reference to driver's private information
>   *                     **MUST** be accessed **ONLY** via iio_priv() helper
> @@ -542,7 +541,6 @@ struct iio_dev {
>         const struct iio_info           *info;
>         clockid_t                       clock_id;
>         const struct iio_buffer_setup_ops       *setup_ops;
> -       struct cdev                     chrdev;
>
>         unsigned long                   flags;
>         void                            *priv;
> --
> 2.31.1
>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 8/9] iio: core: move @flags from struct iio_dev to struct iio_dev_opaque
  2021-04-26 17:49 ` [PATCH 8/9] iio: core: move @flags " Jonathan Cameron
@ 2021-04-27  8:07   ` Alexandru Ardelean
  0 siblings, 0 replies; 27+ messages in thread
From: Alexandru Ardelean @ 2021-04-27  8:07 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Jonathan Cameron

On Mon, Apr 26, 2021 at 8:50 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> No reason any driver should ever need access to this field, so hide it.
>


Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>


> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  drivers/iio/industrialio-core.c | 6 +++---
>  include/linux/iio/iio-opaque.h  | 2 ++
>  include/linux/iio/iio.h         | 2 --
>  3 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 6fbe29f0b1de..4a4c02fea152 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -1720,7 +1720,7 @@ static int iio_chrdev_open(struct inode *inode, struct file *filp)
>         struct iio_dev *indio_dev = &iio_dev_opaque->indio_dev;
>         struct iio_dev_buffer_pair *ib;
>
> -       if (test_and_set_bit(IIO_BUSY_BIT_POS, &indio_dev->flags))
> +       if (test_and_set_bit(IIO_BUSY_BIT_POS, &iio_dev_opaque->flags))
>                 return -EBUSY;
>
>         iio_device_get(indio_dev);
> @@ -1728,7 +1728,7 @@ static int iio_chrdev_open(struct inode *inode, struct file *filp)
>         ib = kmalloc(sizeof(*ib), GFP_KERNEL);
>         if (!ib) {
>                 iio_device_put(indio_dev);
> -               clear_bit(IIO_BUSY_BIT_POS, &indio_dev->flags);
> +               clear_bit(IIO_BUSY_BIT_POS, &iio_dev_opaque->flags);
>                 return -ENOMEM;
>         }
>
> @@ -1754,7 +1754,7 @@ static int iio_chrdev_release(struct inode *inode, struct file *filp)
>                 container_of(inode->i_cdev, struct iio_dev_opaque, chrdev);
>         struct iio_dev *indio_dev = &iio_dev_opaque->indio_dev;
>         kfree(ib);
> -       clear_bit(IIO_BUSY_BIT_POS, &indio_dev->flags);
> +       clear_bit(IIO_BUSY_BIT_POS, &iio_dev_opaque->flags);
>         iio_device_put(indio_dev);
>
>         return 0;
> diff --git a/include/linux/iio/iio-opaque.h b/include/linux/iio/iio-opaque.h
> index 2f8ef5d15a66..d7c3036861ac 100644
> --- a/include/linux/iio/iio-opaque.h
> +++ b/include/linux/iio/iio-opaque.h
> @@ -25,6 +25,7 @@
>   * @legacy_buffer_group:       attribute group for legacy buffer attributes group
>   * @scan_index_timestamp:      cache of the index to the timestamp
>   * @chrdev:                    associated character device
> + * @flags:                     file ops related flags including busy flag.
>   * @debugfs_dentry:            device specific debugfs dentry
>   * @cached_reg_addr:           cached register address for debugfs reads
>   * @read_buf:                  read buffer to be used for the initial reg read
> @@ -51,6 +52,7 @@ struct iio_dev_opaque {
>
>         unsigned int                    scan_index_timestamp;
>         struct cdev                     chrdev;
> +       unsigned long                   flags;
>
>  #if defined(CONFIG_DEBUG_FS)
>         struct dentry                   *debugfs_dentry;
> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> index 586e2dc4fbf3..ed0537015eee 100644
> --- a/include/linux/iio/iio.h
> +++ b/include/linux/iio/iio.h
> @@ -512,7 +512,6 @@ struct iio_buffer_setup_ops {
>   * @clock_id:          [INTERN] timestamping clock posix identifier
>   * @setup_ops:         [DRIVER] callbacks to call before and after buffer
>   *                     enable/disable
> - * @flags:             [INTERN] file ops related flags including busy flag.
>   * @priv:              [DRIVER] reference to driver's private information
>   *                     **MUST** be accessed **ONLY** via iio_priv() helper
>   */
> @@ -542,7 +541,6 @@ struct iio_dev {
>         clockid_t                       clock_id;
>         const struct iio_buffer_setup_ops       *setup_ops;
>
> -       unsigned long                   flags;
>         void                            *priv;
>  };
>
> --
> 2.31.1
>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 0/9] iio: Move more things from iio_dev to iio_dev_opaque
  2021-04-26 17:49 [PATCH 0/9] iio: Move more things from iio_dev to iio_dev_opaque Jonathan Cameron
                   ` (8 preceding siblings ...)
  2021-04-26 17:49 ` [PATCH 9/9] iio: core: move @clock_id " Jonathan Cameron
@ 2021-04-27  8:08 ` Alexandru Ardelean
  2021-04-27 17:12   ` Jonathan Cameron
  9 siblings, 1 reply; 27+ messages in thread
From: Alexandru Ardelean @ 2021-04-27  8:08 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Jonathan Cameron

On Mon, Apr 26, 2021 at 8:50 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> Intent here is to clear out the low hanging fruit so we can focus on the
> more interesting elements.
>
> Hopefully this set are all uncontroversial. Lightly tested only but
> all fairly mechanical so hopefully I didn't mess up.
>

Series looks good.
Thanks for moving this forward :)

Alex

> As for the others my current thinking is as follows
>
> mlock: Still some instances to clear out of this being used to protect things
> it should not be used for. Long run we definitely want to move this one.
>
> scan_timestamp: Can easily use a look up function in drivers that access this
> directly, but that feels like an unwanted level of indirection in
> iio_push_to_buffers_with_timestamp().  Perhaps worth doing anyway.
> scan_bytes is also used in this function.
>
> active_scan_mask and masklength: Both used in valid ways inside drivers.
> Could be wrapped up in access functions, but it does seem a little
> convoluted.
>
> trig: This is used correctly in lots of drivers, so should stay in
> struct iio_dev.
>
> Jonathan Cameron (9):
>   iio: core: move @id from struct iio_dev to struct iio_dev_opaque
>   iio: avoid shadowing of variable name in to_iio_dev_opaque()
>   iio: core: move @driver_module from struct iio_dev to struct
>     iio_dev_opaque
>   iio: core: move @trig_readonly from struct iio_dev to struct
>     iio_dev_opaque
>   iio: core: move @scan_index_timestamp to struct iio_dev_opaque
>   iio: core: move @info_exist_lock to struct iio_dev_opaque
>   iio: core: move @chrdev from struct iio_dev to struct iio_dev_opaque
>   iio: core: move @flags from struct iio_dev to struct iio_dev_opaque
>   iio: core: move @clock_id from struct iio_dev to struct iio_dev_opaque
>
>  drivers/iio/accel/adxl372.c                   |  4 +-
>  drivers/iio/accel/bma180.c                    |  2 +-
>  drivers/iio/accel/bmc150-accel-core.c         |  4 +-
>  drivers/iio/accel/kxcjk-1013.c                |  4 +-
>  drivers/iio/accel/mma8452.c                   |  2 +-
>  drivers/iio/accel/mxc4005.c                   |  2 +-
>  drivers/iio/accel/stk8312.c                   |  2 +-
>  drivers/iio/accel/stk8ba50.c                  |  2 +-
>  drivers/iio/adc/ad7606.c                      |  3 +-
>  drivers/iio/adc/ad7766.c                      |  3 +-
>  drivers/iio/adc/ad7768-1.c                    |  3 +-
>  drivers/iio/adc/ad_sigma_delta.c              |  2 +-
>  drivers/iio/adc/at91_adc.c                    |  4 +-
>  drivers/iio/adc/dln2-adc.c                    |  3 +-
>  drivers/iio/adc/ina2xx-adc.c                  |  3 +-
>  drivers/iio/adc/ti-ads131e08.c                |  2 +-
>  drivers/iio/adc/xilinx-xadc-core.c            |  2 +-
>  .../buffer/industrialio-triggered-buffer.c    |  2 +-
>  drivers/iio/chemical/atlas-sensor.c           |  2 +-
>  drivers/iio/chemical/ccs811.c                 |  2 +-
>  drivers/iio/chemical/scd30_core.c             |  3 +-
>  .../common/hid-sensors/hid-sensor-trigger.c   |  2 +-
>  drivers/iio/gyro/adxrs290.c                   |  2 +-
>  drivers/iio/gyro/bmg160_core.c                |  4 +-
>  drivers/iio/gyro/fxas21002c_core.c            |  2 +-
>  drivers/iio/gyro/itg3200_buffer.c             |  2 +-
>  drivers/iio/gyro/mpu3050-core.c               |  2 +-
>  drivers/iio/health/afe4403.c                  |  2 +-
>  drivers/iio/health/afe4404.c                  |  2 +-
>  drivers/iio/imu/adis_trigger.c                |  3 +-
>  drivers/iio/imu/bmi160/bmi160_core.c          |  3 +-
>  drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c |  2 +-
>  drivers/iio/imu/kmx61.c                       |  2 +-
>  drivers/iio/industrialio-buffer.c             | 12 ++-
>  drivers/iio/industrialio-core.c               | 76 +++++++++++++------
>  drivers/iio/industrialio-trigger.c            | 19 +++--
>  drivers/iio/industrialio-triggered-event.c    |  2 +-
>  drivers/iio/inkern.c                          | 46 ++++++-----
>  drivers/iio/light/acpi-als.c                  |  3 +-
>  drivers/iio/light/rpr0521.c                   |  2 +-
>  drivers/iio/light/si1145.c                    |  2 +-
>  drivers/iio/light/vcnl4000.c                  |  3 +-
>  drivers/iio/light/vcnl4035.c                  |  2 +-
>  drivers/iio/magnetometer/bmc150_magn.c        |  2 +-
>  drivers/iio/magnetometer/rm3100-core.c        |  2 +-
>  drivers/iio/potentiostat/lmp91000.c           |  3 +-
>  drivers/iio/pressure/zpa2326.c                |  3 +-
>  drivers/iio/proximity/as3935.c                |  3 +-
>  drivers/iio/proximity/sx9310.c                |  2 +-
>  drivers/iio/proximity/sx9500.c                |  2 +-
>  include/linux/iio/iio-opaque.h                | 22 +++++-
>  include/linux/iio/iio.h                       | 29 +------
>  52 files changed, 188 insertions(+), 131 deletions(-)
>
> --
> 2.31.1
>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 0/9] iio: Move more things from iio_dev to iio_dev_opaque
  2021-04-27  8:08 ` [PATCH 0/9] iio: Move more things from iio_dev to iio_dev_opaque Alexandru Ardelean
@ 2021-04-27 17:12   ` Jonathan Cameron
  2021-04-28  6:55     ` Alexandru Ardelean
  0 siblings, 1 reply; 27+ messages in thread
From: Jonathan Cameron @ 2021-04-27 17:12 UTC (permalink / raw)
  To: Alexandru Ardelean; +Cc: linux-iio, Jonathan Cameron

On Tue, 27 Apr 2021 11:08:52 +0300
Alexandru Ardelean <ardeleanalex@gmail.com> wrote:

> On Mon, Apr 26, 2021 at 8:50 PM Jonathan Cameron <jic23@kernel.org> wrote:
> >
> > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> >
> > Intent here is to clear out the low hanging fruit so we can focus on the
> > more interesting elements.
> >
> > Hopefully this set are all uncontroversial. Lightly tested only but
> > all fairly mechanical so hopefully I didn't mess up.
> >  
> 
> Series looks good.
> Thanks for moving this forward :)
no problem.

One thing.  You gave tags for all but it seems patch 3.
Fine if I also put your tag on that one?

> 
> Alex
> 
> > As for the others my current thinking is as follows
> >
> > mlock: Still some instances to clear out of this being used to protect things
> > it should not be used for. Long run we definitely want to move this one.
> >
> > scan_timestamp: Can easily use a look up function in drivers that access this
> > directly, but that feels like an unwanted level of indirection in
> > iio_push_to_buffers_with_timestamp().  Perhaps worth doing anyway.
> > scan_bytes is also used in this function.
> >
> > active_scan_mask and masklength: Both used in valid ways inside drivers.
> > Could be wrapped up in access functions, but it does seem a little
> > convoluted.
> >
> > trig: This is used correctly in lots of drivers, so should stay in
> > struct iio_dev.
> >
> > Jonathan Cameron (9):
> >   iio: core: move @id from struct iio_dev to struct iio_dev_opaque
> >   iio: avoid shadowing of variable name in to_iio_dev_opaque()
> >   iio: core: move @driver_module from struct iio_dev to struct
> >     iio_dev_opaque
> >   iio: core: move @trig_readonly from struct iio_dev to struct
> >     iio_dev_opaque
> >   iio: core: move @scan_index_timestamp to struct iio_dev_opaque
> >   iio: core: move @info_exist_lock to struct iio_dev_opaque
> >   iio: core: move @chrdev from struct iio_dev to struct iio_dev_opaque
> >   iio: core: move @flags from struct iio_dev to struct iio_dev_opaque
> >   iio: core: move @clock_id from struct iio_dev to struct iio_dev_opaque
> >
> >  drivers/iio/accel/adxl372.c                   |  4 +-
> >  drivers/iio/accel/bma180.c                    |  2 +-
> >  drivers/iio/accel/bmc150-accel-core.c         |  4 +-
> >  drivers/iio/accel/kxcjk-1013.c                |  4 +-
> >  drivers/iio/accel/mma8452.c                   |  2 +-
> >  drivers/iio/accel/mxc4005.c                   |  2 +-
> >  drivers/iio/accel/stk8312.c                   |  2 +-
> >  drivers/iio/accel/stk8ba50.c                  |  2 +-
> >  drivers/iio/adc/ad7606.c                      |  3 +-
> >  drivers/iio/adc/ad7766.c                      |  3 +-
> >  drivers/iio/adc/ad7768-1.c                    |  3 +-
> >  drivers/iio/adc/ad_sigma_delta.c              |  2 +-
> >  drivers/iio/adc/at91_adc.c                    |  4 +-
> >  drivers/iio/adc/dln2-adc.c                    |  3 +-
> >  drivers/iio/adc/ina2xx-adc.c                  |  3 +-
> >  drivers/iio/adc/ti-ads131e08.c                |  2 +-
> >  drivers/iio/adc/xilinx-xadc-core.c            |  2 +-
> >  .../buffer/industrialio-triggered-buffer.c    |  2 +-
> >  drivers/iio/chemical/atlas-sensor.c           |  2 +-
> >  drivers/iio/chemical/ccs811.c                 |  2 +-
> >  drivers/iio/chemical/scd30_core.c             |  3 +-
> >  .../common/hid-sensors/hid-sensor-trigger.c   |  2 +-
> >  drivers/iio/gyro/adxrs290.c                   |  2 +-
> >  drivers/iio/gyro/bmg160_core.c                |  4 +-
> >  drivers/iio/gyro/fxas21002c_core.c            |  2 +-
> >  drivers/iio/gyro/itg3200_buffer.c             |  2 +-
> >  drivers/iio/gyro/mpu3050-core.c               |  2 +-
> >  drivers/iio/health/afe4403.c                  |  2 +-
> >  drivers/iio/health/afe4404.c                  |  2 +-
> >  drivers/iio/imu/adis_trigger.c                |  3 +-
> >  drivers/iio/imu/bmi160/bmi160_core.c          |  3 +-
> >  drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c |  2 +-
> >  drivers/iio/imu/kmx61.c                       |  2 +-
> >  drivers/iio/industrialio-buffer.c             | 12 ++-
> >  drivers/iio/industrialio-core.c               | 76 +++++++++++++------
> >  drivers/iio/industrialio-trigger.c            | 19 +++--
> >  drivers/iio/industrialio-triggered-event.c    |  2 +-
> >  drivers/iio/inkern.c                          | 46 ++++++-----
> >  drivers/iio/light/acpi-als.c                  |  3 +-
> >  drivers/iio/light/rpr0521.c                   |  2 +-
> >  drivers/iio/light/si1145.c                    |  2 +-
> >  drivers/iio/light/vcnl4000.c                  |  3 +-
> >  drivers/iio/light/vcnl4035.c                  |  2 +-
> >  drivers/iio/magnetometer/bmc150_magn.c        |  2 +-
> >  drivers/iio/magnetometer/rm3100-core.c        |  2 +-
> >  drivers/iio/potentiostat/lmp91000.c           |  3 +-
> >  drivers/iio/pressure/zpa2326.c                |  3 +-
> >  drivers/iio/proximity/as3935.c                |  3 +-
> >  drivers/iio/proximity/sx9310.c                |  2 +-
> >  drivers/iio/proximity/sx9500.c                |  2 +-
> >  include/linux/iio/iio-opaque.h                | 22 +++++-
> >  include/linux/iio/iio.h                       | 29 +------
> >  52 files changed, 188 insertions(+), 131 deletions(-)
> >
> > --
> > 2.31.1
> >  


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/9] iio: core: move @id from struct iio_dev to struct iio_dev_opaque
  2021-04-27  7:44   ` Alexandru Ardelean
@ 2021-04-27 17:16     ` Jonathan Cameron
  0 siblings, 0 replies; 27+ messages in thread
From: Jonathan Cameron @ 2021-04-27 17:16 UTC (permalink / raw)
  To: Alexandru Ardelean; +Cc: linux-iio, Jonathan Cameron

On Tue, 27 Apr 2021 10:44:29 +0300
Alexandru Ardelean <ardeleanalex@gmail.com> wrote:

> On Mon, Apr 26, 2021 at 8:50 PM Jonathan Cameron <jic23@kernel.org> wrote:
> >
> > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> >
> > Continuing from Alexandru Ardelean's introduction of the split between
> > driver modifiable fields and those that should only be set by the core.
> >
> > This could have been done in two steps to make the actual move after
> > introducing iio_device_id() but there seemed limited point to that
> > given how mechanical the majority of the patch is.
> >  
> 
> The way I was thinking [initially] about moving this, is to somehow
> try to unify/generalize the {devm_}iio_trigger_alloc() function.
> It looks like the IIO device ID is needed only there.
> Maybe there is a good solution for this; maybe if we just provide the
> fmt string, and have a convention that the IIO device name and ID are
> filled in.
> Though that's tricky.

With hindsight we should have standardized the IIO trigger naming
suffix, but we can't do it now and I think we have cases with multiple
elements in their format string so it would be non obvious.

Mostly it's the last element but not in at91-adc where it's in the
middle of two other parameters.

> 
> But this iio_device_id() getter is also a good approach for now.
> 
> Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>
> 
> > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > ---
> >  drivers/iio/accel/adxl372.c                   |  4 ++--
> >  drivers/iio/accel/bma180.c                    |  2 +-
> >  drivers/iio/accel/bmc150-accel-core.c         |  4 ++--
> >  drivers/iio/accel/kxcjk-1013.c                |  4 ++--
> >  drivers/iio/accel/mma8452.c                   |  2 +-
> >  drivers/iio/accel/mxc4005.c                   |  2 +-
> >  drivers/iio/accel/stk8312.c                   |  2 +-
> >  drivers/iio/accel/stk8ba50.c                  |  2 +-
> >  drivers/iio/adc/ad7606.c                      |  3 ++-
> >  drivers/iio/adc/ad7766.c                      |  3 ++-
> >  drivers/iio/adc/ad7768-1.c                    |  3 ++-
> >  drivers/iio/adc/ad_sigma_delta.c              |  2 +-
> >  drivers/iio/adc/at91_adc.c                    |  4 ++--
> >  drivers/iio/adc/dln2-adc.c                    |  3 ++-
> >  drivers/iio/adc/ina2xx-adc.c                  |  3 ++-
> >  drivers/iio/adc/ti-ads131e08.c                |  2 +-
> >  drivers/iio/adc/xilinx-xadc-core.c            |  2 +-
> >  .../buffer/industrialio-triggered-buffer.c    |  2 +-
> >  drivers/iio/chemical/atlas-sensor.c           |  2 +-
> >  drivers/iio/chemical/ccs811.c                 |  2 +-
> >  drivers/iio/chemical/scd30_core.c             |  3 ++-
> >  .../common/hid-sensors/hid-sensor-trigger.c   |  2 +-
> >  drivers/iio/gyro/adxrs290.c                   |  2 +-
> >  drivers/iio/gyro/bmg160_core.c                |  4 ++--
> >  drivers/iio/gyro/fxas21002c_core.c            |  2 +-
> >  drivers/iio/gyro/itg3200_buffer.c             |  2 +-
> >  drivers/iio/gyro/mpu3050-core.c               |  2 +-
> >  drivers/iio/health/afe4403.c                  |  2 +-
> >  drivers/iio/health/afe4404.c                  |  2 +-
> >  drivers/iio/imu/adis_trigger.c                |  3 ++-
> >  drivers/iio/imu/bmi160/bmi160_core.c          |  3 ++-
> >  drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c |  2 +-
> >  drivers/iio/imu/kmx61.c                       |  2 +-
> >  drivers/iio/industrialio-core.c               | 24 +++++++++++++++----
> >  drivers/iio/industrialio-triggered-event.c    |  2 +-
> >  drivers/iio/light/acpi-als.c                  |  3 ++-
> >  drivers/iio/light/rpr0521.c                   |  2 +-
> >  drivers/iio/light/si1145.c                    |  2 +-
> >  drivers/iio/light/vcnl4000.c                  |  3 ++-
> >  drivers/iio/light/vcnl4035.c                  |  2 +-
> >  drivers/iio/magnetometer/bmc150_magn.c        |  2 +-
> >  drivers/iio/magnetometer/rm3100-core.c        |  2 +-
> >  drivers/iio/potentiostat/lmp91000.c           |  3 ++-
> >  drivers/iio/pressure/zpa2326.c                |  3 ++-
> >  drivers/iio/proximity/as3935.c                |  3 ++-
> >  drivers/iio/proximity/sx9310.c                |  2 +-
> >  drivers/iio/proximity/sx9500.c                |  2 +-
> >  include/linux/iio/iio-opaque.h                |  2 ++
> >  include/linux/iio/iio.h                       |  4 ++--
> >  49 files changed, 87 insertions(+), 58 deletions(-)
> >
> > diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c
> > index 9c9a896a872a..fc9592407717 100644
> > --- a/drivers/iio/accel/adxl372.c
> > +++ b/drivers/iio/accel/adxl372.c
> > @@ -1223,14 +1223,14 @@ int adxl372_probe(struct device *dev, struct regmap *regmap,
> >                 st->dready_trig = devm_iio_trigger_alloc(dev,
> >                                                          "%s-dev%d",
> >                                                          indio_dev->name,
> > -                                                        indio_dev->id);
> > +                                                        iio_device_id(indio_dev));
> >                 if (st->dready_trig == NULL)
> >                         return -ENOMEM;
> >
> >                 st->peak_datardy_trig = devm_iio_trigger_alloc(dev,
> >                                                                "%s-dev%d-peak",
> >                                                                indio_dev->name,
> > -                                                              indio_dev->id);
> > +                                                              iio_device_id(indio_dev));
> >                 if (!st->peak_datardy_trig)
> >                         return -ENOMEM;
> >
> > diff --git a/drivers/iio/accel/bma180.c b/drivers/iio/accel/bma180.c
> > index b8a7469cdae4..68d91a70de03 100644
> > --- a/drivers/iio/accel/bma180.c
> > +++ b/drivers/iio/accel/bma180.c
> > @@ -1045,7 +1045,7 @@ static int bma180_probe(struct i2c_client *client,
> >
> >         if (client->irq > 0) {
> >                 data->trig = iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name,
> > -                       indio_dev->id);
> > +                                              iio_device_id(indio_dev));
> >                 if (!data->trig) {
> >                         ret = -ENOMEM;
> >                         goto err_chip_disable;
> > diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
> > index 04d85ce34e9f..62a164a7b852 100644
> > --- a/drivers/iio/accel/bmc150-accel-core.c
> > +++ b/drivers/iio/accel/bmc150-accel-core.c
> > @@ -1470,9 +1470,9 @@ static int bmc150_accel_triggers_setup(struct iio_dev *indio_dev,
> >                 struct bmc150_accel_trigger *t = &data->triggers[i];
> >
> >                 t->indio_trig = devm_iio_trigger_alloc(dev,
> > -                                       bmc150_accel_triggers[i].name,
> > +                                                      bmc150_accel_triggers[i].name,
> >                                                        indio_dev->name,
> > -                                                      indio_dev->id);
> > +                                                      iio_device_id(indio_dev));
> >                 if (!t->indio_trig) {
> >                         ret = -ENOMEM;
> >                         break;
> > diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c
> > index ff724bc17a45..283e6a3feffc 100644
> > --- a/drivers/iio/accel/kxcjk-1013.c
> > +++ b/drivers/iio/accel/kxcjk-1013.c
> > @@ -1404,7 +1404,7 @@ static int kxcjk1013_probe(struct i2c_client *client,
> >                 data->dready_trig = devm_iio_trigger_alloc(&client->dev,
> >                                                            "%s-dev%d",
> >                                                            indio_dev->name,
> > -                                                          indio_dev->id);
> > +                                                          iio_device_id(indio_dev));
> >                 if (!data->dready_trig) {
> >                         ret = -ENOMEM;
> >                         goto err_poweroff;
> > @@ -1413,7 +1413,7 @@ static int kxcjk1013_probe(struct i2c_client *client,
> >                 data->motion_trig = devm_iio_trigger_alloc(&client->dev,
> >                                                           "%s-any-motion-dev%d",
> >                                                           indio_dev->name,
> > -                                                         indio_dev->id);
> > +                                                         iio_device_id(indio_dev));
> >                 if (!data->motion_trig) {
> >                         ret = -ENOMEM;
> >                         goto err_poweroff;
> > diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
> > index 4d307dfb9169..464a6bfe6746 100644
> > --- a/drivers/iio/accel/mma8452.c
> > +++ b/drivers/iio/accel/mma8452.c
> > @@ -1461,7 +1461,7 @@ static int mma8452_trigger_setup(struct iio_dev *indio_dev)
> >
> >         trig = devm_iio_trigger_alloc(&data->client->dev, "%s-dev%d",
> >                                       indio_dev->name,
> > -                                     indio_dev->id);
> > +                                     iio_device_id(indio_dev));
> >         if (!trig)
> >                 return -ENOMEM;
> >
> > diff --git a/drivers/iio/accel/mxc4005.c b/drivers/iio/accel/mxc4005.c
> > index fb3cbaa62bd8..98c7f5f59011 100644
> > --- a/drivers/iio/accel/mxc4005.c
> > +++ b/drivers/iio/accel/mxc4005.c
> > @@ -433,7 +433,7 @@ static int mxc4005_probe(struct i2c_client *client,
> >                 data->dready_trig = devm_iio_trigger_alloc(&client->dev,
> >                                                            "%s-dev%d",
> >                                                            indio_dev->name,
> > -                                                          indio_dev->id);
> > +                                                          iio_device_id(indio_dev));
> >                 if (!data->dready_trig)
> >                         return -ENOMEM;
> >
> > diff --git a/drivers/iio/accel/stk8312.c b/drivers/iio/accel/stk8312.c
> > index 60aecfa9fd92..aeab108c457d 100644
> > --- a/drivers/iio/accel/stk8312.c
> > +++ b/drivers/iio/accel/stk8312.c
> > @@ -552,7 +552,7 @@ static int stk8312_probe(struct i2c_client *client,
> >                 data->dready_trig = devm_iio_trigger_alloc(&client->dev,
> >                                                            "%s-dev%d",
> >                                                            indio_dev->name,
> > -                                                          indio_dev->id);
> > +                                                          iio_device_id(indio_dev));
> >                 if (!data->dready_trig) {
> >                         ret = -ENOMEM;
> >                         goto err_power_off;
> > diff --git a/drivers/iio/accel/stk8ba50.c b/drivers/iio/accel/stk8ba50.c
> > index 7cf9cb7e8666..3e7cf23be7e1 100644
> > --- a/drivers/iio/accel/stk8ba50.c
> > +++ b/drivers/iio/accel/stk8ba50.c
> > @@ -448,7 +448,7 @@ static int stk8ba50_probe(struct i2c_client *client,
> >                 data->dready_trig = devm_iio_trigger_alloc(&client->dev,
> >                                                            "%s-dev%d",
> >                                                            indio_dev->name,
> > -                                                          indio_dev->id);
> > +                                                          iio_device_id(indio_dev));
> >                 if (!data->dready_trig) {
> >                         ret = -ENOMEM;
> >                         goto err_power_off;
> > diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
> > index 0af0bb4d5a7f..0a60ecc69d38 100644
> > --- a/drivers/iio/adc/ad7606.c
> > +++ b/drivers/iio/adc/ad7606.c
> > @@ -663,7 +663,8 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
> >         }
> >
> >         st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
> > -                                         indio_dev->name, indio_dev->id);
> > +                                         indio_dev->name,
> > +                                         iio_device_id(indio_dev));
> >         if (!st->trig)
> >                 return -ENOMEM;
> >
> > diff --git a/drivers/iio/adc/ad7766.c b/drivers/iio/adc/ad7766.c
> > index 1e41759f3ee5..236a455aaa18 100644
> > --- a/drivers/iio/adc/ad7766.c
> > +++ b/drivers/iio/adc/ad7766.c
> > @@ -248,7 +248,8 @@ static int ad7766_probe(struct spi_device *spi)
> >
> >         if (spi->irq > 0) {
> >                 ad7766->trig = devm_iio_trigger_alloc(&spi->dev, "%s-dev%d",
> > -                       indio_dev->name, indio_dev->id);
> > +                                                     indio_dev->name,
> > +                                                     iio_device_id(indio_dev));
> >                 if (!ad7766->trig)
> >                         return -ENOMEM;
> >
> > diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c
> > index c945f1349623..41752777e96c 100644
> > --- a/drivers/iio/adc/ad7768-1.c
> > +++ b/drivers/iio/adc/ad7768-1.c
> > @@ -626,7 +626,8 @@ static int ad7768_probe(struct spi_device *spi)
> >         }
> >
> >         st->trig = devm_iio_trigger_alloc(&spi->dev, "%s-dev%d",
> > -                                         indio_dev->name, indio_dev->id);
> > +                                         indio_dev->name,
> > +                                         iio_device_id(indio_dev));
> >         if (!st->trig)
> >                 return -ENOMEM;
> >
> > diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
> > index e777ec718973..69b979331ccd 100644
> > --- a/drivers/iio/adc/ad_sigma_delta.c
> > +++ b/drivers/iio/adc/ad_sigma_delta.c
> > @@ -477,7 +477,7 @@ static int ad_sd_probe_trigger(struct iio_dev *indio_dev)
> >
> >         sigma_delta->trig = iio_trigger_alloc(&sigma_delta->spi->dev,
> >                                               "%s-dev%d", indio_dev->name,
> > -                                             indio_dev->id);
> > +                                             iio_device_id(indio_dev));
> >         if (sigma_delta->trig == NULL) {
> >                 ret = -ENOMEM;
> >                 goto error_ret;
> > diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
> > index 0b5f0c91d0d7..5a7d3a3a5fa8 100644
> > --- a/drivers/iio/adc/at91_adc.c
> > +++ b/drivers/iio/adc/at91_adc.c
> > @@ -547,7 +547,7 @@ static int at91_adc_get_trigger_value_by_name(struct iio_dev *idev,
> >                 char *name = kasprintf(GFP_KERNEL,
> >                                 "%s-dev%d-%s",
> >                                 idev->name,
> > -                               idev->id,
> > +                               iio_device_id(idev),
> >                                 triggers[i].name);
> >                 if (!name)
> >                         return -ENOMEM;
> > @@ -626,7 +626,7 @@ static struct iio_trigger *at91_adc_allocate_trigger(struct iio_dev *idev,
> >         int ret;
> >
> >         trig = iio_trigger_alloc(idev->dev.parent, "%s-dev%d-%s", idev->name,
> > -                                idev->id, trigger->name);
> > +                                iio_device_id(idev), trigger->name);
> >         if (trig == NULL)
> >                 return NULL;
> >
> > diff --git a/drivers/iio/adc/dln2-adc.c b/drivers/iio/adc/dln2-adc.c
> > index 0d53ef18e045..16407664182c 100644
> > --- a/drivers/iio/adc/dln2-adc.c
> > +++ b/drivers/iio/adc/dln2-adc.c
> > @@ -649,7 +649,8 @@ static int dln2_adc_probe(struct platform_device *pdev)
> >         indio_dev->setup_ops = &dln2_adc_buffer_setup_ops;
> >
> >         dln2->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
> > -                                           indio_dev->name, indio_dev->id);
> > +                                           indio_dev->name,
> > +                                           iio_device_id(indio_dev));
> >         if (!dln2->trig) {
> >                 dev_err(dev, "failed to allocate trigger\n");
> >                 return -ENOMEM;
> > diff --git a/drivers/iio/adc/ina2xx-adc.c b/drivers/iio/adc/ina2xx-adc.c
> > index 2ae54258b221..a4b2ff9e0dd5 100644
> > --- a/drivers/iio/adc/ina2xx-adc.c
> > +++ b/drivers/iio/adc/ina2xx-adc.c
> > @@ -843,7 +843,8 @@ static int ina2xx_buffer_enable(struct iio_dev *indio_dev)
> >                 chip->allow_async_readout);
> >
> >         task = kthread_create(ina2xx_capture_thread, (void *)indio_dev,
> > -                             "%s:%d-%uus", indio_dev->name, indio_dev->id,
> > +                             "%s:%d-%uus", indio_dev->name,
> > +                             iio_device_id(indio_dev),
> >                               sampling_us);
> >         if (IS_ERR(task))
> >                 return PTR_ERR(task);
> > diff --git a/drivers/iio/adc/ti-ads131e08.c b/drivers/iio/adc/ti-ads131e08.c
> > index 0060d5f0abb0..5dcf1e9294d7 100644
> > --- a/drivers/iio/adc/ti-ads131e08.c
> > +++ b/drivers/iio/adc/ti-ads131e08.c
> > @@ -844,7 +844,7 @@ static int ads131e08_probe(struct spi_device *spi)
> >         }
> >
> >         st->trig = devm_iio_trigger_alloc(&spi->dev, "%s-dev%d",
> > -               indio_dev->name, indio_dev->id);
> > +               indio_dev->name, iio_device_id(indio_dev));
> >         if (!st->trig) {
> >                 dev_err(&spi->dev, "failed to allocate IIO trigger\n");
> >                 return -ENOMEM;
> > diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c
> > index 6914c1900ed0..198d2916266d 100644
> > --- a/drivers/iio/adc/xilinx-xadc-core.c
> > +++ b/drivers/iio/adc/xilinx-xadc-core.c
> > @@ -743,7 +743,7 @@ static struct iio_trigger *xadc_alloc_trigger(struct iio_dev *indio_dev,
> >         int ret;
> >
> >         trig = devm_iio_trigger_alloc(dev, "%s%d-%s", indio_dev->name,
> > -                                     indio_dev->id, name);
> > +                                     iio_device_id(indio_dev), name);
> >         if (trig == NULL)
> >                 return ERR_PTR(-ENOMEM);
> >
> > diff --git a/drivers/iio/buffer/industrialio-triggered-buffer.c b/drivers/iio/buffer/industrialio-triggered-buffer.c
> > index ebb4520ac291..f77c4538141e 100644
> > --- a/drivers/iio/buffer/industrialio-triggered-buffer.c
> > +++ b/drivers/iio/buffer/industrialio-triggered-buffer.c
> > @@ -56,7 +56,7 @@ int iio_triggered_buffer_setup_ext(struct iio_dev *indio_dev,
> >                                                  indio_dev,
> >                                                  "%s_consumer%d",
> >                                                  indio_dev->name,
> > -                                                indio_dev->id);
> > +                                                iio_device_id(indio_dev));
> >         if (indio_dev->pollfunc == NULL) {
> >                 ret = -ENOMEM;
> >                 goto error_kfifo_free;
> > diff --git a/drivers/iio/chemical/atlas-sensor.c b/drivers/iio/chemical/atlas-sensor.c
> > index 56ba6c82b501..d10f921b233a 100644
> > --- a/drivers/iio/chemical/atlas-sensor.c
> > +++ b/drivers/iio/chemical/atlas-sensor.c
> > @@ -640,7 +640,7 @@ static int atlas_probe(struct i2c_client *client,
> >         indio_dev->modes = INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE;
> >
> >         trig = devm_iio_trigger_alloc(&client->dev, "%s-dev%d",
> > -                                     indio_dev->name, indio_dev->id);
> > +                                     indio_dev->name, iio_device_id(indio_dev));
> >
> >         if (!trig)
> >                 return -ENOMEM;
> > diff --git a/drivers/iio/chemical/ccs811.c b/drivers/iio/chemical/ccs811.c
> > index 886e96496dbf..847194fa1e46 100644
> > --- a/drivers/iio/chemical/ccs811.c
> > +++ b/drivers/iio/chemical/ccs811.c
> > @@ -491,7 +491,7 @@ static int ccs811_probe(struct i2c_client *client,
> >                 data->drdy_trig = devm_iio_trigger_alloc(&client->dev,
> >                                                          "%s-dev%d",
> >                                                          indio_dev->name,
> > -                                                        indio_dev->id);
> > +                                                        iio_device_id(indio_dev));
> >                 if (!data->drdy_trig) {
> >                         ret = -ENOMEM;
> >                         goto err_poweroff;
> > diff --git a/drivers/iio/chemical/scd30_core.c b/drivers/iio/chemical/scd30_core.c
> > index d89f117dd0ef..9fe6bbe9ee04 100644
> > --- a/drivers/iio/chemical/scd30_core.c
> > +++ b/drivers/iio/chemical/scd30_core.c
> > @@ -640,7 +640,8 @@ static int scd30_setup_trigger(struct iio_dev *indio_dev)
> >         struct iio_trigger *trig;
> >         int ret;
> >
> > -       trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, indio_dev->id);
> > +       trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name,
> > +                                     iio_device_id(indio_dev));
> >         if (!trig) {
> >                 dev_err(dev, "failed to allocate trigger\n");
> >                 return -ENOMEM;
> > diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
> > index 95ddccb44f1c..5a7b3e253e58 100644
> > --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
> > +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
> > @@ -256,7 +256,7 @@ int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
> >         }
> >
> >         trig = iio_trigger_alloc(indio_dev->dev.parent,
> > -                                "%s-dev%d", name, indio_dev->id);
> > +                                "%s-dev%d", name, iio_device_id(indio_dev));
> >         if (trig == NULL) {
> >                 dev_err(&indio_dev->dev, "Trigger Allocate Failed\n");
> >                 ret = -ENOMEM;
> > diff --git a/drivers/iio/gyro/adxrs290.c b/drivers/iio/gyro/adxrs290.c
> > index cec5e1f17c22..3e0734ddafe3 100644
> > --- a/drivers/iio/gyro/adxrs290.c
> > +++ b/drivers/iio/gyro/adxrs290.c
> > @@ -589,7 +589,7 @@ static int adxrs290_probe_trigger(struct iio_dev *indio_dev)
> >
> >         st->dready_trig = devm_iio_trigger_alloc(&st->spi->dev, "%s-dev%d",
> >                                                  indio_dev->name,
> > -                                                indio_dev->id);
> > +                                                iio_device_id(indio_dev));
> >         if (!st->dready_trig)
> >                 return -ENOMEM;
> >
> > diff --git a/drivers/iio/gyro/bmg160_core.c b/drivers/iio/gyro/bmg160_core.c
> > index b11ebd9bb7a4..26a9ed5770c6 100644
> > --- a/drivers/iio/gyro/bmg160_core.c
> > +++ b/drivers/iio/gyro/bmg160_core.c
> > @@ -1137,14 +1137,14 @@ int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq,
> >                 data->dready_trig = devm_iio_trigger_alloc(dev,
> >                                                            "%s-dev%d",
> >                                                            indio_dev->name,
> > -                                                          indio_dev->id);
> > +                                                          iio_device_id(indio_dev));
> >                 if (!data->dready_trig)
> >                         return -ENOMEM;
> >
> >                 data->motion_trig = devm_iio_trigger_alloc(dev,
> >                                                           "%s-any-motion-dev%d",
> >                                                           indio_dev->name,
> > -                                                         indio_dev->id);
> > +                                                         iio_device_id(indio_dev));
> >                 if (!data->motion_trig)
> >                         return -ENOMEM;
> >
> > diff --git a/drivers/iio/gyro/fxas21002c_core.c b/drivers/iio/gyro/fxas21002c_core.c
> > index 1a20c6b88e7d..5af7b48ff01a 100644
> > --- a/drivers/iio/gyro/fxas21002c_core.c
> > +++ b/drivers/iio/gyro/fxas21002c_core.c
> > @@ -852,7 +852,7 @@ static int fxas21002c_trigger_probe(struct fxas21002c_data *data)
> >
> >         data->dready_trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
> >                                                    indio_dev->name,
> > -                                                  indio_dev->id);
> > +                                                  iio_device_id(indio_dev));
> >         if (!data->dready_trig)
> >                 return -ENOMEM;
> >
> > diff --git a/drivers/iio/gyro/itg3200_buffer.c b/drivers/iio/gyro/itg3200_buffer.c
> > index af0aaa146f0c..04dd6a7969ea 100644
> > --- a/drivers/iio/gyro/itg3200_buffer.c
> > +++ b/drivers/iio/gyro/itg3200_buffer.c
> > @@ -114,7 +114,7 @@ int itg3200_probe_trigger(struct iio_dev *indio_dev)
> >         struct itg3200 *st = iio_priv(indio_dev);
> >
> >         st->trig = iio_trigger_alloc(&st->i2c->dev, "%s-dev%d", indio_dev->name,
> > -                                    indio_dev->id);
> > +                                    iio_device_id(indio_dev));
> >         if (!st->trig)
> >                 return -ENOMEM;
> >
> > diff --git a/drivers/iio/gyro/mpu3050-core.c b/drivers/iio/gyro/mpu3050-core.c
> > index ac90be03332a..131e6f54948e 100644
> > --- a/drivers/iio/gyro/mpu3050-core.c
> > +++ b/drivers/iio/gyro/mpu3050-core.c
> > @@ -1049,7 +1049,7 @@ static int mpu3050_trigger_probe(struct iio_dev *indio_dev, int irq)
> >         mpu3050->trig = devm_iio_trigger_alloc(&indio_dev->dev,
> >                                                "%s-dev%d",
> >                                                indio_dev->name,
> > -                                              indio_dev->id);
> > +                                              iio_device_id(indio_dev));
> >         if (!mpu3050->trig)
> >                 return -ENOMEM;
> >
> > diff --git a/drivers/iio/health/afe4403.c b/drivers/iio/health/afe4403.c
> > index 1fa8d51d5080..d4921385aaf7 100644
> > --- a/drivers/iio/health/afe4403.c
> > +++ b/drivers/iio/health/afe4403.c
> > @@ -521,7 +521,7 @@ static int afe4403_probe(struct spi_device *spi)
> >                 afe->trig = devm_iio_trigger_alloc(afe->dev,
> >                                                    "%s-dev%d",
> >                                                    indio_dev->name,
> > -                                                  indio_dev->id);
> > +                                                  iio_device_id(indio_dev));
> >                 if (!afe->trig) {
> >                         dev_err(afe->dev, "Unable to allocate IIO trigger\n");
> >                         ret = -ENOMEM;
> > diff --git a/drivers/iio/health/afe4404.c b/drivers/iio/health/afe4404.c
> > index e1476bf79fe2..d8a27dfe074a 100644
> > --- a/drivers/iio/health/afe4404.c
> > +++ b/drivers/iio/health/afe4404.c
> > @@ -528,7 +528,7 @@ static int afe4404_probe(struct i2c_client *client,
> >                 afe->trig = devm_iio_trigger_alloc(afe->dev,
> >                                                    "%s-dev%d",
> >                                                    indio_dev->name,
> > -                                                  indio_dev->id);
> > +                                                  iio_device_id(indio_dev));
> >                 if (!afe->trig) {
> >                         dev_err(afe->dev, "Unable to allocate IIO trigger\n");
> >                         ret = -ENOMEM;
> > diff --git a/drivers/iio/imu/adis_trigger.c b/drivers/iio/imu/adis_trigger.c
> > index fa5540fabacc..48eedc29b28a 100644
> > --- a/drivers/iio/imu/adis_trigger.c
> > +++ b/drivers/iio/imu/adis_trigger.c
> > @@ -62,7 +62,8 @@ int devm_adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev)
> >         int ret;
> >
> >         adis->trig = devm_iio_trigger_alloc(&adis->spi->dev, "%s-dev%d",
> > -                                           indio_dev->name, indio_dev->id);
> > +                                           indio_dev->name,
> > +                                           iio_device_id(indio_dev));
> >         if (!adis->trig)
> >                 return -ENOMEM;
> >
> > diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c
> > index 290b5ef83f77..b63bd7e5e5e5 100644
> > --- a/drivers/iio/imu/bmi160/bmi160_core.c
> > +++ b/drivers/iio/imu/bmi160/bmi160_core.c
> > @@ -785,7 +785,8 @@ int bmi160_probe_trigger(struct iio_dev *indio_dev, int irq, u32 irq_type)
> >         int ret;
> >
> >         data->trig = devm_iio_trigger_alloc(&indio_dev->dev, "%s-dev%d",
> > -                                           indio_dev->name, indio_dev->id);
> > +                                           indio_dev->name,
> > +                                           iio_device_id(indio_dev));
> >
> >         if (data->trig == NULL)
> >                 return -ENOMEM;
> > diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
> > index de8ed1446d60..e21ba778595a 100644
> > --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
> > +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
> > @@ -238,7 +238,7 @@ int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev, int irq_type)
> >         st->trig = devm_iio_trigger_alloc(&indio_dev->dev,
> >                                           "%s-dev%d",
> >                                           indio_dev->name,
> > -                                         indio_dev->id);
> > +                                         iio_device_id(indio_dev));
> >         if (!st->trig)
> >                 return -ENOMEM;
> >
> > diff --git a/drivers/iio/imu/kmx61.c b/drivers/iio/imu/kmx61.c
> > index fc5a60fcfec0..d3e06ce99c1e 100644
> > --- a/drivers/iio/imu/kmx61.c
> > +++ b/drivers/iio/imu/kmx61.c
> > @@ -1264,7 +1264,7 @@ static struct iio_trigger *kmx61_trigger_setup(struct kmx61_data *data,
> >                                       "%s-%s-dev%d",
> >                                       indio_dev->name,
> >                                       tag,
> > -                                     indio_dev->id);
> > +                                     iio_device_id(indio_dev));
> >         if (!trig)
> >                 return ERR_PTR(-ENOMEM);
> >
> > diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> > index 022198c32e32..c16b8f344c93 100644
> > --- a/drivers/iio/industrialio-core.c
> > +++ b/drivers/iio/industrialio-core.c
> > @@ -169,6 +169,20 @@ static const char * const iio_chan_info_postfix[] = {
> >         [IIO_CHAN_INFO_THERMOCOUPLE_TYPE] = "thermocouple_type",
> >         [IIO_CHAN_INFO_CALIBAMBIENT] = "calibambient",
> >  };
> > +/**
> > + * iio_device_id() - query the unique ID for the device
> > + * @indio_dev:         Device structure whose ID is being queried
> > + *
> > + * The IIO device ID is a unique index used for example for the naming
> > + * of the character device /dev/iio\:device[ID]
> > + */
> > +int iio_device_id(struct iio_dev *indio_dev)
> > +{
> > +       struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
> > +
> > +       return iio_dev_opaque->id;
> > +}
> > +EXPORT_SYMBOL_GPL(iio_device_id);
> >
> >  /**
> >   * iio_sysfs_match_string_with_gaps - matches given string in an array with gaps
> > @@ -1588,7 +1602,7 @@ static void iio_dev_release(struct device *device)
> >
> >         iio_device_detach_buffers(indio_dev);
> >
> > -       ida_simple_remove(&iio_ida, indio_dev->id);
> > +       ida_simple_remove(&iio_ida, iio_dev_opaque->id);
> >         kfree(iio_dev_opaque);
> >  }
> >
> > @@ -1631,14 +1645,14 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)
> >         mutex_init(&indio_dev->info_exist_lock);
> >         INIT_LIST_HEAD(&iio_dev_opaque->channel_attr_list);
> >
> > -       indio_dev->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL);
> > -       if (indio_dev->id < 0) {
> > +       iio_dev_opaque->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL);
> > +       if (iio_dev_opaque->id < 0) {
> >                 /* cannot use a dev_err as the name isn't available */
> >                 pr_err("failed to get device id\n");
> >                 kfree(iio_dev_opaque);
> >                 return NULL;
> >         }
> > -       dev_set_name(&indio_dev->dev, "iio:device%d", indio_dev->id);
> > +       dev_set_name(&indio_dev->dev, "iio:device%d", iio_dev_opaque->id);
> >         INIT_LIST_HEAD(&iio_dev_opaque->buffer_list);
> >         INIT_LIST_HEAD(&iio_dev_opaque->ioctl_handlers);
> >
> > @@ -1892,7 +1906,7 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod)
> >                 cdev_init(&indio_dev->chrdev, &iio_event_fileops);
> >
> >         if (iio_dev_opaque->attached_buffers_cnt || iio_dev_opaque->event_interface) {
> > -               indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), indio_dev->id);
> > +               indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), iio_dev_opaque->id);
> >                 indio_dev->chrdev.owner = this_mod;
> >         }
> >
> > diff --git a/drivers/iio/industrialio-triggered-event.c b/drivers/iio/industrialio-triggered-event.c
> > index 53da9ab17a62..4bedc65c9fe3 100644
> > --- a/drivers/iio/industrialio-triggered-event.c
> > +++ b/drivers/iio/industrialio-triggered-event.c
> > @@ -37,7 +37,7 @@ int iio_triggered_event_setup(struct iio_dev *indio_dev,
> >                                                        indio_dev,
> >                                                        "%s_consumer%d",
> >                                                        indio_dev->name,
> > -                                                      indio_dev->id);
> > +                                                      iio_device_id(indio_dev));
> >         if (indio_dev->pollfunc_event == NULL)
> >                 return -ENOMEM;
> >
> > diff --git a/drivers/iio/light/acpi-als.c b/drivers/iio/light/acpi-als.c
> > index 30393f08e082..260f96ea5f3c 100644
> > --- a/drivers/iio/light/acpi-als.c
> > +++ b/drivers/iio/light/acpi-als.c
> > @@ -206,7 +206,8 @@ static int acpi_als_add(struct acpi_device *device)
> >         indio_dev->channels = acpi_als_channels;
> >         indio_dev->num_channels = ARRAY_SIZE(acpi_als_channels);
> >
> > -       als->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, indio_dev->id);
> > +       als->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name,
> > +                                          iio_device_id(indio_dev));
> >         if (!als->trig)
> >                 return -ENOMEM;
> >
> > diff --git a/drivers/iio/light/rpr0521.c b/drivers/iio/light/rpr0521.c
> > index 033578f444e4..7e332de0e6a5 100644
> > --- a/drivers/iio/light/rpr0521.c
> > +++ b/drivers/iio/light/rpr0521.c
> > @@ -985,7 +985,7 @@ static int rpr0521_probe(struct i2c_client *client,
> >                 /* Trigger0 producer setup */
> >                 data->drdy_trigger0 = devm_iio_trigger_alloc(
> >                         indio_dev->dev.parent,
> > -                       "%s-dev%d", indio_dev->name, indio_dev->id);
> > +                       "%s-dev%d", indio_dev->name, iio_device_id(indio_dev));
> >                 if (!data->drdy_trigger0) {
> >                         ret = -ENOMEM;
> >                         goto err_pm_disable;
> > diff --git a/drivers/iio/light/si1145.c b/drivers/iio/light/si1145.c
> > index 9b5c99823943..3fb52402fcc3 100644
> > --- a/drivers/iio/light/si1145.c
> > +++ b/drivers/iio/light/si1145.c
> > @@ -1243,7 +1243,7 @@ static int si1145_probe_trigger(struct iio_dev *indio_dev)
> >         int ret;
> >
> >         trig = devm_iio_trigger_alloc(&client->dev,
> > -                       "%s-dev%d", indio_dev->name, indio_dev->id);
> > +                       "%s-dev%d", indio_dev->name, iio_device_id(indio_dev));
> >         if (!trig)
> >                 return -ENOMEM;
> >
> > diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
> > index 2f7916f95689..4a61865d01cd 100644
> > --- a/drivers/iio/light/vcnl4000.c
> > +++ b/drivers/iio/light/vcnl4000.c
> > @@ -998,7 +998,8 @@ static int vcnl4010_probe_trigger(struct iio_dev *indio_dev)
> >         struct iio_trigger *trigger;
> >
> >         trigger = devm_iio_trigger_alloc(&client->dev, "%s-dev%d",
> > -                                        indio_dev->name, indio_dev->id);
> > +                                        indio_dev->name,
> > +                                        iio_device_id(indio_dev));
> >         if (!trigger)
> >                 return -ENOMEM;
> >
> > diff --git a/drivers/iio/light/vcnl4035.c b/drivers/iio/light/vcnl4035.c
> > index ae87740d9cef..691a54b763e1 100644
> > --- a/drivers/iio/light/vcnl4035.c
> > +++ b/drivers/iio/light/vcnl4035.c
> > @@ -507,7 +507,7 @@ static int vcnl4035_probe_trigger(struct iio_dev *indio_dev)
> >
> >         data->drdy_trigger0 = devm_iio_trigger_alloc(
> >                         indio_dev->dev.parent,
> > -                       "%s-dev%d", indio_dev->name, indio_dev->id);
> > +                       "%s-dev%d", indio_dev->name, iio_device_id(indio_dev));
> >         if (!data->drdy_trigger0)
> >                 return -ENOMEM;
> >
> > diff --git a/drivers/iio/magnetometer/bmc150_magn.c b/drivers/iio/magnetometer/bmc150_magn.c
> > index 00f9766bad5c..d75b437a43f2 100644
> > --- a/drivers/iio/magnetometer/bmc150_magn.c
> > +++ b/drivers/iio/magnetometer/bmc150_magn.c
> > @@ -915,7 +915,7 @@ int bmc150_magn_probe(struct device *dev, struct regmap *regmap,
> >                 data->dready_trig = devm_iio_trigger_alloc(dev,
> >                                                            "%s-dev%d",
> >                                                            indio_dev->name,
> > -                                                          indio_dev->id);
> > +                                                          iio_device_id(indio_dev));
> >                 if (!data->dready_trig) {
> >                         ret = -ENOMEM;
> >                         dev_err(dev, "iio trigger alloc failed\n");
> > diff --git a/drivers/iio/magnetometer/rm3100-core.c b/drivers/iio/magnetometer/rm3100-core.c
> > index dd811da9cb6d..4df5887fd04c 100644
> > --- a/drivers/iio/magnetometer/rm3100-core.c
> > +++ b/drivers/iio/magnetometer/rm3100-core.c
> > @@ -575,7 +575,7 @@ int rm3100_common_probe(struct device *dev, struct regmap *regmap, int irq)
> >
> >                 data->drdy_trig = devm_iio_trigger_alloc(dev, "%s-drdy%d",
> >                                                          indio_dev->name,
> > -                                                        indio_dev->id);
> > +                                                        iio_device_id(indio_dev));
> >                 if (!data->drdy_trig)
> >                         return -ENOMEM;
> >
> > diff --git a/drivers/iio/potentiostat/lmp91000.c b/drivers/iio/potentiostat/lmp91000.c
> > index 8a9c576616ee..1948e2d22c27 100644
> > --- a/drivers/iio/potentiostat/lmp91000.c
> > +++ b/drivers/iio/potentiostat/lmp91000.c
> > @@ -323,7 +323,8 @@ static int lmp91000_probe(struct i2c_client *client,
> >         }
> >
> >         data->trig = devm_iio_trigger_alloc(dev, "%s-mux%d",
> > -                                           indio_dev->name, indio_dev->id);
> > +                                           indio_dev->name,
> > +                                           iio_device_id(indio_dev));
> >         if (!data->trig) {
> >                 dev_err(dev, "cannot allocate iio trigger.\n");
> >                 return -ENOMEM;
> > diff --git a/drivers/iio/pressure/zpa2326.c b/drivers/iio/pressure/zpa2326.c
> > index a93411216aee..89295c90f801 100644
> > --- a/drivers/iio/pressure/zpa2326.c
> > +++ b/drivers/iio/pressure/zpa2326.c
> > @@ -1408,7 +1408,8 @@ static int zpa2326_init_managed_trigger(struct device          *parent,
> >                 return 0;
> >
> >         trigger = devm_iio_trigger_alloc(parent, "%s-dev%d",
> > -                                        indio_dev->name, indio_dev->id);
> > +                                        indio_dev->name,
> > +                                        iio_device_id(indio_dev));
> >         if (!trigger)
> >                 return -ENOMEM;
> >
> > diff --git a/drivers/iio/proximity/as3935.c b/drivers/iio/proximity/as3935.c
> > index edc4a35ae66d..dc20fe81232c 100644
> > --- a/drivers/iio/proximity/as3935.c
> > +++ b/drivers/iio/proximity/as3935.c
> > @@ -404,7 +404,8 @@ static int as3935_probe(struct spi_device *spi)
> >         indio_dev->info = &as3935_info;
> >
> >         trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
> > -                                     indio_dev->name, indio_dev->id);
> > +                                     indio_dev->name,
> > +                                     iio_device_id(indio_dev));
> >
> >         if (!trig)
> >                 return -ENOMEM;
> > diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c
> > index 327ebb7ddbb9..175f3b7c61d7 100644
> > --- a/drivers/iio/proximity/sx9310.c
> > +++ b/drivers/iio/proximity/sx9310.c
> > @@ -1473,7 +1473,7 @@ static int sx9310_probe(struct i2c_client *client)
> >
> >                 data->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
> >                                                     indio_dev->name,
> > -                                                   indio_dev->id);
> > +                                                   iio_device_id(indio_dev));
> >                 if (!data->trig)
> >                         return -ENOMEM;
> >
> > diff --git a/drivers/iio/proximity/sx9500.c b/drivers/iio/proximity/sx9500.c
> > index a87f4a8e4327..3e4ddb2e8c2b 100644
> > --- a/drivers/iio/proximity/sx9500.c
> > +++ b/drivers/iio/proximity/sx9500.c
> > @@ -946,7 +946,7 @@ static int sx9500_probe(struct i2c_client *client,
> >                         return ret;
> >
> >                 data->trig = devm_iio_trigger_alloc(&client->dev,
> > -                               "%s-dev%d", indio_dev->name, indio_dev->id);
> > +                               "%s-dev%d", indio_dev->name, iio_device_id(indio_dev));
> >                 if (!data->trig)
> >                         return -ENOMEM;
> >
> > diff --git a/include/linux/iio/iio-opaque.h b/include/linux/iio/iio-opaque.h
> > index 32addd5e790e..e66b029d99de 100644
> > --- a/include/linux/iio/iio-opaque.h
> > +++ b/include/linux/iio/iio-opaque.h
> > @@ -6,6 +6,7 @@
> >  /**
> >   * struct iio_dev_opaque - industrial I/O device opaque information
> >   * @indio_dev:                 public industrial I/O device information
> > + * @id:                        used to identify device internally
> >   * @event_interface:           event chrdevs associated with interrupt lines
> >   * @attached_buffers:          array of buffers statically attached by the driver
> >   * @attached_buffers_cnt:      number of buffers in the array of statically attached buffers
> > @@ -26,6 +27,7 @@
> >   */
> >  struct iio_dev_opaque {
> >         struct iio_dev                  indio_dev;
> > +       int                             id;
> >         struct iio_event_interface      *event_interface;
> >         struct iio_buffer               **attached_buffers;
> >         unsigned int                    attached_buffers_cnt;
> > diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> > index f2d65e2e88b6..569861d5887a 100644
> > --- a/include/linux/iio/iio.h
> > +++ b/include/linux/iio/iio.h
> > @@ -488,7 +488,6 @@ struct iio_buffer_setup_ops {
> >
> >  /**
> >   * struct iio_dev - industrial I/O device
> > - * @id:                        [INTERN] used to identify device internally
> >   * @driver_module:     [INTERN] used to make it harder to undercut users
> >   * @modes:             [DRIVER] operating modes supported by device
> >   * @currentmode:       [DRIVER] current operating mode
> > @@ -523,7 +522,6 @@ struct iio_buffer_setup_ops {
> >   *                     **MUST** be accessed **ONLY** via iio_priv() helper
> >   */
> >  struct iio_dev {
> > -       int                             id;
> >         struct module                   *driver_module;
> >
> >         int                             modes;
> > @@ -559,6 +557,8 @@ struct iio_dev {
> >         void                            *priv;
> >  };
> >
> > +int iio_device_id(struct iio_dev *indio_dev);
> > +
> >  const struct iio_chan_spec
> >  *iio_find_channel_from_si(struct iio_dev *indio_dev, int si);
> >  /**
> > --
> > 2.31.1
> >  


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 7/9] iio: core: move @chrdev from struct iio_dev to struct iio_dev_opaque
  2021-04-27  8:06   ` Alexandru Ardelean
@ 2021-04-27 17:17     ` Jonathan Cameron
  0 siblings, 0 replies; 27+ messages in thread
From: Jonathan Cameron @ 2021-04-27 17:17 UTC (permalink / raw)
  To: Alexandru Ardelean; +Cc: linux-iio, Jonathan Cameron

On Tue, 27 Apr 2021 11:06:56 +0300
Alexandru Ardelean <ardeleanalex@gmail.com> wrote:

> On Mon, Apr 26, 2021 at 8:50 PM Jonathan Cameron <jic23@kernel.org> wrote:
> >
> > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> >
> > No reason for this to be exposed to the drivers, so lets move it to the
> > opaque structure.  
> 
> Even though this looks straightforward, I am paranoid about it.
> Mostly because of all the chardev juggling that I tried.
Yup. Several of these needed to wait for that work to be in place
so could really be done until now (when things are generally
somewhat cleaner than they were!)

Jonathan

> 
> Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>
> 
> >
> > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > ---
> >  drivers/iio/industrialio-core.c | 20 +++++++++++---------
> >  include/linux/iio/iio-opaque.h  |  2 ++
> >  include/linux/iio/iio.h         |  2 --
> >  3 files changed, 13 insertions(+), 11 deletions(-)
> >
> > diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> > index f3b38d69b7e1..6fbe29f0b1de 100644
> > --- a/drivers/iio/industrialio-core.c
> > +++ b/drivers/iio/industrialio-core.c
> > @@ -1715,8 +1715,9 @@ EXPORT_SYMBOL_GPL(devm_iio_device_alloc);
> >   **/
> >  static int iio_chrdev_open(struct inode *inode, struct file *filp)
> >  {
> > -       struct iio_dev *indio_dev = container_of(inode->i_cdev,
> > -                                               struct iio_dev, chrdev);
> > +       struct iio_dev_opaque *iio_dev_opaque =
> > +               container_of(inode->i_cdev, struct iio_dev_opaque, chrdev);
> > +       struct iio_dev *indio_dev = &iio_dev_opaque->indio_dev;
> >         struct iio_dev_buffer_pair *ib;
> >
> >         if (test_and_set_bit(IIO_BUSY_BIT_POS, &indio_dev->flags))
> > @@ -1749,8 +1750,9 @@ static int iio_chrdev_open(struct inode *inode, struct file *filp)
> >  static int iio_chrdev_release(struct inode *inode, struct file *filp)
> >  {
> >         struct iio_dev_buffer_pair *ib = filp->private_data;
> > -       struct iio_dev *indio_dev = container_of(inode->i_cdev,
> > -                                               struct iio_dev, chrdev);
> > +       struct iio_dev_opaque *iio_dev_opaque =
> > +               container_of(inode->i_cdev, struct iio_dev_opaque, chrdev);
> > +       struct iio_dev *indio_dev = &iio_dev_opaque->indio_dev;
> >         kfree(ib);
> >         clear_bit(IIO_BUSY_BIT_POS, &indio_dev->flags);
> >         iio_device_put(indio_dev);
> > @@ -1901,19 +1903,19 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod)
> >                 indio_dev->setup_ops = &noop_ring_setup_ops;
> >
> >         if (iio_dev_opaque->attached_buffers_cnt)
> > -               cdev_init(&indio_dev->chrdev, &iio_buffer_fileops);
> > +               cdev_init(&iio_dev_opaque->chrdev, &iio_buffer_fileops);
> >         else if (iio_dev_opaque->event_interface)
> > -               cdev_init(&indio_dev->chrdev, &iio_event_fileops);
> > +               cdev_init(&iio_dev_opaque->chrdev, &iio_event_fileops);
> >
> >         if (iio_dev_opaque->attached_buffers_cnt || iio_dev_opaque->event_interface) {
> >                 indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), iio_dev_opaque->id);
> > -               indio_dev->chrdev.owner = this_mod;
> > +               iio_dev_opaque->chrdev.owner = this_mod;
> >         }
> >
> >         /* assign device groups now; they should be all registered now */
> >         indio_dev->dev.groups = iio_dev_opaque->groups;
> >
> > -       ret = cdev_device_add(&indio_dev->chrdev, &indio_dev->dev);
> > +       ret = cdev_device_add(&iio_dev_opaque->chrdev, &indio_dev->dev);
> >         if (ret < 0)
> >                 goto error_unreg_eventset;
> >
> > @@ -1940,7 +1942,7 @@ void iio_device_unregister(struct iio_dev *indio_dev)
> >         struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
> >         struct iio_ioctl_handler *h, *t;
> >
> > -       cdev_device_del(&indio_dev->chrdev, &indio_dev->dev);
> > +       cdev_device_del(&iio_dev_opaque->chrdev, &indio_dev->dev);
> >
> >         mutex_lock(&iio_dev_opaque->info_exist_lock);
> >
> > diff --git a/include/linux/iio/iio-opaque.h b/include/linux/iio/iio-opaque.h
> > index 538b4b5ef1a9..2f8ef5d15a66 100644
> > --- a/include/linux/iio/iio-opaque.h
> > +++ b/include/linux/iio/iio-opaque.h
> > @@ -24,6 +24,7 @@
> >   * @legacy_scan_el_group:      attribute group for legacy scan elements attribute group
> >   * @legacy_buffer_group:       attribute group for legacy buffer attributes group
> >   * @scan_index_timestamp:      cache of the index to the timestamp
> > + * @chrdev:                    associated character device
> >   * @debugfs_dentry:            device specific debugfs dentry
> >   * @cached_reg_addr:           cached register address for debugfs reads
> >   * @read_buf:                  read buffer to be used for the initial reg read
> > @@ -49,6 +50,7 @@ struct iio_dev_opaque {
> >         struct attribute_group          legacy_buffer_group;
> >
> >         unsigned int                    scan_index_timestamp;
> > +       struct cdev                     chrdev;
> >
> >  #if defined(CONFIG_DEBUG_FS)
> >         struct dentry                   *debugfs_dentry;
> > diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> > index a12bbd8b1e74..586e2dc4fbf3 100644
> > --- a/include/linux/iio/iio.h
> > +++ b/include/linux/iio/iio.h
> > @@ -512,7 +512,6 @@ struct iio_buffer_setup_ops {
> >   * @clock_id:          [INTERN] timestamping clock posix identifier
> >   * @setup_ops:         [DRIVER] callbacks to call before and after buffer
> >   *                     enable/disable
> > - * @chrdev:            [INTERN] associated character device
> >   * @flags:             [INTERN] file ops related flags including busy flag.
> >   * @priv:              [DRIVER] reference to driver's private information
> >   *                     **MUST** be accessed **ONLY** via iio_priv() helper
> > @@ -542,7 +541,6 @@ struct iio_dev {
> >         const struct iio_info           *info;
> >         clockid_t                       clock_id;
> >         const struct iio_buffer_setup_ops       *setup_ops;
> > -       struct cdev                     chrdev;
> >
> >         unsigned long                   flags;
> >         void                            *priv;
> > --
> > 2.31.1
> >  


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 9/9] iio: core: move @clock_id from struct iio_dev to struct iio_dev_opaque
  2021-04-27  8:02   ` Alexandru Ardelean
@ 2021-04-27 17:19     ` Jonathan Cameron
  0 siblings, 0 replies; 27+ messages in thread
From: Jonathan Cameron @ 2021-04-27 17:19 UTC (permalink / raw)
  To: Alexandru Ardelean; +Cc: linux-iio, Jonathan Cameron

On Tue, 27 Apr 2021 11:02:02 +0300
Alexandru Ardelean <ardeleanalex@gmail.com> wrote:

> On Mon, Apr 26, 2021 at 8:50 PM Jonathan Cameron <jic23@kernel.org> wrote:
> >
> > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> >
> > There is already an acessor function used to access it, making this
> > move straight forward.  
> 
> Right now the iio_device_get_clock() helper is only being used in the
> Chrome EC core sensor driver.
> Maybe later if that can be reworked without this helper, then it could
> be made private to IIO core.
> Though, chances are some other driver may come along later and ask for
> it to be public again.

Agreed. My gut feeling is this will come up again (largely because some
idiot who will remain nameless picked a silly default clock many years
ago when he didn't know better).

Jonathan

> 
> Anyway.
> 
> Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>
> 
> >
> > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > ---
> >  drivers/iio/industrialio-core.c | 14 +++++++++++++-
> >  include/linux/iio/iio-opaque.h  |  2 ++
> >  include/linux/iio/iio.h         | 12 +-----------
> >  3 files changed, 16 insertions(+), 12 deletions(-)
> >
> > diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> > index 4a4c02fea152..efb4cf91c9e4 100644
> > --- a/drivers/iio/industrialio-core.c
> > +++ b/drivers/iio/industrialio-core.c
> > @@ -271,13 +271,25 @@ int iio_device_set_clock(struct iio_dev *indio_dev, clockid_t clock_id)
> >                 mutex_unlock(&indio_dev->mlock);
> >                 return -EBUSY;
> >         }
> > -       indio_dev->clock_id = clock_id;
> > +       iio_dev_opaque->clock_id = clock_id;
> >         mutex_unlock(&indio_dev->mlock);
> >
> >         return 0;
> >  }
> >  EXPORT_SYMBOL(iio_device_set_clock);
> >
> > +/**
> > + * iio_device_get_clock() - Retrieve current timestamping clock for the device
> > + * @indio_dev: IIO device structure containing the device
> > + */
> > +clockid_t iio_device_get_clock(const struct iio_dev *indio_dev)
> > +{
> > +       struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
> > +
> > +       return iio_dev_opaque->clock_id;
> > +}
> > +EXPORT_SYMBOL(iio_device_get_clock);
> > +
> >  /**
> >   * iio_get_time_ns() - utility function to get a time stamp for events etc
> >   * @indio_dev: device
> > diff --git a/include/linux/iio/iio-opaque.h b/include/linux/iio/iio-opaque.h
> > index d7c3036861ac..c9504e9da571 100644
> > --- a/include/linux/iio/iio-opaque.h
> > +++ b/include/linux/iio/iio-opaque.h
> > @@ -24,6 +24,7 @@
> >   * @legacy_scan_el_group:      attribute group for legacy scan elements attribute group
> >   * @legacy_buffer_group:       attribute group for legacy buffer attributes group
> >   * @scan_index_timestamp:      cache of the index to the timestamp
> > + * @clock_id:                  timestamping clock posix identifier
> >   * @chrdev:                    associated character device
> >   * @flags:                     file ops related flags including busy flag.
> >   * @debugfs_dentry:            device specific debugfs dentry
> > @@ -51,6 +52,7 @@ struct iio_dev_opaque {
> >         struct attribute_group          legacy_buffer_group;
> >
> >         unsigned int                    scan_index_timestamp;
> > +       clockid_t                       clock_id;
> >         struct cdev                     chrdev;
> >         unsigned long                   flags;
> >
> > diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> > index ed0537015eee..5606a3f4c4cb 100644
> > --- a/include/linux/iio/iio.h
> > +++ b/include/linux/iio/iio.h
> > @@ -509,7 +509,6 @@ struct iio_buffer_setup_ops {
> >   * @name:              [DRIVER] name of the device.
> >   * @label:              [DRIVER] unique name to identify which device this is
> >   * @info:              [DRIVER] callbacks and constant info from driver
> > - * @clock_id:          [INTERN] timestamping clock posix identifier
> >   * @setup_ops:         [DRIVER] callbacks to call before and after buffer
> >   *                     enable/disable
> >   * @priv:              [DRIVER] reference to driver's private information
> > @@ -538,7 +537,6 @@ struct iio_dev {
> >         const char                      *name;
> >         const char                      *label;
> >         const struct iio_info           *info;
> > -       clockid_t                       clock_id;
> >         const struct iio_buffer_setup_ops       *setup_ops;
> >
> >         void                            *priv;
> > @@ -589,15 +587,7 @@ static inline void iio_device_put(struct iio_dev *indio_dev)
> >                 put_device(&indio_dev->dev);
> >  }
> >
> > -/**
> > - * iio_device_get_clock() - Retrieve current timestamping clock for the device
> > - * @indio_dev: IIO device structure containing the device
> > - */
> > -static inline clockid_t iio_device_get_clock(const struct iio_dev *indio_dev)
> > -{
> > -       return indio_dev->clock_id;
> > -}
> > -
> > +clockid_t iio_device_get_clock(const struct iio_dev *indio_dev);
> >  int iio_device_set_clock(struct iio_dev *indio_dev, clockid_t clock_id);
> >
> >  /**
> > --
> > 2.31.1
> >  


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 0/9] iio: Move more things from iio_dev to iio_dev_opaque
  2021-04-27 17:12   ` Jonathan Cameron
@ 2021-04-28  6:55     ` Alexandru Ardelean
  2021-05-03 11:53       ` Jonathan Cameron
  0 siblings, 1 reply; 27+ messages in thread
From: Alexandru Ardelean @ 2021-04-28  6:55 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Jonathan Cameron

On Tue, Apr 27, 2021 at 8:11 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> On Tue, 27 Apr 2021 11:08:52 +0300
> Alexandru Ardelean <ardeleanalex@gmail.com> wrote:
>
> > On Mon, Apr 26, 2021 at 8:50 PM Jonathan Cameron <jic23@kernel.org> wrote:
> > >
> > > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > >
> > > Intent here is to clear out the low hanging fruit so we can focus on the
> > > more interesting elements.
> > >
> > > Hopefully this set are all uncontroversial. Lightly tested only but
> > > all fairly mechanical so hopefully I didn't mess up.
> > >
> >
> > Series looks good.
> > Thanks for moving this forward :)
> no problem.
>
> One thing.  You gave tags for all but it seems patch 3.
> Fine if I also put your tag on that one?

Yes.
I may have missed it.
I usually have reviews in the morning before starting some other work
and drinking my coffee.

>
> >
> > Alex
> >
> > > As for the others my current thinking is as follows
> > >
> > > mlock: Still some instances to clear out of this being used to protect things
> > > it should not be used for. Long run we definitely want to move this one.
> > >
> > > scan_timestamp: Can easily use a look up function in drivers that access this
> > > directly, but that feels like an unwanted level of indirection in
> > > iio_push_to_buffers_with_timestamp().  Perhaps worth doing anyway.
> > > scan_bytes is also used in this function.
> > >
> > > active_scan_mask and masklength: Both used in valid ways inside drivers.
> > > Could be wrapped up in access functions, but it does seem a little
> > > convoluted.
> > >
> > > trig: This is used correctly in lots of drivers, so should stay in
> > > struct iio_dev.
> > >
> > > Jonathan Cameron (9):
> > >   iio: core: move @id from struct iio_dev to struct iio_dev_opaque
> > >   iio: avoid shadowing of variable name in to_iio_dev_opaque()
> > >   iio: core: move @driver_module from struct iio_dev to struct
> > >     iio_dev_opaque
> > >   iio: core: move @trig_readonly from struct iio_dev to struct
> > >     iio_dev_opaque
> > >   iio: core: move @scan_index_timestamp to struct iio_dev_opaque
> > >   iio: core: move @info_exist_lock to struct iio_dev_opaque
> > >   iio: core: move @chrdev from struct iio_dev to struct iio_dev_opaque
> > >   iio: core: move @flags from struct iio_dev to struct iio_dev_opaque
> > >   iio: core: move @clock_id from struct iio_dev to struct iio_dev_opaque
> > >
> > >  drivers/iio/accel/adxl372.c                   |  4 +-
> > >  drivers/iio/accel/bma180.c                    |  2 +-
> > >  drivers/iio/accel/bmc150-accel-core.c         |  4 +-
> > >  drivers/iio/accel/kxcjk-1013.c                |  4 +-
> > >  drivers/iio/accel/mma8452.c                   |  2 +-
> > >  drivers/iio/accel/mxc4005.c                   |  2 +-
> > >  drivers/iio/accel/stk8312.c                   |  2 +-
> > >  drivers/iio/accel/stk8ba50.c                  |  2 +-
> > >  drivers/iio/adc/ad7606.c                      |  3 +-
> > >  drivers/iio/adc/ad7766.c                      |  3 +-
> > >  drivers/iio/adc/ad7768-1.c                    |  3 +-
> > >  drivers/iio/adc/ad_sigma_delta.c              |  2 +-
> > >  drivers/iio/adc/at91_adc.c                    |  4 +-
> > >  drivers/iio/adc/dln2-adc.c                    |  3 +-
> > >  drivers/iio/adc/ina2xx-adc.c                  |  3 +-
> > >  drivers/iio/adc/ti-ads131e08.c                |  2 +-
> > >  drivers/iio/adc/xilinx-xadc-core.c            |  2 +-
> > >  .../buffer/industrialio-triggered-buffer.c    |  2 +-
> > >  drivers/iio/chemical/atlas-sensor.c           |  2 +-
> > >  drivers/iio/chemical/ccs811.c                 |  2 +-
> > >  drivers/iio/chemical/scd30_core.c             |  3 +-
> > >  .../common/hid-sensors/hid-sensor-trigger.c   |  2 +-
> > >  drivers/iio/gyro/adxrs290.c                   |  2 +-
> > >  drivers/iio/gyro/bmg160_core.c                |  4 +-
> > >  drivers/iio/gyro/fxas21002c_core.c            |  2 +-
> > >  drivers/iio/gyro/itg3200_buffer.c             |  2 +-
> > >  drivers/iio/gyro/mpu3050-core.c               |  2 +-
> > >  drivers/iio/health/afe4403.c                  |  2 +-
> > >  drivers/iio/health/afe4404.c                  |  2 +-
> > >  drivers/iio/imu/adis_trigger.c                |  3 +-
> > >  drivers/iio/imu/bmi160/bmi160_core.c          |  3 +-
> > >  drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c |  2 +-
> > >  drivers/iio/imu/kmx61.c                       |  2 +-
> > >  drivers/iio/industrialio-buffer.c             | 12 ++-
> > >  drivers/iio/industrialio-core.c               | 76 +++++++++++++------
> > >  drivers/iio/industrialio-trigger.c            | 19 +++--
> > >  drivers/iio/industrialio-triggered-event.c    |  2 +-
> > >  drivers/iio/inkern.c                          | 46 ++++++-----
> > >  drivers/iio/light/acpi-als.c                  |  3 +-
> > >  drivers/iio/light/rpr0521.c                   |  2 +-
> > >  drivers/iio/light/si1145.c                    |  2 +-
> > >  drivers/iio/light/vcnl4000.c                  |  3 +-
> > >  drivers/iio/light/vcnl4035.c                  |  2 +-
> > >  drivers/iio/magnetometer/bmc150_magn.c        |  2 +-
> > >  drivers/iio/magnetometer/rm3100-core.c        |  2 +-
> > >  drivers/iio/potentiostat/lmp91000.c           |  3 +-
> > >  drivers/iio/pressure/zpa2326.c                |  3 +-
> > >  drivers/iio/proximity/as3935.c                |  3 +-
> > >  drivers/iio/proximity/sx9310.c                |  2 +-
> > >  drivers/iio/proximity/sx9500.c                |  2 +-
> > >  include/linux/iio/iio-opaque.h                | 22 +++++-
> > >  include/linux/iio/iio.h                       | 29 +------
> > >  52 files changed, 188 insertions(+), 131 deletions(-)
> > >
> > > --
> > > 2.31.1
> > >
>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 3/9] iio: core: move @driver_module from struct iio_dev to struct iio_dev_opaque
  2021-04-26 17:49 ` [PATCH 3/9] iio: core: move @driver_module from struct iio_dev to struct iio_dev_opaque Jonathan Cameron
@ 2021-04-28  6:55   ` Alexandru Ardelean
  0 siblings, 0 replies; 27+ messages in thread
From: Alexandru Ardelean @ 2021-04-28  6:55 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Jonathan Cameron

On Mon, Apr 26, 2021 at 8:50 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> Continuing move to hide internal elements from drivers, move this structure
> element over.  It's only accessed from iio core files so this one was
> straight forward and no accessor functions are needed.
>

Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>

> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  drivers/iio/industrialio-core.c    | 2 +-
>  drivers/iio/industrialio-trigger.c | 9 ++++++---
>  include/linux/iio/iio-opaque.h     | 2 ++
>  include/linux/iio/iio.h            | 3 ---
>  4 files changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index c16b8f344c93..8c38f1f6e075 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -1859,7 +1859,7 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod)
>         if (!indio_dev->info)
>                 return -EINVAL;
>
> -       indio_dev->driver_module = this_mod;
> +       iio_dev_opaque->driver_module = this_mod;
>         /* If the calling driver did not initialize of_node, do it here */
>         if (!indio_dev->dev.of_node && indio_dev->dev.parent)
>                 indio_dev->dev.of_node = indio_dev->dev.parent->of_node;
> diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
> index 3236647b2c37..b489eeeb0004 100644
> --- a/drivers/iio/industrialio-trigger.c
> +++ b/drivers/iio/industrialio-trigger.c
> @@ -13,6 +13,7 @@
>  #include <linux/slab.h>
>
>  #include <linux/iio/iio.h>
> +#include <linux/iio/iio-opaque.h>
>  #include <linux/iio/trigger.h>
>  #include "iio_core.h"
>  #include "iio_core_trigger.h"
> @@ -240,12 +241,13 @@ static void iio_trigger_put_irq(struct iio_trigger *trig, int irq)
>  int iio_trigger_attach_poll_func(struct iio_trigger *trig,
>                                  struct iio_poll_func *pf)
>  {
> +       struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(pf->indio_dev);
>         bool notinuse =
>                 bitmap_empty(trig->pool, CONFIG_IIO_CONSUMERS_PER_TRIGGER);
>         int ret = 0;
>
>         /* Prevent the module from being removed whilst attached to a trigger */
> -       __module_get(pf->indio_dev->driver_module);
> +       __module_get(iio_dev_opaque->driver_module);
>
>         /* Get irq number */
>         pf->irq = iio_trigger_get_irq(trig);
> @@ -284,13 +286,14 @@ int iio_trigger_attach_poll_func(struct iio_trigger *trig,
>  out_put_irq:
>         iio_trigger_put_irq(trig, pf->irq);
>  out_put_module:
> -       module_put(pf->indio_dev->driver_module);
> +       module_put(iio_dev_opaque->driver_module);
>         return ret;
>  }
>
>  int iio_trigger_detach_poll_func(struct iio_trigger *trig,
>                                  struct iio_poll_func *pf)
>  {
> +       struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(pf->indio_dev);
>         bool no_other_users =
>                 bitmap_weight(trig->pool, CONFIG_IIO_CONSUMERS_PER_TRIGGER) == 1;
>         int ret = 0;
> @@ -304,7 +307,7 @@ int iio_trigger_detach_poll_func(struct iio_trigger *trig,
>                 trig->attached_own_device = false;
>         iio_trigger_put_irq(trig, pf->irq);
>         free_irq(pf->irq, pf);
> -       module_put(pf->indio_dev->driver_module);
> +       module_put(iio_dev_opaque->driver_module);
>
>         return ret;
>  }
> diff --git a/include/linux/iio/iio-opaque.h b/include/linux/iio/iio-opaque.h
> index f876e3aede2c..96dd265103d0 100644
> --- a/include/linux/iio/iio-opaque.h
> +++ b/include/linux/iio/iio-opaque.h
> @@ -7,6 +7,7 @@
>   * struct iio_dev_opaque - industrial I/O device opaque information
>   * @indio_dev:                 public industrial I/O device information
>   * @id:                        used to identify device internally
> + * @driver_module:             used to make it harder to undercut users
>   * @event_interface:           event chrdevs associated with interrupt lines
>   * @attached_buffers:          array of buffers statically attached by the driver
>   * @attached_buffers_cnt:      number of buffers in the array of statically attached buffers
> @@ -28,6 +29,7 @@
>  struct iio_dev_opaque {
>         struct iio_dev                  indio_dev;
>         int                             id;
> +       struct module                   *driver_module;
>         struct iio_event_interface      *event_interface;
>         struct iio_buffer               **attached_buffers;
>         unsigned int                    attached_buffers_cnt;
> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> index 569861d5887a..9e8e1358a032 100644
> --- a/include/linux/iio/iio.h
> +++ b/include/linux/iio/iio.h
> @@ -488,7 +488,6 @@ struct iio_buffer_setup_ops {
>
>  /**
>   * struct iio_dev - industrial I/O device
> - * @driver_module:     [INTERN] used to make it harder to undercut users
>   * @modes:             [DRIVER] operating modes supported by device
>   * @currentmode:       [DRIVER] current operating mode
>   * @dev:               [DRIVER] device structure, should be assigned a parent
> @@ -522,8 +521,6 @@ struct iio_buffer_setup_ops {
>   *                     **MUST** be accessed **ONLY** via iio_priv() helper
>   */
>  struct iio_dev {
> -       struct module                   *driver_module;
> -
>         int                             modes;
>         int                             currentmode;
>         struct device                   dev;
> --
> 2.31.1
>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 1/9] iio: core: move @id from struct iio_dev to struct iio_dev_opaque
  2021-04-26 17:49 ` [PATCH 1/9] iio: core: move @id from struct iio_dev to struct iio_dev_opaque Jonathan Cameron
  2021-04-27  7:44   ` Alexandru Ardelean
@ 2021-05-03 11:42   ` Jonathan Cameron
  1 sibling, 0 replies; 27+ messages in thread
From: Jonathan Cameron @ 2021-05-03 11:42 UTC (permalink / raw)
  To: linux-iio; +Cc: Alexandru Ardelean, Jonathan Cameron

On Mon, 26 Apr 2021 18:49:03 +0100
Jonathan Cameron <jic23@kernel.org> wrote:

> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> 
> Continuing from Alexandru Ardelean's introduction of the split between
> driver modifiable fields and those that should only be set by the core.
> 
> This could have been done in two steps to make the actual move after
> introducing iio_device_id() but there seemed limited point to that
> given how mechanical the majority of the patch is.
> 
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This somehow missed at91-sama5d2_adc.c

I've added that one and applied this to the togreg branch of iio.git.
Pushed out as testing as I definitely want this series to get some
significant build exposure.

Thanks,

Jonathan

> ---
>  drivers/iio/accel/adxl372.c                   |  4 ++--
>  drivers/iio/accel/bma180.c                    |  2 +-
>  drivers/iio/accel/bmc150-accel-core.c         |  4 ++--
>  drivers/iio/accel/kxcjk-1013.c                |  4 ++--
>  drivers/iio/accel/mma8452.c                   |  2 +-
>  drivers/iio/accel/mxc4005.c                   |  2 +-
>  drivers/iio/accel/stk8312.c                   |  2 +-
>  drivers/iio/accel/stk8ba50.c                  |  2 +-
>  drivers/iio/adc/ad7606.c                      |  3 ++-
>  drivers/iio/adc/ad7766.c                      |  3 ++-
>  drivers/iio/adc/ad7768-1.c                    |  3 ++-
>  drivers/iio/adc/ad_sigma_delta.c              |  2 +-
>  drivers/iio/adc/at91_adc.c                    |  4 ++--
>  drivers/iio/adc/dln2-adc.c                    |  3 ++-
>  drivers/iio/adc/ina2xx-adc.c                  |  3 ++-
>  drivers/iio/adc/ti-ads131e08.c                |  2 +-
>  drivers/iio/adc/xilinx-xadc-core.c            |  2 +-
>  .../buffer/industrialio-triggered-buffer.c    |  2 +-
>  drivers/iio/chemical/atlas-sensor.c           |  2 +-
>  drivers/iio/chemical/ccs811.c                 |  2 +-
>  drivers/iio/chemical/scd30_core.c             |  3 ++-
>  .../common/hid-sensors/hid-sensor-trigger.c   |  2 +-
>  drivers/iio/gyro/adxrs290.c                   |  2 +-
>  drivers/iio/gyro/bmg160_core.c                |  4 ++--
>  drivers/iio/gyro/fxas21002c_core.c            |  2 +-
>  drivers/iio/gyro/itg3200_buffer.c             |  2 +-
>  drivers/iio/gyro/mpu3050-core.c               |  2 +-
>  drivers/iio/health/afe4403.c                  |  2 +-
>  drivers/iio/health/afe4404.c                  |  2 +-
>  drivers/iio/imu/adis_trigger.c                |  3 ++-
>  drivers/iio/imu/bmi160/bmi160_core.c          |  3 ++-
>  drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c |  2 +-
>  drivers/iio/imu/kmx61.c                       |  2 +-
>  drivers/iio/industrialio-core.c               | 24 +++++++++++++++----
>  drivers/iio/industrialio-triggered-event.c    |  2 +-
>  drivers/iio/light/acpi-als.c                  |  3 ++-
>  drivers/iio/light/rpr0521.c                   |  2 +-
>  drivers/iio/light/si1145.c                    |  2 +-
>  drivers/iio/light/vcnl4000.c                  |  3 ++-
>  drivers/iio/light/vcnl4035.c                  |  2 +-
>  drivers/iio/magnetometer/bmc150_magn.c        |  2 +-
>  drivers/iio/magnetometer/rm3100-core.c        |  2 +-
>  drivers/iio/potentiostat/lmp91000.c           |  3 ++-
>  drivers/iio/pressure/zpa2326.c                |  3 ++-
>  drivers/iio/proximity/as3935.c                |  3 ++-
>  drivers/iio/proximity/sx9310.c                |  2 +-
>  drivers/iio/proximity/sx9500.c                |  2 +-
>  include/linux/iio/iio-opaque.h                |  2 ++
>  include/linux/iio/iio.h                       |  4 ++--
>  49 files changed, 87 insertions(+), 58 deletions(-)
> 
> diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c
> index 9c9a896a872a..fc9592407717 100644
> --- a/drivers/iio/accel/adxl372.c
> +++ b/drivers/iio/accel/adxl372.c
> @@ -1223,14 +1223,14 @@ int adxl372_probe(struct device *dev, struct regmap *regmap,
>  		st->dready_trig = devm_iio_trigger_alloc(dev,
>  							 "%s-dev%d",
>  							 indio_dev->name,
> -							 indio_dev->id);
> +							 iio_device_id(indio_dev));
>  		if (st->dready_trig == NULL)
>  			return -ENOMEM;
>  
>  		st->peak_datardy_trig = devm_iio_trigger_alloc(dev,
>  							       "%s-dev%d-peak",
>  							       indio_dev->name,
> -							       indio_dev->id);
> +							       iio_device_id(indio_dev));
>  		if (!st->peak_datardy_trig)
>  			return -ENOMEM;
>  
> diff --git a/drivers/iio/accel/bma180.c b/drivers/iio/accel/bma180.c
> index b8a7469cdae4..68d91a70de03 100644
> --- a/drivers/iio/accel/bma180.c
> +++ b/drivers/iio/accel/bma180.c
> @@ -1045,7 +1045,7 @@ static int bma180_probe(struct i2c_client *client,
>  
>  	if (client->irq > 0) {
>  		data->trig = iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name,
> -			indio_dev->id);
> +					       iio_device_id(indio_dev));
>  		if (!data->trig) {
>  			ret = -ENOMEM;
>  			goto err_chip_disable;
> diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
> index 04d85ce34e9f..62a164a7b852 100644
> --- a/drivers/iio/accel/bmc150-accel-core.c
> +++ b/drivers/iio/accel/bmc150-accel-core.c
> @@ -1470,9 +1470,9 @@ static int bmc150_accel_triggers_setup(struct iio_dev *indio_dev,
>  		struct bmc150_accel_trigger *t = &data->triggers[i];
>  
>  		t->indio_trig = devm_iio_trigger_alloc(dev,
> -					bmc150_accel_triggers[i].name,
> +						       bmc150_accel_triggers[i].name,
>  						       indio_dev->name,
> -						       indio_dev->id);
> +						       iio_device_id(indio_dev));
>  		if (!t->indio_trig) {
>  			ret = -ENOMEM;
>  			break;
> diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c
> index ff724bc17a45..283e6a3feffc 100644
> --- a/drivers/iio/accel/kxcjk-1013.c
> +++ b/drivers/iio/accel/kxcjk-1013.c
> @@ -1404,7 +1404,7 @@ static int kxcjk1013_probe(struct i2c_client *client,
>  		data->dready_trig = devm_iio_trigger_alloc(&client->dev,
>  							   "%s-dev%d",
>  							   indio_dev->name,
> -							   indio_dev->id);
> +							   iio_device_id(indio_dev));
>  		if (!data->dready_trig) {
>  			ret = -ENOMEM;
>  			goto err_poweroff;
> @@ -1413,7 +1413,7 @@ static int kxcjk1013_probe(struct i2c_client *client,
>  		data->motion_trig = devm_iio_trigger_alloc(&client->dev,
>  							  "%s-any-motion-dev%d",
>  							  indio_dev->name,
> -							  indio_dev->id);
> +							  iio_device_id(indio_dev));
>  		if (!data->motion_trig) {
>  			ret = -ENOMEM;
>  			goto err_poweroff;
> diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
> index 4d307dfb9169..464a6bfe6746 100644
> --- a/drivers/iio/accel/mma8452.c
> +++ b/drivers/iio/accel/mma8452.c
> @@ -1461,7 +1461,7 @@ static int mma8452_trigger_setup(struct iio_dev *indio_dev)
>  
>  	trig = devm_iio_trigger_alloc(&data->client->dev, "%s-dev%d",
>  				      indio_dev->name,
> -				      indio_dev->id);
> +				      iio_device_id(indio_dev));
>  	if (!trig)
>  		return -ENOMEM;
>  
> diff --git a/drivers/iio/accel/mxc4005.c b/drivers/iio/accel/mxc4005.c
> index fb3cbaa62bd8..98c7f5f59011 100644
> --- a/drivers/iio/accel/mxc4005.c
> +++ b/drivers/iio/accel/mxc4005.c
> @@ -433,7 +433,7 @@ static int mxc4005_probe(struct i2c_client *client,
>  		data->dready_trig = devm_iio_trigger_alloc(&client->dev,
>  							   "%s-dev%d",
>  							   indio_dev->name,
> -							   indio_dev->id);
> +							   iio_device_id(indio_dev));
>  		if (!data->dready_trig)
>  			return -ENOMEM;
>  
> diff --git a/drivers/iio/accel/stk8312.c b/drivers/iio/accel/stk8312.c
> index 60aecfa9fd92..aeab108c457d 100644
> --- a/drivers/iio/accel/stk8312.c
> +++ b/drivers/iio/accel/stk8312.c
> @@ -552,7 +552,7 @@ static int stk8312_probe(struct i2c_client *client,
>  		data->dready_trig = devm_iio_trigger_alloc(&client->dev,
>  							   "%s-dev%d",
>  							   indio_dev->name,
> -							   indio_dev->id);
> +							   iio_device_id(indio_dev));
>  		if (!data->dready_trig) {
>  			ret = -ENOMEM;
>  			goto err_power_off;
> diff --git a/drivers/iio/accel/stk8ba50.c b/drivers/iio/accel/stk8ba50.c
> index 7cf9cb7e8666..3e7cf23be7e1 100644
> --- a/drivers/iio/accel/stk8ba50.c
> +++ b/drivers/iio/accel/stk8ba50.c
> @@ -448,7 +448,7 @@ static int stk8ba50_probe(struct i2c_client *client,
>  		data->dready_trig = devm_iio_trigger_alloc(&client->dev,
>  							   "%s-dev%d",
>  							   indio_dev->name,
> -							   indio_dev->id);
> +							   iio_device_id(indio_dev));
>  		if (!data->dready_trig) {
>  			ret = -ENOMEM;
>  			goto err_power_off;
> diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
> index 0af0bb4d5a7f..0a60ecc69d38 100644
> --- a/drivers/iio/adc/ad7606.c
> +++ b/drivers/iio/adc/ad7606.c
> @@ -663,7 +663,8 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
>  	}
>  
>  	st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
> -					  indio_dev->name, indio_dev->id);
> +					  indio_dev->name,
> +					  iio_device_id(indio_dev));
>  	if (!st->trig)
>  		return -ENOMEM;
>  
> diff --git a/drivers/iio/adc/ad7766.c b/drivers/iio/adc/ad7766.c
> index 1e41759f3ee5..236a455aaa18 100644
> --- a/drivers/iio/adc/ad7766.c
> +++ b/drivers/iio/adc/ad7766.c
> @@ -248,7 +248,8 @@ static int ad7766_probe(struct spi_device *spi)
>  
>  	if (spi->irq > 0) {
>  		ad7766->trig = devm_iio_trigger_alloc(&spi->dev, "%s-dev%d",
> -			indio_dev->name, indio_dev->id);
> +						      indio_dev->name,
> +						      iio_device_id(indio_dev));
>  		if (!ad7766->trig)
>  			return -ENOMEM;
>  
> diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c
> index c945f1349623..41752777e96c 100644
> --- a/drivers/iio/adc/ad7768-1.c
> +++ b/drivers/iio/adc/ad7768-1.c
> @@ -626,7 +626,8 @@ static int ad7768_probe(struct spi_device *spi)
>  	}
>  
>  	st->trig = devm_iio_trigger_alloc(&spi->dev, "%s-dev%d",
> -					  indio_dev->name, indio_dev->id);
> +					  indio_dev->name,
> +					  iio_device_id(indio_dev));
>  	if (!st->trig)
>  		return -ENOMEM;
>  
> diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
> index e777ec718973..69b979331ccd 100644
> --- a/drivers/iio/adc/ad_sigma_delta.c
> +++ b/drivers/iio/adc/ad_sigma_delta.c
> @@ -477,7 +477,7 @@ static int ad_sd_probe_trigger(struct iio_dev *indio_dev)
>  
>  	sigma_delta->trig = iio_trigger_alloc(&sigma_delta->spi->dev,
>  					      "%s-dev%d", indio_dev->name,
> -					      indio_dev->id);
> +					      iio_device_id(indio_dev));
>  	if (sigma_delta->trig == NULL) {
>  		ret = -ENOMEM;
>  		goto error_ret;
> diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
> index 0b5f0c91d0d7..5a7d3a3a5fa8 100644
> --- a/drivers/iio/adc/at91_adc.c
> +++ b/drivers/iio/adc/at91_adc.c
> @@ -547,7 +547,7 @@ static int at91_adc_get_trigger_value_by_name(struct iio_dev *idev,
>  		char *name = kasprintf(GFP_KERNEL,
>  				"%s-dev%d-%s",
>  				idev->name,
> -				idev->id,
> +				iio_device_id(idev),
>  				triggers[i].name);
>  		if (!name)
>  			return -ENOMEM;
> @@ -626,7 +626,7 @@ static struct iio_trigger *at91_adc_allocate_trigger(struct iio_dev *idev,
>  	int ret;
>  
>  	trig = iio_trigger_alloc(idev->dev.parent, "%s-dev%d-%s", idev->name,
> -				 idev->id, trigger->name);
> +				 iio_device_id(idev), trigger->name);
>  	if (trig == NULL)
>  		return NULL;
>  
> diff --git a/drivers/iio/adc/dln2-adc.c b/drivers/iio/adc/dln2-adc.c
> index 0d53ef18e045..16407664182c 100644
> --- a/drivers/iio/adc/dln2-adc.c
> +++ b/drivers/iio/adc/dln2-adc.c
> @@ -649,7 +649,8 @@ static int dln2_adc_probe(struct platform_device *pdev)
>  	indio_dev->setup_ops = &dln2_adc_buffer_setup_ops;
>  
>  	dln2->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
> -					    indio_dev->name, indio_dev->id);
> +					    indio_dev->name,
> +					    iio_device_id(indio_dev));
>  	if (!dln2->trig) {
>  		dev_err(dev, "failed to allocate trigger\n");
>  		return -ENOMEM;
> diff --git a/drivers/iio/adc/ina2xx-adc.c b/drivers/iio/adc/ina2xx-adc.c
> index 2ae54258b221..a4b2ff9e0dd5 100644
> --- a/drivers/iio/adc/ina2xx-adc.c
> +++ b/drivers/iio/adc/ina2xx-adc.c
> @@ -843,7 +843,8 @@ static int ina2xx_buffer_enable(struct iio_dev *indio_dev)
>  		chip->allow_async_readout);
>  
>  	task = kthread_create(ina2xx_capture_thread, (void *)indio_dev,
> -			      "%s:%d-%uus", indio_dev->name, indio_dev->id,
> +			      "%s:%d-%uus", indio_dev->name,
> +			      iio_device_id(indio_dev),
>  			      sampling_us);
>  	if (IS_ERR(task))
>  		return PTR_ERR(task);
> diff --git a/drivers/iio/adc/ti-ads131e08.c b/drivers/iio/adc/ti-ads131e08.c
> index 0060d5f0abb0..5dcf1e9294d7 100644
> --- a/drivers/iio/adc/ti-ads131e08.c
> +++ b/drivers/iio/adc/ti-ads131e08.c
> @@ -844,7 +844,7 @@ static int ads131e08_probe(struct spi_device *spi)
>  	}
>  
>  	st->trig = devm_iio_trigger_alloc(&spi->dev, "%s-dev%d",
> -		indio_dev->name, indio_dev->id);
> +		indio_dev->name, iio_device_id(indio_dev));
>  	if (!st->trig) {
>  		dev_err(&spi->dev, "failed to allocate IIO trigger\n");
>  		return -ENOMEM;
> diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c
> index 6914c1900ed0..198d2916266d 100644
> --- a/drivers/iio/adc/xilinx-xadc-core.c
> +++ b/drivers/iio/adc/xilinx-xadc-core.c
> @@ -743,7 +743,7 @@ static struct iio_trigger *xadc_alloc_trigger(struct iio_dev *indio_dev,
>  	int ret;
>  
>  	trig = devm_iio_trigger_alloc(dev, "%s%d-%s", indio_dev->name,
> -				      indio_dev->id, name);
> +				      iio_device_id(indio_dev), name);
>  	if (trig == NULL)
>  		return ERR_PTR(-ENOMEM);
>  
> diff --git a/drivers/iio/buffer/industrialio-triggered-buffer.c b/drivers/iio/buffer/industrialio-triggered-buffer.c
> index ebb4520ac291..f77c4538141e 100644
> --- a/drivers/iio/buffer/industrialio-triggered-buffer.c
> +++ b/drivers/iio/buffer/industrialio-triggered-buffer.c
> @@ -56,7 +56,7 @@ int iio_triggered_buffer_setup_ext(struct iio_dev *indio_dev,
>  						 indio_dev,
>  						 "%s_consumer%d",
>  						 indio_dev->name,
> -						 indio_dev->id);
> +						 iio_device_id(indio_dev));
>  	if (indio_dev->pollfunc == NULL) {
>  		ret = -ENOMEM;
>  		goto error_kfifo_free;
> diff --git a/drivers/iio/chemical/atlas-sensor.c b/drivers/iio/chemical/atlas-sensor.c
> index 56ba6c82b501..d10f921b233a 100644
> --- a/drivers/iio/chemical/atlas-sensor.c
> +++ b/drivers/iio/chemical/atlas-sensor.c
> @@ -640,7 +640,7 @@ static int atlas_probe(struct i2c_client *client,
>  	indio_dev->modes = INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE;
>  
>  	trig = devm_iio_trigger_alloc(&client->dev, "%s-dev%d",
> -				      indio_dev->name, indio_dev->id);
> +				      indio_dev->name, iio_device_id(indio_dev));
>  
>  	if (!trig)
>  		return -ENOMEM;
> diff --git a/drivers/iio/chemical/ccs811.c b/drivers/iio/chemical/ccs811.c
> index 886e96496dbf..847194fa1e46 100644
> --- a/drivers/iio/chemical/ccs811.c
> +++ b/drivers/iio/chemical/ccs811.c
> @@ -491,7 +491,7 @@ static int ccs811_probe(struct i2c_client *client,
>  		data->drdy_trig = devm_iio_trigger_alloc(&client->dev,
>  							 "%s-dev%d",
>  							 indio_dev->name,
> -							 indio_dev->id);
> +							 iio_device_id(indio_dev));
>  		if (!data->drdy_trig) {
>  			ret = -ENOMEM;
>  			goto err_poweroff;
> diff --git a/drivers/iio/chemical/scd30_core.c b/drivers/iio/chemical/scd30_core.c
> index d89f117dd0ef..9fe6bbe9ee04 100644
> --- a/drivers/iio/chemical/scd30_core.c
> +++ b/drivers/iio/chemical/scd30_core.c
> @@ -640,7 +640,8 @@ static int scd30_setup_trigger(struct iio_dev *indio_dev)
>  	struct iio_trigger *trig;
>  	int ret;
>  
> -	trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, indio_dev->id);
> +	trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name,
> +				      iio_device_id(indio_dev));
>  	if (!trig) {
>  		dev_err(dev, "failed to allocate trigger\n");
>  		return -ENOMEM;
> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
> index 95ddccb44f1c..5a7b3e253e58 100644
> --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
> +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
> @@ -256,7 +256,7 @@ int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
>  	}
>  
>  	trig = iio_trigger_alloc(indio_dev->dev.parent,
> -				 "%s-dev%d", name, indio_dev->id);
> +				 "%s-dev%d", name, iio_device_id(indio_dev));
>  	if (trig == NULL) {
>  		dev_err(&indio_dev->dev, "Trigger Allocate Failed\n");
>  		ret = -ENOMEM;
> diff --git a/drivers/iio/gyro/adxrs290.c b/drivers/iio/gyro/adxrs290.c
> index cec5e1f17c22..3e0734ddafe3 100644
> --- a/drivers/iio/gyro/adxrs290.c
> +++ b/drivers/iio/gyro/adxrs290.c
> @@ -589,7 +589,7 @@ static int adxrs290_probe_trigger(struct iio_dev *indio_dev)
>  
>  	st->dready_trig = devm_iio_trigger_alloc(&st->spi->dev, "%s-dev%d",
>  						 indio_dev->name,
> -						 indio_dev->id);
> +						 iio_device_id(indio_dev));
>  	if (!st->dready_trig)
>  		return -ENOMEM;
>  
> diff --git a/drivers/iio/gyro/bmg160_core.c b/drivers/iio/gyro/bmg160_core.c
> index b11ebd9bb7a4..26a9ed5770c6 100644
> --- a/drivers/iio/gyro/bmg160_core.c
> +++ b/drivers/iio/gyro/bmg160_core.c
> @@ -1137,14 +1137,14 @@ int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq,
>  		data->dready_trig = devm_iio_trigger_alloc(dev,
>  							   "%s-dev%d",
>  							   indio_dev->name,
> -							   indio_dev->id);
> +							   iio_device_id(indio_dev));
>  		if (!data->dready_trig)
>  			return -ENOMEM;
>  
>  		data->motion_trig = devm_iio_trigger_alloc(dev,
>  							  "%s-any-motion-dev%d",
>  							  indio_dev->name,
> -							  indio_dev->id);
> +							  iio_device_id(indio_dev));
>  		if (!data->motion_trig)
>  			return -ENOMEM;
>  
> diff --git a/drivers/iio/gyro/fxas21002c_core.c b/drivers/iio/gyro/fxas21002c_core.c
> index 1a20c6b88e7d..5af7b48ff01a 100644
> --- a/drivers/iio/gyro/fxas21002c_core.c
> +++ b/drivers/iio/gyro/fxas21002c_core.c
> @@ -852,7 +852,7 @@ static int fxas21002c_trigger_probe(struct fxas21002c_data *data)
>  
>  	data->dready_trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
>  						   indio_dev->name,
> -						   indio_dev->id);
> +						   iio_device_id(indio_dev));
>  	if (!data->dready_trig)
>  		return -ENOMEM;
>  
> diff --git a/drivers/iio/gyro/itg3200_buffer.c b/drivers/iio/gyro/itg3200_buffer.c
> index af0aaa146f0c..04dd6a7969ea 100644
> --- a/drivers/iio/gyro/itg3200_buffer.c
> +++ b/drivers/iio/gyro/itg3200_buffer.c
> @@ -114,7 +114,7 @@ int itg3200_probe_trigger(struct iio_dev *indio_dev)
>  	struct itg3200 *st = iio_priv(indio_dev);
>  
>  	st->trig = iio_trigger_alloc(&st->i2c->dev, "%s-dev%d", indio_dev->name,
> -				     indio_dev->id);
> +				     iio_device_id(indio_dev));
>  	if (!st->trig)
>  		return -ENOMEM;
>  
> diff --git a/drivers/iio/gyro/mpu3050-core.c b/drivers/iio/gyro/mpu3050-core.c
> index ac90be03332a..131e6f54948e 100644
> --- a/drivers/iio/gyro/mpu3050-core.c
> +++ b/drivers/iio/gyro/mpu3050-core.c
> @@ -1049,7 +1049,7 @@ static int mpu3050_trigger_probe(struct iio_dev *indio_dev, int irq)
>  	mpu3050->trig = devm_iio_trigger_alloc(&indio_dev->dev,
>  					       "%s-dev%d",
>  					       indio_dev->name,
> -					       indio_dev->id);
> +					       iio_device_id(indio_dev));
>  	if (!mpu3050->trig)
>  		return -ENOMEM;
>  
> diff --git a/drivers/iio/health/afe4403.c b/drivers/iio/health/afe4403.c
> index 1fa8d51d5080..d4921385aaf7 100644
> --- a/drivers/iio/health/afe4403.c
> +++ b/drivers/iio/health/afe4403.c
> @@ -521,7 +521,7 @@ static int afe4403_probe(struct spi_device *spi)
>  		afe->trig = devm_iio_trigger_alloc(afe->dev,
>  						   "%s-dev%d",
>  						   indio_dev->name,
> -						   indio_dev->id);
> +						   iio_device_id(indio_dev));
>  		if (!afe->trig) {
>  			dev_err(afe->dev, "Unable to allocate IIO trigger\n");
>  			ret = -ENOMEM;
> diff --git a/drivers/iio/health/afe4404.c b/drivers/iio/health/afe4404.c
> index e1476bf79fe2..d8a27dfe074a 100644
> --- a/drivers/iio/health/afe4404.c
> +++ b/drivers/iio/health/afe4404.c
> @@ -528,7 +528,7 @@ static int afe4404_probe(struct i2c_client *client,
>  		afe->trig = devm_iio_trigger_alloc(afe->dev,
>  						   "%s-dev%d",
>  						   indio_dev->name,
> -						   indio_dev->id);
> +						   iio_device_id(indio_dev));
>  		if (!afe->trig) {
>  			dev_err(afe->dev, "Unable to allocate IIO trigger\n");
>  			ret = -ENOMEM;
> diff --git a/drivers/iio/imu/adis_trigger.c b/drivers/iio/imu/adis_trigger.c
> index fa5540fabacc..48eedc29b28a 100644
> --- a/drivers/iio/imu/adis_trigger.c
> +++ b/drivers/iio/imu/adis_trigger.c
> @@ -62,7 +62,8 @@ int devm_adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev)
>  	int ret;
>  
>  	adis->trig = devm_iio_trigger_alloc(&adis->spi->dev, "%s-dev%d",
> -					    indio_dev->name, indio_dev->id);
> +					    indio_dev->name,
> +					    iio_device_id(indio_dev));
>  	if (!adis->trig)
>  		return -ENOMEM;
>  
> diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c
> index 290b5ef83f77..b63bd7e5e5e5 100644
> --- a/drivers/iio/imu/bmi160/bmi160_core.c
> +++ b/drivers/iio/imu/bmi160/bmi160_core.c
> @@ -785,7 +785,8 @@ int bmi160_probe_trigger(struct iio_dev *indio_dev, int irq, u32 irq_type)
>  	int ret;
>  
>  	data->trig = devm_iio_trigger_alloc(&indio_dev->dev, "%s-dev%d",
> -					    indio_dev->name, indio_dev->id);
> +					    indio_dev->name,
> +					    iio_device_id(indio_dev));
>  
>  	if (data->trig == NULL)
>  		return -ENOMEM;
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
> index de8ed1446d60..e21ba778595a 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
> @@ -238,7 +238,7 @@ int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev, int irq_type)
>  	st->trig = devm_iio_trigger_alloc(&indio_dev->dev,
>  					  "%s-dev%d",
>  					  indio_dev->name,
> -					  indio_dev->id);
> +					  iio_device_id(indio_dev));
>  	if (!st->trig)
>  		return -ENOMEM;
>  
> diff --git a/drivers/iio/imu/kmx61.c b/drivers/iio/imu/kmx61.c
> index fc5a60fcfec0..d3e06ce99c1e 100644
> --- a/drivers/iio/imu/kmx61.c
> +++ b/drivers/iio/imu/kmx61.c
> @@ -1264,7 +1264,7 @@ static struct iio_trigger *kmx61_trigger_setup(struct kmx61_data *data,
>  				      "%s-%s-dev%d",
>  				      indio_dev->name,
>  				      tag,
> -				      indio_dev->id);
> +				      iio_device_id(indio_dev));
>  	if (!trig)
>  		return ERR_PTR(-ENOMEM);
>  
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 022198c32e32..c16b8f344c93 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -169,6 +169,20 @@ static const char * const iio_chan_info_postfix[] = {
>  	[IIO_CHAN_INFO_THERMOCOUPLE_TYPE] = "thermocouple_type",
>  	[IIO_CHAN_INFO_CALIBAMBIENT] = "calibambient",
>  };
> +/**
> + * iio_device_id() - query the unique ID for the device
> + * @indio_dev:		Device structure whose ID is being queried
> + *
> + * The IIO device ID is a unique index used for example for the naming
> + * of the character device /dev/iio\:device[ID]
> + */
> +int iio_device_id(struct iio_dev *indio_dev)
> +{
> +	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
> +
> +	return iio_dev_opaque->id;
> +}
> +EXPORT_SYMBOL_GPL(iio_device_id);
>  
>  /**
>   * iio_sysfs_match_string_with_gaps - matches given string in an array with gaps
> @@ -1588,7 +1602,7 @@ static void iio_dev_release(struct device *device)
>  
>  	iio_device_detach_buffers(indio_dev);
>  
> -	ida_simple_remove(&iio_ida, indio_dev->id);
> +	ida_simple_remove(&iio_ida, iio_dev_opaque->id);
>  	kfree(iio_dev_opaque);
>  }
>  
> @@ -1631,14 +1645,14 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)
>  	mutex_init(&indio_dev->info_exist_lock);
>  	INIT_LIST_HEAD(&iio_dev_opaque->channel_attr_list);
>  
> -	indio_dev->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL);
> -	if (indio_dev->id < 0) {
> +	iio_dev_opaque->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL);
> +	if (iio_dev_opaque->id < 0) {
>  		/* cannot use a dev_err as the name isn't available */
>  		pr_err("failed to get device id\n");
>  		kfree(iio_dev_opaque);
>  		return NULL;
>  	}
> -	dev_set_name(&indio_dev->dev, "iio:device%d", indio_dev->id);
> +	dev_set_name(&indio_dev->dev, "iio:device%d", iio_dev_opaque->id);
>  	INIT_LIST_HEAD(&iio_dev_opaque->buffer_list);
>  	INIT_LIST_HEAD(&iio_dev_opaque->ioctl_handlers);
>  
> @@ -1892,7 +1906,7 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod)
>  		cdev_init(&indio_dev->chrdev, &iio_event_fileops);
>  
>  	if (iio_dev_opaque->attached_buffers_cnt || iio_dev_opaque->event_interface) {
> -		indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), indio_dev->id);
> +		indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), iio_dev_opaque->id);
>  		indio_dev->chrdev.owner = this_mod;
>  	}
>  
> diff --git a/drivers/iio/industrialio-triggered-event.c b/drivers/iio/industrialio-triggered-event.c
> index 53da9ab17a62..4bedc65c9fe3 100644
> --- a/drivers/iio/industrialio-triggered-event.c
> +++ b/drivers/iio/industrialio-triggered-event.c
> @@ -37,7 +37,7 @@ int iio_triggered_event_setup(struct iio_dev *indio_dev,
>  						       indio_dev,
>  						       "%s_consumer%d",
>  						       indio_dev->name,
> -						       indio_dev->id);
> +						       iio_device_id(indio_dev));
>  	if (indio_dev->pollfunc_event == NULL)
>  		return -ENOMEM;
>  
> diff --git a/drivers/iio/light/acpi-als.c b/drivers/iio/light/acpi-als.c
> index 30393f08e082..260f96ea5f3c 100644
> --- a/drivers/iio/light/acpi-als.c
> +++ b/drivers/iio/light/acpi-als.c
> @@ -206,7 +206,8 @@ static int acpi_als_add(struct acpi_device *device)
>  	indio_dev->channels = acpi_als_channels;
>  	indio_dev->num_channels = ARRAY_SIZE(acpi_als_channels);
>  
> -	als->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, indio_dev->id);
> +	als->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name,
> +					   iio_device_id(indio_dev));
>  	if (!als->trig)
>  		return -ENOMEM;
>  
> diff --git a/drivers/iio/light/rpr0521.c b/drivers/iio/light/rpr0521.c
> index 033578f444e4..7e332de0e6a5 100644
> --- a/drivers/iio/light/rpr0521.c
> +++ b/drivers/iio/light/rpr0521.c
> @@ -985,7 +985,7 @@ static int rpr0521_probe(struct i2c_client *client,
>  		/* Trigger0 producer setup */
>  		data->drdy_trigger0 = devm_iio_trigger_alloc(
>  			indio_dev->dev.parent,
> -			"%s-dev%d", indio_dev->name, indio_dev->id);
> +			"%s-dev%d", indio_dev->name, iio_device_id(indio_dev));
>  		if (!data->drdy_trigger0) {
>  			ret = -ENOMEM;
>  			goto err_pm_disable;
> diff --git a/drivers/iio/light/si1145.c b/drivers/iio/light/si1145.c
> index 9b5c99823943..3fb52402fcc3 100644
> --- a/drivers/iio/light/si1145.c
> +++ b/drivers/iio/light/si1145.c
> @@ -1243,7 +1243,7 @@ static int si1145_probe_trigger(struct iio_dev *indio_dev)
>  	int ret;
>  
>  	trig = devm_iio_trigger_alloc(&client->dev,
> -			"%s-dev%d", indio_dev->name, indio_dev->id);
> +			"%s-dev%d", indio_dev->name, iio_device_id(indio_dev));
>  	if (!trig)
>  		return -ENOMEM;
>  
> diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
> index 2f7916f95689..4a61865d01cd 100644
> --- a/drivers/iio/light/vcnl4000.c
> +++ b/drivers/iio/light/vcnl4000.c
> @@ -998,7 +998,8 @@ static int vcnl4010_probe_trigger(struct iio_dev *indio_dev)
>  	struct iio_trigger *trigger;
>  
>  	trigger = devm_iio_trigger_alloc(&client->dev, "%s-dev%d",
> -					 indio_dev->name, indio_dev->id);
> +					 indio_dev->name,
> +					 iio_device_id(indio_dev));
>  	if (!trigger)
>  		return -ENOMEM;
>  
> diff --git a/drivers/iio/light/vcnl4035.c b/drivers/iio/light/vcnl4035.c
> index ae87740d9cef..691a54b763e1 100644
> --- a/drivers/iio/light/vcnl4035.c
> +++ b/drivers/iio/light/vcnl4035.c
> @@ -507,7 +507,7 @@ static int vcnl4035_probe_trigger(struct iio_dev *indio_dev)
>  
>  	data->drdy_trigger0 = devm_iio_trigger_alloc(
>  			indio_dev->dev.parent,
> -			"%s-dev%d", indio_dev->name, indio_dev->id);
> +			"%s-dev%d", indio_dev->name, iio_device_id(indio_dev));
>  	if (!data->drdy_trigger0)
>  		return -ENOMEM;
>  
> diff --git a/drivers/iio/magnetometer/bmc150_magn.c b/drivers/iio/magnetometer/bmc150_magn.c
> index 00f9766bad5c..d75b437a43f2 100644
> --- a/drivers/iio/magnetometer/bmc150_magn.c
> +++ b/drivers/iio/magnetometer/bmc150_magn.c
> @@ -915,7 +915,7 @@ int bmc150_magn_probe(struct device *dev, struct regmap *regmap,
>  		data->dready_trig = devm_iio_trigger_alloc(dev,
>  							   "%s-dev%d",
>  							   indio_dev->name,
> -							   indio_dev->id);
> +							   iio_device_id(indio_dev));
>  		if (!data->dready_trig) {
>  			ret = -ENOMEM;
>  			dev_err(dev, "iio trigger alloc failed\n");
> diff --git a/drivers/iio/magnetometer/rm3100-core.c b/drivers/iio/magnetometer/rm3100-core.c
> index dd811da9cb6d..4df5887fd04c 100644
> --- a/drivers/iio/magnetometer/rm3100-core.c
> +++ b/drivers/iio/magnetometer/rm3100-core.c
> @@ -575,7 +575,7 @@ int rm3100_common_probe(struct device *dev, struct regmap *regmap, int irq)
>  
>  		data->drdy_trig = devm_iio_trigger_alloc(dev, "%s-drdy%d",
>  							 indio_dev->name,
> -							 indio_dev->id);
> +							 iio_device_id(indio_dev));
>  		if (!data->drdy_trig)
>  			return -ENOMEM;
>  
> diff --git a/drivers/iio/potentiostat/lmp91000.c b/drivers/iio/potentiostat/lmp91000.c
> index 8a9c576616ee..1948e2d22c27 100644
> --- a/drivers/iio/potentiostat/lmp91000.c
> +++ b/drivers/iio/potentiostat/lmp91000.c
> @@ -323,7 +323,8 @@ static int lmp91000_probe(struct i2c_client *client,
>  	}
>  
>  	data->trig = devm_iio_trigger_alloc(dev, "%s-mux%d",
> -					    indio_dev->name, indio_dev->id);
> +					    indio_dev->name,
> +					    iio_device_id(indio_dev));
>  	if (!data->trig) {
>  		dev_err(dev, "cannot allocate iio trigger.\n");
>  		return -ENOMEM;
> diff --git a/drivers/iio/pressure/zpa2326.c b/drivers/iio/pressure/zpa2326.c
> index a93411216aee..89295c90f801 100644
> --- a/drivers/iio/pressure/zpa2326.c
> +++ b/drivers/iio/pressure/zpa2326.c
> @@ -1408,7 +1408,8 @@ static int zpa2326_init_managed_trigger(struct device          *parent,
>  		return 0;
>  
>  	trigger = devm_iio_trigger_alloc(parent, "%s-dev%d",
> -					 indio_dev->name, indio_dev->id);
> +					 indio_dev->name,
> +					 iio_device_id(indio_dev));
>  	if (!trigger)
>  		return -ENOMEM;
>  
> diff --git a/drivers/iio/proximity/as3935.c b/drivers/iio/proximity/as3935.c
> index edc4a35ae66d..dc20fe81232c 100644
> --- a/drivers/iio/proximity/as3935.c
> +++ b/drivers/iio/proximity/as3935.c
> @@ -404,7 +404,8 @@ static int as3935_probe(struct spi_device *spi)
>  	indio_dev->info = &as3935_info;
>  
>  	trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
> -				      indio_dev->name, indio_dev->id);
> +				      indio_dev->name,
> +				      iio_device_id(indio_dev));
>  
>  	if (!trig)
>  		return -ENOMEM;
> diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c
> index 327ebb7ddbb9..175f3b7c61d7 100644
> --- a/drivers/iio/proximity/sx9310.c
> +++ b/drivers/iio/proximity/sx9310.c
> @@ -1473,7 +1473,7 @@ static int sx9310_probe(struct i2c_client *client)
>  
>  		data->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
>  						    indio_dev->name,
> -						    indio_dev->id);
> +						    iio_device_id(indio_dev));
>  		if (!data->trig)
>  			return -ENOMEM;
>  
> diff --git a/drivers/iio/proximity/sx9500.c b/drivers/iio/proximity/sx9500.c
> index a87f4a8e4327..3e4ddb2e8c2b 100644
> --- a/drivers/iio/proximity/sx9500.c
> +++ b/drivers/iio/proximity/sx9500.c
> @@ -946,7 +946,7 @@ static int sx9500_probe(struct i2c_client *client,
>  			return ret;
>  
>  		data->trig = devm_iio_trigger_alloc(&client->dev,
> -				"%s-dev%d", indio_dev->name, indio_dev->id);
> +				"%s-dev%d", indio_dev->name, iio_device_id(indio_dev));
>  		if (!data->trig)
>  			return -ENOMEM;
>  
> diff --git a/include/linux/iio/iio-opaque.h b/include/linux/iio/iio-opaque.h
> index 32addd5e790e..e66b029d99de 100644
> --- a/include/linux/iio/iio-opaque.h
> +++ b/include/linux/iio/iio-opaque.h
> @@ -6,6 +6,7 @@
>  /**
>   * struct iio_dev_opaque - industrial I/O device opaque information
>   * @indio_dev:			public industrial I/O device information
> + * @id:			used to identify device internally
>   * @event_interface:		event chrdevs associated with interrupt lines
>   * @attached_buffers:		array of buffers statically attached by the driver
>   * @attached_buffers_cnt:	number of buffers in the array of statically attached buffers
> @@ -26,6 +27,7 @@
>   */
>  struct iio_dev_opaque {
>  	struct iio_dev			indio_dev;
> +	int				id;
>  	struct iio_event_interface	*event_interface;
>  	struct iio_buffer		**attached_buffers;
>  	unsigned int			attached_buffers_cnt;
> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> index f2d65e2e88b6..569861d5887a 100644
> --- a/include/linux/iio/iio.h
> +++ b/include/linux/iio/iio.h
> @@ -488,7 +488,6 @@ struct iio_buffer_setup_ops {
>  
>  /**
>   * struct iio_dev - industrial I/O device
> - * @id:			[INTERN] used to identify device internally
>   * @driver_module:	[INTERN] used to make it harder to undercut users
>   * @modes:		[DRIVER] operating modes supported by device
>   * @currentmode:	[DRIVER] current operating mode
> @@ -523,7 +522,6 @@ struct iio_buffer_setup_ops {
>   *			**MUST** be accessed **ONLY** via iio_priv() helper
>   */
>  struct iio_dev {
> -	int				id;
>  	struct module			*driver_module;
>  
>  	int				modes;
> @@ -559,6 +557,8 @@ struct iio_dev {
>  	void				*priv;
>  };
>  
> +int iio_device_id(struct iio_dev *indio_dev);
> +
>  const struct iio_chan_spec
>  *iio_find_channel_from_si(struct iio_dev *indio_dev, int si);
>  /**


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 0/9] iio: Move more things from iio_dev to iio_dev_opaque
  2021-04-28  6:55     ` Alexandru Ardelean
@ 2021-05-03 11:53       ` Jonathan Cameron
  0 siblings, 0 replies; 27+ messages in thread
From: Jonathan Cameron @ 2021-05-03 11:53 UTC (permalink / raw)
  To: Alexandru Ardelean; +Cc: linux-iio, Jonathan Cameron

On Wed, 28 Apr 2021 09:55:19 +0300
Alexandru Ardelean <ardeleanalex@gmail.com> wrote:

> On Tue, Apr 27, 2021 at 8:11 PM Jonathan Cameron <jic23@kernel.org> wrote:
> >
> > On Tue, 27 Apr 2021 11:08:52 +0300
> > Alexandru Ardelean <ardeleanalex@gmail.com> wrote:
> >  
> > > On Mon, Apr 26, 2021 at 8:50 PM Jonathan Cameron <jic23@kernel.org> wrote:  
> > > >
> > > > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > > >
> > > > Intent here is to clear out the low hanging fruit so we can focus on the
> > > > more interesting elements.
> > > >
> > > > Hopefully this set are all uncontroversial. Lightly tested only but
> > > > all fairly mechanical so hopefully I didn't mess up.
> > > >  
> > >
> > > Series looks good.
> > > Thanks for moving this forward :)  
> > no problem.
> >
> > One thing.  You gave tags for all but it seems patch 3.
> > Fine if I also put your tag on that one?  
> 
> Yes.
> I may have missed it.
> I usually have reviews in the morning before starting some other work
> and drinking my coffee.

Thanks,

Applied to the togreg branch of iio.git and pushed out as testing to see if
I missed any more cases... 

Now we just have the 'small' issue of figuring out what to do about the remaining
elements!

Thanks,

Jonathan

> 
> >  
> > >
> > > Alex
> > >  
> > > > As for the others my current thinking is as follows
> > > >
> > > > mlock: Still some instances to clear out of this being used to protect things
> > > > it should not be used for. Long run we definitely want to move this one.
> > > >
> > > > scan_timestamp: Can easily use a look up function in drivers that access this
> > > > directly, but that feels like an unwanted level of indirection in
> > > > iio_push_to_buffers_with_timestamp().  Perhaps worth doing anyway.
> > > > scan_bytes is also used in this function.
> > > >
> > > > active_scan_mask and masklength: Both used in valid ways inside drivers.
> > > > Could be wrapped up in access functions, but it does seem a little
> > > > convoluted.
> > > >
> > > > trig: This is used correctly in lots of drivers, so should stay in
> > > > struct iio_dev.
> > > >
> > > > Jonathan Cameron (9):
> > > >   iio: core: move @id from struct iio_dev to struct iio_dev_opaque
> > > >   iio: avoid shadowing of variable name in to_iio_dev_opaque()
> > > >   iio: core: move @driver_module from struct iio_dev to struct
> > > >     iio_dev_opaque
> > > >   iio: core: move @trig_readonly from struct iio_dev to struct
> > > >     iio_dev_opaque
> > > >   iio: core: move @scan_index_timestamp to struct iio_dev_opaque
> > > >   iio: core: move @info_exist_lock to struct iio_dev_opaque
> > > >   iio: core: move @chrdev from struct iio_dev to struct iio_dev_opaque
> > > >   iio: core: move @flags from struct iio_dev to struct iio_dev_opaque
> > > >   iio: core: move @clock_id from struct iio_dev to struct iio_dev_opaque
> > > >
> > > >  drivers/iio/accel/adxl372.c                   |  4 +-
> > > >  drivers/iio/accel/bma180.c                    |  2 +-
> > > >  drivers/iio/accel/bmc150-accel-core.c         |  4 +-
> > > >  drivers/iio/accel/kxcjk-1013.c                |  4 +-
> > > >  drivers/iio/accel/mma8452.c                   |  2 +-
> > > >  drivers/iio/accel/mxc4005.c                   |  2 +-
> > > >  drivers/iio/accel/stk8312.c                   |  2 +-
> > > >  drivers/iio/accel/stk8ba50.c                  |  2 +-
> > > >  drivers/iio/adc/ad7606.c                      |  3 +-
> > > >  drivers/iio/adc/ad7766.c                      |  3 +-
> > > >  drivers/iio/adc/ad7768-1.c                    |  3 +-
> > > >  drivers/iio/adc/ad_sigma_delta.c              |  2 +-
> > > >  drivers/iio/adc/at91_adc.c                    |  4 +-
> > > >  drivers/iio/adc/dln2-adc.c                    |  3 +-
> > > >  drivers/iio/adc/ina2xx-adc.c                  |  3 +-
> > > >  drivers/iio/adc/ti-ads131e08.c                |  2 +-
> > > >  drivers/iio/adc/xilinx-xadc-core.c            |  2 +-
> > > >  .../buffer/industrialio-triggered-buffer.c    |  2 +-
> > > >  drivers/iio/chemical/atlas-sensor.c           |  2 +-
> > > >  drivers/iio/chemical/ccs811.c                 |  2 +-
> > > >  drivers/iio/chemical/scd30_core.c             |  3 +-
> > > >  .../common/hid-sensors/hid-sensor-trigger.c   |  2 +-
> > > >  drivers/iio/gyro/adxrs290.c                   |  2 +-
> > > >  drivers/iio/gyro/bmg160_core.c                |  4 +-
> > > >  drivers/iio/gyro/fxas21002c_core.c            |  2 +-
> > > >  drivers/iio/gyro/itg3200_buffer.c             |  2 +-
> > > >  drivers/iio/gyro/mpu3050-core.c               |  2 +-
> > > >  drivers/iio/health/afe4403.c                  |  2 +-
> > > >  drivers/iio/health/afe4404.c                  |  2 +-
> > > >  drivers/iio/imu/adis_trigger.c                |  3 +-
> > > >  drivers/iio/imu/bmi160/bmi160_core.c          |  3 +-
> > > >  drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c |  2 +-
> > > >  drivers/iio/imu/kmx61.c                       |  2 +-
> > > >  drivers/iio/industrialio-buffer.c             | 12 ++-
> > > >  drivers/iio/industrialio-core.c               | 76 +++++++++++++------
> > > >  drivers/iio/industrialio-trigger.c            | 19 +++--
> > > >  drivers/iio/industrialio-triggered-event.c    |  2 +-
> > > >  drivers/iio/inkern.c                          | 46 ++++++-----
> > > >  drivers/iio/light/acpi-als.c                  |  3 +-
> > > >  drivers/iio/light/rpr0521.c                   |  2 +-
> > > >  drivers/iio/light/si1145.c                    |  2 +-
> > > >  drivers/iio/light/vcnl4000.c                  |  3 +-
> > > >  drivers/iio/light/vcnl4035.c                  |  2 +-
> > > >  drivers/iio/magnetometer/bmc150_magn.c        |  2 +-
> > > >  drivers/iio/magnetometer/rm3100-core.c        |  2 +-
> > > >  drivers/iio/potentiostat/lmp91000.c           |  3 +-
> > > >  drivers/iio/pressure/zpa2326.c                |  3 +-
> > > >  drivers/iio/proximity/as3935.c                |  3 +-
> > > >  drivers/iio/proximity/sx9310.c                |  2 +-
> > > >  drivers/iio/proximity/sx9500.c                |  2 +-
> > > >  include/linux/iio/iio-opaque.h                | 22 +++++-
> > > >  include/linux/iio/iio.h                       | 29 +------
> > > >  52 files changed, 188 insertions(+), 131 deletions(-)
> > > >
> > > > --
> > > > 2.31.1
> > > >  
> >  


^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2021-05-03 11:52 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-26 17:49 [PATCH 0/9] iio: Move more things from iio_dev to iio_dev_opaque Jonathan Cameron
2021-04-26 17:49 ` [PATCH 1/9] iio: core: move @id from struct iio_dev to struct iio_dev_opaque Jonathan Cameron
2021-04-27  7:44   ` Alexandru Ardelean
2021-04-27 17:16     ` Jonathan Cameron
2021-05-03 11:42   ` Jonathan Cameron
2021-04-26 17:49 ` [PATCH 2/9] iio: avoid shadowing of variable name in to_iio_dev_opaque() Jonathan Cameron
2021-04-27  7:45   ` Alexandru Ardelean
2021-04-26 17:49 ` [PATCH 3/9] iio: core: move @driver_module from struct iio_dev to struct iio_dev_opaque Jonathan Cameron
2021-04-28  6:55   ` Alexandru Ardelean
2021-04-26 17:49 ` [PATCH 4/9] iio: core: move @trig_readonly " Jonathan Cameron
2021-04-27  8:03   ` Alexandru Ardelean
2021-04-26 17:49 ` [PATCH 5/9] iio: core: move @scan_index_timestamp " Jonathan Cameron
2021-04-27  8:03   ` Alexandru Ardelean
2021-04-26 17:49 ` [PATCH 6/9] iio: core: move @info_exist_lock " Jonathan Cameron
2021-04-27  8:04   ` Alexandru Ardelean
2021-04-26 17:49 ` [PATCH 7/9] iio: core: move @chrdev from struct iio_dev " Jonathan Cameron
2021-04-27  8:06   ` Alexandru Ardelean
2021-04-27 17:17     ` Jonathan Cameron
2021-04-26 17:49 ` [PATCH 8/9] iio: core: move @flags " Jonathan Cameron
2021-04-27  8:07   ` Alexandru Ardelean
2021-04-26 17:49 ` [PATCH 9/9] iio: core: move @clock_id " Jonathan Cameron
2021-04-27  8:02   ` Alexandru Ardelean
2021-04-27 17:19     ` Jonathan Cameron
2021-04-27  8:08 ` [PATCH 0/9] iio: Move more things from iio_dev to iio_dev_opaque Alexandru Ardelean
2021-04-27 17:12   ` Jonathan Cameron
2021-04-28  6:55     ` Alexandru Ardelean
2021-05-03 11:53       ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).