linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] iio: kfifo: define a devm_iio_kfifo_buffer_setup helper
@ 2021-02-14 14:33 Alexandru Ardelean
  2021-02-14 14:33 ` [PATCH 1/5] iio: adc: ti_am335x_adc: remove omitted iio_kfifo_free() Alexandru Ardelean
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Alexandru Ardelean @ 2021-02-14 14:33 UTC (permalink / raw)
  To: linux-kernel, linux-iio
  Cc: lars, Michael.Hennerich, jic23, nuno.sa, dragos.bogdan,
	Alexandru Ardelean

This is a re-spin of an older set [1]:
 https://patchwork.kernel.org/project/linux-iio/patch/20200401125936.6398-1-alexandru.ardelean@analog.com/

Patch 'iio: adc: ti_am335x_adc: remove omitted iio_kfifo_free()' is
already be present in a fixes-togreg path. It did not make it yet
downstream in the iio-togreg path.

Following [1], where there was a suggestion to name this
'devm_iio_device_attach_new_kfifo_buffer()', I took another look and
devm_iio_kfifo_buffer_setup() made more sense, since there is already a
'{devm_}iio_triggered_buffer_setup()' helper.

This reduces the usage of the iio_device_attach_buffer() helper to a
more manage-able state.
This is related to comment:
  https://lore.kernel.org/linux-iio/CA+U=Dsp5hxd9=rNbigUMFALBpPVBqDZDRq_Pe69ggKak7p46=w@mail.gmail.com/T/#u

This should have gone before the multibuffer patch-set, but I was still
waiting on patch 'iio: adc: ti_am335x_adc: remove omitted iio_kfifo_free()'
to make it downstream in iio-togreg.

Regarding patch 'iio: kfifo: un-export devm_iio_kfifo_allocate() function'
I would have also wanted to un-export iio_kfifo_allocate() &
iio_kfifo_free(), but that still needs a bit of work to cleanup the IIO
dummy buffer.
Related to patchset:
  https://lore.kernel.org/linux-iio/20201203095005.72252-1-alexandru.ardelean@analog.com/

The IIO dummy driver seems to be one of those blockers in cleaning up
some IIO API.

Alexandru Ardelean (5):
  iio: adc: ti_am335x_adc: remove omitted iio_kfifo_free()
  iio: kfifo: add devm_iio_kfifo_buffer_setup() helper
  iio: make use of devm_iio_kfifo_buffer_setup() helper
  iio: accel: sca3000: use devm_iio_kfifo_buffer_setup() helper
  iio: kfifo: un-export devm_iio_kfifo_allocate() function

 .../driver-api/driver-model/devres.rst        |  2 +-
 drivers/iio/accel/sca3000.c                   | 19 ++-------
 drivers/iio/accel/ssp_accel_sensor.c          | 14 +++----
 drivers/iio/adc/ina2xx-adc.c                  | 14 +++----
 drivers/iio/adc/ti_am335x_adc.c               | 24 +++--------
 drivers/iio/buffer/kfifo_buf.c                | 42 ++++++++++++++++++-
 .../cros_ec_sensors/cros_ec_sensors_core.c    | 13 +++---
 drivers/iio/gyro/ssp_gyro_sensor.c            | 14 +++----
 drivers/iio/health/max30100.c                 | 16 ++++---
 drivers/iio/health/max30102.c                 | 16 ++++---
 .../iio/imu/inv_icm42600/inv_icm42600_accel.c | 14 +++----
 .../iio/imu/inv_icm42600/inv_icm42600_gyro.c  | 13 +++---
 .../iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c    | 15 +++----
 drivers/iio/light/acpi-als.c                  | 12 +++---
 drivers/iio/light/apds9960.c                  | 16 ++++---
 .../staging/iio/impedance-analyzer/ad5933.c   | 23 ++--------
 include/linux/iio/kfifo_buf.h                 |  7 +++-
 17 files changed, 125 insertions(+), 149 deletions(-)

-- 
2.17.1


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

* [PATCH 1/5] iio: adc: ti_am335x_adc: remove omitted iio_kfifo_free()
  2021-02-14 14:33 [PATCH 0/5] iio: kfifo: define a devm_iio_kfifo_buffer_setup helper Alexandru Ardelean
@ 2021-02-14 14:33 ` Alexandru Ardelean
  2021-02-14 14:33 ` [PATCH 2/5] iio: kfifo: add devm_iio_kfifo_buffer_setup() helper Alexandru Ardelean
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Alexandru Ardelean @ 2021-02-14 14:33 UTC (permalink / raw)
  To: linux-kernel, linux-iio
  Cc: lars, Michael.Hennerich, jic23, nuno.sa, dragos.bogdan,
	Alexandru Ardelean

When the conversion was done to use devm_iio_kfifo_allocate(), a call to
iio_kfifo_free() was omitted (to be removed).
This change removes it.

Fixes: 3c5308058899 ("iio: adc: ti_am335x_adc: alloc kfifo & IRQ via devm_ functions")
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/adc/ti_am335x_adc.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index b11c8c47ba2a..e946903b0993 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -397,16 +397,12 @@ static int tiadc_iio_buffered_hardware_setup(struct device *dev,
 	ret = devm_request_threaded_irq(dev, irq, pollfunc_th, pollfunc_bh,
 				flags, indio_dev->name, indio_dev);
 	if (ret)
-		goto error_kfifo_free;
+		return ret;
 
 	indio_dev->setup_ops = setup_ops;
 	indio_dev->modes |= INDIO_BUFFER_SOFTWARE;
 
 	return 0;
-
-error_kfifo_free:
-	iio_kfifo_free(indio_dev->buffer);
-	return ret;
 }
 
 static const char * const chan_name_ain[] = {
-- 
2.17.1


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

* [PATCH 2/5] iio: kfifo: add devm_iio_kfifo_buffer_setup() helper
  2021-02-14 14:33 [PATCH 0/5] iio: kfifo: define a devm_iio_kfifo_buffer_setup helper Alexandru Ardelean
  2021-02-14 14:33 ` [PATCH 1/5] iio: adc: ti_am335x_adc: remove omitted iio_kfifo_free() Alexandru Ardelean
@ 2021-02-14 14:33 ` Alexandru Ardelean
  2021-02-14 14:33 ` [PATCH 3/5] iio: make use of " Alexandru Ardelean
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Alexandru Ardelean @ 2021-02-14 14:33 UTC (permalink / raw)
  To: linux-kernel, linux-iio
  Cc: lars, Michael.Hennerich, jic23, nuno.sa, dragos.bogdan,
	Alexandru Ardelean

This change adds the devm_iio_kfifo_buffer_setup() helper/short-hand,
which groups the simple routine of allocating a kfifo buffers via
devm_iio_kfifo_allocate() and calling iio_device_attach_buffer().

The mode_flags parameter is required, as the IIO kfifo supports 2 modes:
INDIO_BUFFER_SOFTWARE & INDIO_BUFFER_TRIGGERED.
The setup_ops parameter is optional.

This function will be a bit more useful when needing to define multiple
buffers per IIO device.

The naming for this function has been inspired from
iio_triggered_buffer_setup() since that one does a kfifo alloc + a pollfunc
alloc. So, this should have a more familiar ring to what it is.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 .../driver-api/driver-model/devres.rst        |  1 +
 drivers/iio/buffer/kfifo_buf.c                | 39 +++++++++++++++++++
 include/linux/iio/kfifo_buf.h                 |  7 ++++
 3 files changed, 47 insertions(+)

diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst
index cd8b6e657b94..562f5722281e 100644
--- a/Documentation/driver-api/driver-model/devres.rst
+++ b/Documentation/driver-api/driver-model/devres.rst
@@ -286,6 +286,7 @@ IIO
   devm_iio_device_alloc()
   devm_iio_device_register()
   devm_iio_kfifo_allocate()
+  devm_iio_kfifo_buffer_setup()
   devm_iio_triggered_buffer_setup()
   devm_iio_trigger_alloc()
   devm_iio_trigger_register()
diff --git a/drivers/iio/buffer/kfifo_buf.c b/drivers/iio/buffer/kfifo_buf.c
index 1359abed3b31..6472c9fa1937 100644
--- a/drivers/iio/buffer/kfifo_buf.c
+++ b/drivers/iio/buffer/kfifo_buf.c
@@ -206,4 +206,43 @@ struct iio_buffer *devm_iio_kfifo_allocate(struct device *dev)
 }
 EXPORT_SYMBOL(devm_iio_kfifo_allocate);
 
+/**
+ * devm_iio_kfifo_buffer_setup - Allocate a kfifo buffer & attach it to an IIO device
+ * @dev: Device object to which to attach the life-time of this kfifo buffer
+ * @indio_dev: The device the buffer should be attached to
+ * @mode_flags: The mode flags for this buffer (INDIO_BUFFER_SOFTWARE and/or
+ *		INDIO_BUFFER_TRIGGERED).
+ * @setup_ops: The setup_ops required to configure the HW part of the buffer (optional)
+ *
+ * This function allocates a kfifo buffer via devm_iio_kfifo_allocate() and
+ * attaches it to the IIO device via iio_device_attach_buffer().
+ * This is meant to be a bit of a short-hand/helper function as there are a few
+ * drivers that seem to do this.
+ */
+int devm_iio_kfifo_buffer_setup(struct device *dev,
+				struct iio_dev *indio_dev,
+				int mode_flags,
+				const struct iio_buffer_setup_ops *setup_ops)
+{
+	struct iio_buffer *buffer;
+
+	if (mode_flags)
+		mode_flags &= kfifo_access_funcs.modes;
+
+	if (!mode_flags)
+		return -EINVAL;
+
+	buffer = devm_iio_kfifo_allocate(dev);
+	if (!buffer)
+		return -ENOMEM;
+
+	iio_device_attach_buffer(indio_dev, buffer);
+
+	indio_dev->modes |= mode_flags;
+	indio_dev->setup_ops = setup_ops;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(devm_iio_kfifo_buffer_setup);
+
 MODULE_LICENSE("GPL");
diff --git a/include/linux/iio/kfifo_buf.h b/include/linux/iio/kfifo_buf.h
index 1fc1efa7799d..92c411b9ac26 100644
--- a/include/linux/iio/kfifo_buf.h
+++ b/include/linux/iio/kfifo_buf.h
@@ -3,6 +3,8 @@
 #define __LINUX_IIO_KFIFO_BUF_H__
 
 struct iio_buffer;
+struct iio_buffer_setup_ops;
+struct iio_dev;
 struct device;
 
 struct iio_buffer *iio_kfifo_allocate(void);
@@ -10,4 +12,9 @@ void iio_kfifo_free(struct iio_buffer *r);
 
 struct iio_buffer *devm_iio_kfifo_allocate(struct device *dev);
 
+int devm_iio_kfifo_buffer_setup(struct device *dev,
+				struct iio_dev *indio_dev,
+				int mode_flags,
+				const struct iio_buffer_setup_ops *setup_ops);
+
 #endif
-- 
2.17.1


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

* [PATCH 3/5] iio: make use of devm_iio_kfifo_buffer_setup() helper
  2021-02-14 14:33 [PATCH 0/5] iio: kfifo: define a devm_iio_kfifo_buffer_setup helper Alexandru Ardelean
  2021-02-14 14:33 ` [PATCH 1/5] iio: adc: ti_am335x_adc: remove omitted iio_kfifo_free() Alexandru Ardelean
  2021-02-14 14:33 ` [PATCH 2/5] iio: kfifo: add devm_iio_kfifo_buffer_setup() helper Alexandru Ardelean
@ 2021-02-14 14:33 ` Alexandru Ardelean
  2021-02-14 14:33 ` [PATCH 4/5] iio: accel: sca3000: use " Alexandru Ardelean
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Alexandru Ardelean @ 2021-02-14 14:33 UTC (permalink / raw)
  To: linux-kernel, linux-iio
  Cc: lars, Michael.Hennerich, jic23, nuno.sa, dragos.bogdan,
	Alexandru Ardelean

All drivers that already call devm_iio_kfifo_allocate() &
iio_device_attach_buffer() are simple to convert to
iio_device_attach_kfifo_buffer() in a single go.

This change does that; the unwind order is preserved.
What is important, is that the devm_iio_kfifo_buffer_setup() be called
after the indio_dev->modes is assigned, to make sure that
INDIO_BUFFER_SOFTWARE flag is set and not overridden by the assignment to
indio_dev->modes.

Also, the INDIO_BUFFER_SOFTWARE has been removed from the assignments of
'indio_dev->modes' because it is set by devm_iio_kfifo_buffer_setup().

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/accel/ssp_accel_sensor.c          | 14 ++++-------
 drivers/iio/adc/ina2xx-adc.c                  | 14 +++++------
 drivers/iio/adc/ti_am335x_adc.c               | 18 ++++-----------
 .../cros_ec_sensors/cros_ec_sensors_core.c    | 13 ++++-------
 drivers/iio/gyro/ssp_gyro_sensor.c            | 14 ++++-------
 drivers/iio/health/max30100.c                 | 16 ++++++-------
 drivers/iio/health/max30102.c                 | 16 ++++++-------
 .../iio/imu/inv_icm42600/inv_icm42600_accel.c | 14 +++++------
 .../iio/imu/inv_icm42600/inv_icm42600_gyro.c  | 13 +++++------
 .../iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c    | 15 +++++-------
 drivers/iio/light/acpi-als.c                  | 12 ++++------
 drivers/iio/light/apds9960.c                  | 16 ++++++-------
 .../staging/iio/impedance-analyzer/ad5933.c   | 23 ++++---------------
 13 files changed, 74 insertions(+), 124 deletions(-)

diff --git a/drivers/iio/accel/ssp_accel_sensor.c b/drivers/iio/accel/ssp_accel_sensor.c
index 474477e91b5e..04dcb2b657ee 100644
--- a/drivers/iio/accel/ssp_accel_sensor.c
+++ b/drivers/iio/accel/ssp_accel_sensor.c
@@ -96,7 +96,6 @@ static int ssp_accel_probe(struct platform_device *pdev)
 	int ret;
 	struct iio_dev *indio_dev;
 	struct ssp_sensor_data *spd;
-	struct iio_buffer *buffer;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*spd));
 	if (!indio_dev)
@@ -109,18 +108,15 @@ static int ssp_accel_probe(struct platform_device *pdev)
 
 	indio_dev->name = ssp_accel_device_name;
 	indio_dev->info = &ssp_accel_iio_info;
-	indio_dev->modes = INDIO_BUFFER_SOFTWARE;
 	indio_dev->channels = ssp_acc_channels;
 	indio_dev->num_channels = ARRAY_SIZE(ssp_acc_channels);
 	indio_dev->available_scan_masks = ssp_accel_scan_mask;
 
-	buffer = devm_iio_kfifo_allocate(&pdev->dev);
-	if (!buffer)
-		return -ENOMEM;
-
-	iio_device_attach_buffer(indio_dev, buffer);
-
-	indio_dev->setup_ops = &ssp_accel_buffer_ops;
+	ret = devm_iio_kfifo_buffer_setup(&pdev->dev, indio_dev,
+					  INDIO_BUFFER_SOFTWARE,
+					  &ssp_accel_buffer_ops);
+	if (ret)
+		return ret;
 
 	platform_set_drvdata(pdev, indio_dev);
 
diff --git a/drivers/iio/adc/ina2xx-adc.c b/drivers/iio/adc/ina2xx-adc.c
index b573ec60a8b8..2ae54258b221 100644
--- a/drivers/iio/adc/ina2xx-adc.c
+++ b/drivers/iio/adc/ina2xx-adc.c
@@ -953,7 +953,6 @@ static int ina2xx_probe(struct i2c_client *client,
 {
 	struct ina2xx_chip_info *chip;
 	struct iio_dev *indio_dev;
-	struct iio_buffer *buffer;
 	unsigned int val;
 	enum ina2xx_ids type;
 	int ret;
@@ -1017,7 +1016,7 @@ static int ina2xx_probe(struct i2c_client *client,
 		return ret;
 	}
 
-	indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE;
+	indio_dev->modes = INDIO_DIRECT_MODE;
 	if (id->driver_data == ina226) {
 		indio_dev->channels = ina226_channels;
 		indio_dev->num_channels = ARRAY_SIZE(ina226_channels);
@@ -1028,13 +1027,12 @@ static int ina2xx_probe(struct i2c_client *client,
 		indio_dev->info = &ina219_info;
 	}
 	indio_dev->name = id->name;
-	indio_dev->setup_ops = &ina2xx_setup_ops;
 
-	buffer = devm_iio_kfifo_allocate(&indio_dev->dev);
-	if (!buffer)
-		return -ENOMEM;
-
-	iio_device_attach_buffer(indio_dev, buffer);
+	ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev,
+					  INDIO_BUFFER_SOFTWARE,
+					  &ina2xx_setup_ops);
+	if (ret)
+		return ret;
 
 	return iio_device_register(indio_dev);
 }
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index e946903b0993..855cc2d64ac8 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -385,24 +385,16 @@ static int tiadc_iio_buffered_hardware_setup(struct device *dev,
 	unsigned long flags,
 	const struct iio_buffer_setup_ops *setup_ops)
 {
-	struct iio_buffer *buffer;
 	int ret;
 
-	buffer = devm_iio_kfifo_allocate(dev);
-	if (!buffer)
-		return -ENOMEM;
-
-	iio_device_attach_buffer(indio_dev, buffer);
-
-	ret = devm_request_threaded_irq(dev, irq, pollfunc_th, pollfunc_bh,
-				flags, indio_dev->name, indio_dev);
+	ret = devm_iio_kfifo_buffer_setup(dev, indio_dev,
+					  INDIO_BUFFER_SOFTWARE,
+					  setup_ops);
 	if (ret)
 		return ret;
 
-	indio_dev->setup_ops = setup_ops;
-	indio_dev->modes |= INDIO_BUFFER_SOFTWARE;
-
-	return 0;
+	return devm_request_threaded_irq(dev, irq, pollfunc_th, pollfunc_bh,
+				flags, indio_dev->name, indio_dev);
 }
 
 static const char * const chan_name_ain[] = {
diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
index c833ec0ef214..f8824afe595e 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
@@ -334,14 +334,11 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
 			 * We can not use trigger here, as events are generated
 			 * as soon as sample_frequency is set.
 			 */
-			struct iio_buffer *buffer;
-
-			buffer = devm_iio_kfifo_allocate(dev);
-			if (!buffer)
-				return -ENOMEM;
-
-			iio_device_attach_buffer(indio_dev, buffer);
-			indio_dev->modes = INDIO_BUFFER_SOFTWARE;
+			ret = devm_iio_kfifo_buffer_setup(dev, indio_dev,
+							  INDIO_BUFFER_SOFTWARE,
+							  NULL);
+			if (ret)
+				return ret;
 
 			ret = cros_ec_sensorhub_register_push_data(
 					sensor_hub, sensor_platform->sensor_num,
diff --git a/drivers/iio/gyro/ssp_gyro_sensor.c b/drivers/iio/gyro/ssp_gyro_sensor.c
index ac7c170a20de..46ed12771d2f 100644
--- a/drivers/iio/gyro/ssp_gyro_sensor.c
+++ b/drivers/iio/gyro/ssp_gyro_sensor.c
@@ -96,7 +96,6 @@ static int ssp_gyro_probe(struct platform_device *pdev)
 	int ret;
 	struct iio_dev *indio_dev;
 	struct ssp_sensor_data *spd;
-	struct iio_buffer *buffer;
 
 	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*spd));
 	if (!indio_dev)
@@ -109,18 +108,15 @@ static int ssp_gyro_probe(struct platform_device *pdev)
 
 	indio_dev->name = ssp_gyro_name;
 	indio_dev->info = &ssp_gyro_iio_info;
-	indio_dev->modes = INDIO_BUFFER_SOFTWARE;
 	indio_dev->channels = ssp_gyro_channels;
 	indio_dev->num_channels = ARRAY_SIZE(ssp_gyro_channels);
 	indio_dev->available_scan_masks = ssp_gyro_scan_mask;
 
-	buffer = devm_iio_kfifo_allocate(&pdev->dev);
-	if (!buffer)
-		return -ENOMEM;
-
-	iio_device_attach_buffer(indio_dev, buffer);
-
-	indio_dev->setup_ops = &ssp_gyro_buffer_ops;
+	ret = devm_iio_kfifo_buffer_setup(&pdev->dev, indio_dev,
+					  INDIO_BUFFER_SOFTWARE,
+					  &ssp_gyro_buffer_ops);
+	if (ret)
+		return ret;
 
 	platform_set_drvdata(pdev, indio_dev);
 
diff --git a/drivers/iio/health/max30100.c b/drivers/iio/health/max30100.c
index 38aa2030f3c6..36ba7611d9ce 100644
--- a/drivers/iio/health/max30100.c
+++ b/drivers/iio/health/max30100.c
@@ -418,7 +418,6 @@ static int max30100_probe(struct i2c_client *client,
 			  const struct i2c_device_id *id)
 {
 	struct max30100_data *data;
-	struct iio_buffer *buffer;
 	struct iio_dev *indio_dev;
 	int ret;
 
@@ -426,19 +425,18 @@ static int max30100_probe(struct i2c_client *client,
 	if (!indio_dev)
 		return -ENOMEM;
 
-	buffer = devm_iio_kfifo_allocate(&client->dev);
-	if (!buffer)
-		return -ENOMEM;
-
-	iio_device_attach_buffer(indio_dev, buffer);
-
 	indio_dev->name = MAX30100_DRV_NAME;
 	indio_dev->channels = max30100_channels;
 	indio_dev->info = &max30100_info;
 	indio_dev->num_channels = ARRAY_SIZE(max30100_channels);
 	indio_dev->available_scan_masks = max30100_scan_masks;
-	indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE);
-	indio_dev->setup_ops = &max30100_buffer_setup_ops;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+
+	ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev,
+					  INDIO_BUFFER_SOFTWARE,
+					  &max30100_buffer_setup_ops);
+	if (ret)
+		return ret;
 
 	data = iio_priv(indio_dev);
 	data->indio_dev = indio_dev;
diff --git a/drivers/iio/health/max30102.c b/drivers/iio/health/max30102.c
index b35557a54ee2..2292876c55e2 100644
--- a/drivers/iio/health/max30102.c
+++ b/drivers/iio/health/max30102.c
@@ -506,7 +506,6 @@ static int max30102_probe(struct i2c_client *client,
 			  const struct i2c_device_id *id)
 {
 	struct max30102_data *data;
-	struct iio_buffer *buffer;
 	struct iio_dev *indio_dev;
 	int ret;
 	unsigned int reg;
@@ -515,16 +514,9 @@ static int max30102_probe(struct i2c_client *client,
 	if (!indio_dev)
 		return -ENOMEM;
 
-	buffer = devm_iio_kfifo_allocate(&client->dev);
-	if (!buffer)
-		return -ENOMEM;
-
-	iio_device_attach_buffer(indio_dev, buffer);
-
 	indio_dev->name = MAX30102_DRV_NAME;
 	indio_dev->info = &max30102_info;
-	indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE);
-	indio_dev->setup_ops = &max30102_buffer_setup_ops;
+	indio_dev->modes = INDIO_DIRECT_MODE;
 
 	data = iio_priv(indio_dev);
 	data->indio_dev = indio_dev;
@@ -549,6 +541,12 @@ static int max30102_probe(struct i2c_client *client,
 		return -ENODEV;
 	}
 
+	ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev,
+					  INDIO_BUFFER_SOFTWARE,
+					  &max30102_buffer_setup_ops);
+	if (ret)
+		return ret;
+
 	data->regmap = devm_regmap_init_i2c(client, &max30102_regmap_config);
 	if (IS_ERR(data->regmap)) {
 		dev_err(&client->dev, "regmap initialization failed\n");
diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
index 3441b0d61c5d..383cc3250342 100644
--- a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
+++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
@@ -709,7 +709,6 @@ struct iio_dev *inv_icm42600_accel_init(struct inv_icm42600_state *st)
 	const char *name;
 	struct inv_icm42600_timestamp *ts;
 	struct iio_dev *indio_dev;
-	struct iio_buffer *buffer;
 	int ret;
 
 	name = devm_kasprintf(dev, GFP_KERNEL, "%s-accel", st->name);
@@ -720,23 +719,22 @@ struct iio_dev *inv_icm42600_accel_init(struct inv_icm42600_state *st)
 	if (!indio_dev)
 		return ERR_PTR(-ENOMEM);
 
-	buffer = devm_iio_kfifo_allocate(dev);
-	if (!buffer)
-		return ERR_PTR(-ENOMEM);
-
 	ts = iio_priv(indio_dev);
 	inv_icm42600_timestamp_init(ts, inv_icm42600_odr_to_period(st->conf.accel.odr));
 
 	iio_device_set_drvdata(indio_dev, st);
 	indio_dev->name = name;
 	indio_dev->info = &inv_icm42600_accel_info;
-	indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE;
+	indio_dev->modes = INDIO_DIRECT_MODE;
 	indio_dev->channels = inv_icm42600_accel_channels;
 	indio_dev->num_channels = ARRAY_SIZE(inv_icm42600_accel_channels);
 	indio_dev->available_scan_masks = inv_icm42600_accel_scan_masks;
-	indio_dev->setup_ops = &inv_icm42600_buffer_ops;
 
-	iio_device_attach_buffer(indio_dev, buffer);
+	ret = devm_iio_kfifo_buffer_setup(dev, indio_dev,
+					  INDIO_BUFFER_SOFTWARE,
+					  &inv_icm42600_buffer_ops);
+	if (ret)
+		return ERR_PTR(ret);
 
 	ret = devm_iio_device_register(dev, indio_dev);
 	if (ret)
diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c
index aee7b9ff4bf4..cec1dd0e0464 100644
--- a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c
+++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c
@@ -720,7 +720,6 @@ struct iio_dev *inv_icm42600_gyro_init(struct inv_icm42600_state *st)
 	const char *name;
 	struct inv_icm42600_timestamp *ts;
 	struct iio_dev *indio_dev;
-	struct iio_buffer *buffer;
 	int ret;
 
 	name = devm_kasprintf(dev, GFP_KERNEL, "%s-gyro", st->name);
@@ -731,23 +730,23 @@ struct iio_dev *inv_icm42600_gyro_init(struct inv_icm42600_state *st)
 	if (!indio_dev)
 		return ERR_PTR(-ENOMEM);
 
-	buffer = devm_iio_kfifo_allocate(dev);
-	if (!buffer)
-		return ERR_PTR(-ENOMEM);
-
 	ts = iio_priv(indio_dev);
 	inv_icm42600_timestamp_init(ts, inv_icm42600_odr_to_period(st->conf.gyro.odr));
 
 	iio_device_set_drvdata(indio_dev, st);
 	indio_dev->name = name;
 	indio_dev->info = &inv_icm42600_gyro_info;
-	indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE;
+	indio_dev->modes = INDIO_DIRECT_MODE;
 	indio_dev->channels = inv_icm42600_gyro_channels;
 	indio_dev->num_channels = ARRAY_SIZE(inv_icm42600_gyro_channels);
 	indio_dev->available_scan_masks = inv_icm42600_gyro_scan_masks;
 	indio_dev->setup_ops = &inv_icm42600_buffer_ops;
 
-	iio_device_attach_buffer(indio_dev, buffer);
+	ret = devm_iio_kfifo_buffer_setup(dev, indio_dev,
+					  INDIO_BUFFER_SOFTWARE,
+					  &inv_icm42600_buffer_ops);
+	if (ret)
+		return ERR_PTR(ret);
 
 	ret = devm_iio_device_register(dev, indio_dev);
 	if (ret)
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
index f1103ecedd64..16730a780964 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
@@ -739,20 +739,17 @@ static const struct iio_buffer_setup_ops st_lsm6dsx_buffer_ops = {
 
 int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw)
 {
-	struct iio_buffer *buffer;
-	int i;
+	int i, ret;
 
 	for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) {
 		if (!hw->iio_devs[i])
 			continue;
 
-		buffer = devm_iio_kfifo_allocate(hw->dev);
-		if (!buffer)
-			return -ENOMEM;
-
-		iio_device_attach_buffer(hw->iio_devs[i], buffer);
-		hw->iio_devs[i]->modes |= INDIO_BUFFER_SOFTWARE;
-		hw->iio_devs[i]->setup_ops = &st_lsm6dsx_buffer_ops;
+		ret = devm_iio_kfifo_buffer_setup(hw->dev, hw->iio_devs[i],
+						  INDIO_BUFFER_SOFTWARE,
+						  &st_lsm6dsx_buffer_ops);
+		if (ret)
+			return ret;
 	}
 
 	return 0;
diff --git a/drivers/iio/light/acpi-als.c b/drivers/iio/light/acpi-als.c
index 2be7180e2cbf..f8e547fd35e7 100644
--- a/drivers/iio/light/acpi-als.c
+++ b/drivers/iio/light/acpi-als.c
@@ -165,7 +165,7 @@ static int acpi_als_add(struct acpi_device *device)
 {
 	struct acpi_als *als;
 	struct iio_dev *indio_dev;
-	struct iio_buffer *buffer;
+	int ret;
 
 	indio_dev = devm_iio_device_alloc(&device->dev, sizeof(*als));
 	if (!indio_dev)
@@ -179,15 +179,13 @@ static int acpi_als_add(struct acpi_device *device)
 
 	indio_dev->name = ACPI_ALS_DEVICE_NAME;
 	indio_dev->info = &acpi_als_info;
-	indio_dev->modes = INDIO_BUFFER_SOFTWARE;
 	indio_dev->channels = acpi_als_channels;
 	indio_dev->num_channels = ARRAY_SIZE(acpi_als_channels);
 
-	buffer = devm_iio_kfifo_allocate(&device->dev);
-	if (!buffer)
-		return -ENOMEM;
-
-	iio_device_attach_buffer(indio_dev, buffer);
+	ret = devm_iio_kfifo_buffer_setup(&device->dev, indio_dev,
+					  INDIO_BUFFER_SOFTWARE, NULL);
+	if (ret)
+		return ret;
 
 	return devm_iio_device_register(&device->dev, indio_dev);
 }
diff --git a/drivers/iio/light/apds9960.c b/drivers/iio/light/apds9960.c
index df0647856e5d..4141c0fa7bc4 100644
--- a/drivers/iio/light/apds9960.c
+++ b/drivers/iio/light/apds9960.c
@@ -988,7 +988,6 @@ static int apds9960_probe(struct i2c_client *client,
 			  const struct i2c_device_id *id)
 {
 	struct apds9960_data *data;
-	struct iio_buffer *buffer;
 	struct iio_dev *indio_dev;
 	int ret;
 
@@ -996,19 +995,18 @@ static int apds9960_probe(struct i2c_client *client,
 	if (!indio_dev)
 		return -ENOMEM;
 
-	buffer = devm_iio_kfifo_allocate(&client->dev);
-	if (!buffer)
-		return -ENOMEM;
-
-	iio_device_attach_buffer(indio_dev, buffer);
-
 	indio_dev->info = &apds9960_info;
 	indio_dev->name = APDS9960_DRV_NAME;
 	indio_dev->channels = apds9960_channels;
 	indio_dev->num_channels = ARRAY_SIZE(apds9960_channels);
 	indio_dev->available_scan_masks = apds9960_scan_masks;
-	indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE);
-	indio_dev->setup_ops = &apds9960_buffer_setup_ops;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+
+	ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev,
+					  INDIO_BUFFER_SOFTWARE,
+					  &apds9960_buffer_setup_ops);
+	if (ret)
+		return ret;
 
 	data = iio_priv(indio_dev);
 	i2c_set_clientdata(client, indio_dev);
diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c
index dba78896ea8f..793918e1c45f 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -602,23 +602,6 @@ static const struct iio_buffer_setup_ops ad5933_ring_setup_ops = {
 	.postdisable = ad5933_ring_postdisable,
 };
 
-static int ad5933_register_ring_funcs_and_init(struct device *dev,
-					       struct iio_dev *indio_dev)
-{
-	struct iio_buffer *buffer;
-
-	buffer = devm_iio_kfifo_allocate(dev);
-	if (!buffer)
-		return -ENOMEM;
-
-	iio_device_attach_buffer(indio_dev, buffer);
-
-	/* Ring buffer functions - here trigger setup related */
-	indio_dev->setup_ops = &ad5933_ring_setup_ops;
-
-	return 0;
-}
-
 static void ad5933_work(struct work_struct *work)
 {
 	struct ad5933_state *st = container_of(work,
@@ -761,11 +744,13 @@ static int ad5933_probe(struct i2c_client *client,
 
 	indio_dev->info = &ad5933_info;
 	indio_dev->name = id->name;
-	indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE);
+	indio_dev->modes = INDIO_DIRECT_MODE;
 	indio_dev->channels = ad5933_channels;
 	indio_dev->num_channels = ARRAY_SIZE(ad5933_channels);
 
-	ret = ad5933_register_ring_funcs_and_init(&client->dev, indio_dev);
+	ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev,
+					  INDIO_BUFFER_SOFTWARE,
+					  &ad5933_ring_setup_ops);
 	if (ret)
 		return ret;
 
-- 
2.17.1


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

* [PATCH 4/5] iio: accel: sca3000: use devm_iio_kfifo_buffer_setup() helper
  2021-02-14 14:33 [PATCH 0/5] iio: kfifo: define a devm_iio_kfifo_buffer_setup helper Alexandru Ardelean
                   ` (2 preceding siblings ...)
  2021-02-14 14:33 ` [PATCH 3/5] iio: make use of " Alexandru Ardelean
@ 2021-02-14 14:33 ` Alexandru Ardelean
  2021-02-14 14:33 ` [PATCH 5/5] iio: kfifo: un-export devm_iio_kfifo_allocate() function Alexandru Ardelean
  2021-02-14 15:05 ` [PATCH 0/5] iio: kfifo: define a devm_iio_kfifo_buffer_setup helper Jonathan Cameron
  5 siblings, 0 replies; 9+ messages in thread
From: Alexandru Ardelean @ 2021-02-14 14:33 UTC (permalink / raw)
  To: linux-kernel, linux-iio
  Cc: lars, Michael.Hennerich, jic23, nuno.sa, dragos.bogdan,
	Alexandru Ardelean

This change makes use of the devm_iio_kfifo_buffer_setup() helper, however
the unwind order is changed.
The life-time of the kfifo object is attached to the parent device object.
This is to make the driver a bit more consistent with the other IIO
drivers, even though (as it is now before this change) it shouldn't be a
problem.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/accel/sca3000.c | 19 +++----------------
 1 file changed, 3 insertions(+), 16 deletions(-)

diff --git a/drivers/iio/accel/sca3000.c b/drivers/iio/accel/sca3000.c
index 194738660523..467b5fcb81db 100644
--- a/drivers/iio/accel/sca3000.c
+++ b/drivers/iio/accel/sca3000.c
@@ -1272,20 +1272,6 @@ static int sca3000_write_event_config(struct iio_dev *indio_dev,
 	return ret;
 }
 
-static int sca3000_configure_ring(struct iio_dev *indio_dev)
-{
-	struct iio_buffer *buffer;
-
-	buffer = devm_iio_kfifo_allocate(&indio_dev->dev);
-	if (!buffer)
-		return -ENOMEM;
-
-	iio_device_attach_buffer(indio_dev, buffer);
-	indio_dev->modes |= INDIO_BUFFER_SOFTWARE;
-
-	return 0;
-}
-
 static inline
 int __sca3000_hw_ring_state_set(struct iio_dev *indio_dev, bool state)
 {
@@ -1479,7 +1465,9 @@ static int sca3000_probe(struct spi_device *spi)
 	}
 	indio_dev->modes = INDIO_DIRECT_MODE;
 
-	ret = sca3000_configure_ring(indio_dev);
+	ret = devm_iio_kfifo_buffer_setup(&spi->dev, indio_dev,
+					  INDIO_BUFFER_SOFTWARE,
+					  &sca3000_ring_setup_ops);
 	if (ret)
 		return ret;
 
@@ -1493,7 +1481,6 @@ static int sca3000_probe(struct spi_device *spi)
 		if (ret)
 			return ret;
 	}
-	indio_dev->setup_ops = &sca3000_ring_setup_ops;
 	ret = sca3000_clean_setup(st);
 	if (ret)
 		goto error_free_irq;
-- 
2.17.1


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

* [PATCH 5/5] iio: kfifo: un-export devm_iio_kfifo_allocate() function
  2021-02-14 14:33 [PATCH 0/5] iio: kfifo: define a devm_iio_kfifo_buffer_setup helper Alexandru Ardelean
                   ` (3 preceding siblings ...)
  2021-02-14 14:33 ` [PATCH 4/5] iio: accel: sca3000: use " Alexandru Ardelean
@ 2021-02-14 14:33 ` Alexandru Ardelean
  2021-02-14 15:05 ` [PATCH 0/5] iio: kfifo: define a devm_iio_kfifo_buffer_setup helper Jonathan Cameron
  5 siblings, 0 replies; 9+ messages in thread
From: Alexandru Ardelean @ 2021-02-14 14:33 UTC (permalink / raw)
  To: linux-kernel, linux-iio
  Cc: lars, Michael.Hennerich, jic23, nuno.sa, dragos.bogdan,
	Alexandru Ardelean

At this point all drivers should use devm_iio_kfifo_buffer_setup() instead
of manually allocating via devm_iio_kfifo_allocate() and assigning ops and
modes.

With this change, the devm_iio_kfifo_allocate() will be made private to the
IIO core, since all drivers should call either
devm_iio_kfifo_buffer_setup() or devm_iio_triggered_buffer_setup() to
create a kfifo buffer.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 Documentation/driver-api/driver-model/devres.rst | 1 -
 drivers/iio/buffer/kfifo_buf.c                   | 3 +--
 include/linux/iio/kfifo_buf.h                    | 2 --
 3 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst
index 562f5722281e..4b15b3e9358b 100644
--- a/Documentation/driver-api/driver-model/devres.rst
+++ b/Documentation/driver-api/driver-model/devres.rst
@@ -285,7 +285,6 @@ I2C
 IIO
   devm_iio_device_alloc()
   devm_iio_device_register()
-  devm_iio_kfifo_allocate()
   devm_iio_kfifo_buffer_setup()
   devm_iio_triggered_buffer_setup()
   devm_iio_trigger_alloc()
diff --git a/drivers/iio/buffer/kfifo_buf.c b/drivers/iio/buffer/kfifo_buf.c
index 6472c9fa1937..c35a625280b1 100644
--- a/drivers/iio/buffer/kfifo_buf.c
+++ b/drivers/iio/buffer/kfifo_buf.c
@@ -186,7 +186,7 @@ static void devm_iio_kfifo_release(struct device *dev, void *res)
  * RETURNS:
  * Pointer to allocated iio_buffer on success, NULL on failure.
  */
-struct iio_buffer *devm_iio_kfifo_allocate(struct device *dev)
+static struct iio_buffer *devm_iio_kfifo_allocate(struct device *dev)
 {
 	struct iio_buffer **ptr, *r;
 
@@ -204,7 +204,6 @@ struct iio_buffer *devm_iio_kfifo_allocate(struct device *dev)
 
 	return r;
 }
-EXPORT_SYMBOL(devm_iio_kfifo_allocate);
 
 /**
  * devm_iio_kfifo_buffer_setup - Allocate a kfifo buffer & attach it to an IIO device
diff --git a/include/linux/iio/kfifo_buf.h b/include/linux/iio/kfifo_buf.h
index 92c411b9ac26..1522896e1daf 100644
--- a/include/linux/iio/kfifo_buf.h
+++ b/include/linux/iio/kfifo_buf.h
@@ -10,8 +10,6 @@ struct device;
 struct iio_buffer *iio_kfifo_allocate(void);
 void iio_kfifo_free(struct iio_buffer *r);
 
-struct iio_buffer *devm_iio_kfifo_allocate(struct device *dev);
-
 int devm_iio_kfifo_buffer_setup(struct device *dev,
 				struct iio_dev *indio_dev,
 				int mode_flags,
-- 
2.17.1


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

* Re: [PATCH 0/5] iio: kfifo: define a devm_iio_kfifo_buffer_setup helper
  2021-02-14 14:33 [PATCH 0/5] iio: kfifo: define a devm_iio_kfifo_buffer_setup helper Alexandru Ardelean
                   ` (4 preceding siblings ...)
  2021-02-14 14:33 ` [PATCH 5/5] iio: kfifo: un-export devm_iio_kfifo_allocate() function Alexandru Ardelean
@ 2021-02-14 15:05 ` Jonathan Cameron
  2021-02-14 16:07   ` Alexandru Ardelean
  2021-02-15  7:25   ` Alexandru Ardelean
  5 siblings, 2 replies; 9+ messages in thread
From: Jonathan Cameron @ 2021-02-14 15:05 UTC (permalink / raw)
  To: Alexandru Ardelean
  Cc: linux-kernel, linux-iio, lars, Michael.Hennerich, nuno.sa, dragos.bogdan

On Sun, 14 Feb 2021 16:33:08 +0200
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:

> This is a re-spin of an older set [1]:
>  https://patchwork.kernel.org/project/linux-iio/patch/20200401125936.6398-1-alexandru.ardelean@analog.com/
> 
> Patch 'iio: adc: ti_am335x_adc: remove omitted iio_kfifo_free()' is
> already be present in a fixes-togreg path. It did not make it yet
> downstream in the iio-togreg path.
> 
> Following [1], where there was a suggestion to name this
> 'devm_iio_device_attach_new_kfifo_buffer()', I took another look and
> devm_iio_kfifo_buffer_setup() made more sense, since there is already a
> '{devm_}iio_triggered_buffer_setup()' helper.
> 
> This reduces the usage of the iio_device_attach_buffer() helper to a
> more manage-able state.
> This is related to comment:
>   https://lore.kernel.org/linux-iio/CA+U=Dsp5hxd9=rNbigUMFALBpPVBqDZDRq_Pe69ggKak7p46=w@mail.gmail.com/T/#u
This definitely reduces where we need to handle errors from iio_device_attach_buffer() which
is good.  I guess we need a rebase of one or the other series though to make
this all fit together.

> 
> This should have gone before the multibuffer patch-set, but I was still
> waiting on patch 'iio: adc: ti_am335x_adc: remove omitted iio_kfifo_free()'
> to make it downstream in iio-togreg.

Oops. I've been a touch slow sending things onwards recently.

> 
> Regarding patch 'iio: kfifo: un-export devm_iio_kfifo_allocate() function'
> I would have also wanted to un-export iio_kfifo_allocate() &
> iio_kfifo_free(), but that still needs a bit of work to cleanup the IIO
> dummy buffer.

Yup. The lack of having a parent is a bit of pain.  We just need to fake one
I guess however silly that seems.

Mind you, I'd also like to see this go over to the triggered_buffer stuff
if possible.


> Related to patchset:
>   https://lore.kernel.org/linux-iio/20201203095005.72252-1-alexandru.ardelean@analog.com/
> 
> The IIO dummy driver seems to be one of those blockers in cleaning up
> some IIO API.
> 

Jonathan

> Alexandru Ardelean (5):
>   iio: adc: ti_am335x_adc: remove omitted iio_kfifo_free()
>   iio: kfifo: add devm_iio_kfifo_buffer_setup() helper
>   iio: make use of devm_iio_kfifo_buffer_setup() helper
>   iio: accel: sca3000: use devm_iio_kfifo_buffer_setup() helper
>   iio: kfifo: un-export devm_iio_kfifo_allocate() function
> 
>  .../driver-api/driver-model/devres.rst        |  2 +-
>  drivers/iio/accel/sca3000.c                   | 19 ++-------
>  drivers/iio/accel/ssp_accel_sensor.c          | 14 +++----
>  drivers/iio/adc/ina2xx-adc.c                  | 14 +++----
>  drivers/iio/adc/ti_am335x_adc.c               | 24 +++--------
>  drivers/iio/buffer/kfifo_buf.c                | 42 ++++++++++++++++++-
>  .../cros_ec_sensors/cros_ec_sensors_core.c    | 13 +++---
>  drivers/iio/gyro/ssp_gyro_sensor.c            | 14 +++----
>  drivers/iio/health/max30100.c                 | 16 ++++---
>  drivers/iio/health/max30102.c                 | 16 ++++---
>  .../iio/imu/inv_icm42600/inv_icm42600_accel.c | 14 +++----
>  .../iio/imu/inv_icm42600/inv_icm42600_gyro.c  | 13 +++---
>  .../iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c    | 15 +++----
>  drivers/iio/light/acpi-als.c                  | 12 +++---
>  drivers/iio/light/apds9960.c                  | 16 ++++---
>  .../staging/iio/impedance-analyzer/ad5933.c   | 23 ++--------
>  include/linux/iio/kfifo_buf.h                 |  7 +++-
>  17 files changed, 125 insertions(+), 149 deletions(-)
> 


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

* Re: [PATCH 0/5] iio: kfifo: define a devm_iio_kfifo_buffer_setup helper
  2021-02-14 15:05 ` [PATCH 0/5] iio: kfifo: define a devm_iio_kfifo_buffer_setup helper Jonathan Cameron
@ 2021-02-14 16:07   ` Alexandru Ardelean
  2021-02-15  7:25   ` Alexandru Ardelean
  1 sibling, 0 replies; 9+ messages in thread
From: Alexandru Ardelean @ 2021-02-14 16:07 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Alexandru Ardelean, LKML, linux-iio, Lars-Peter Clausen,
	Hennerich, Michael, Nuno Sá,
	Bogdan, Dragos

On Sun, Feb 14, 2021 at 5:06 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> On Sun, 14 Feb 2021 16:33:08 +0200
> Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:
>
> > This is a re-spin of an older set [1]:
> >  https://patchwork.kernel.org/project/linux-iio/patch/20200401125936.6398-1-alexandru.ardelean@analog.com/
> >
> > Patch 'iio: adc: ti_am335x_adc: remove omitted iio_kfifo_free()' is
> > already be present in a fixes-togreg path. It did not make it yet
> > downstream in the iio-togreg path.
> >
> > Following [1], where there was a suggestion to name this
> > 'devm_iio_device_attach_new_kfifo_buffer()', I took another look and
> > devm_iio_kfifo_buffer_setup() made more sense, since there is already a
> > '{devm_}iio_triggered_buffer_setup()' helper.
> >
> > This reduces the usage of the iio_device_attach_buffer() helper to a
> > more manage-able state.
> > This is related to comment:
> >   https://lore.kernel.org/linux-iio/CA+U=Dsp5hxd9=rNbigUMFALBpPVBqDZDRq_Pe69ggKak7p46=w@mail.gmail.com/T/#u
> This definitely reduces where we need to handle errors from iio_device_attach_buffer() which
> is good.  I guess we need a rebase of one or the other series though to make
> this all fit together.
>
> >
> > This should have gone before the multibuffer patch-set, but I was still
> > waiting on patch 'iio: adc: ti_am335x_adc: remove omitted iio_kfifo_free()'
> > to make it downstream in iio-togreg.
>
> Oops. I've been a touch slow sending things onwards recently.
>
> >
> > Regarding patch 'iio: kfifo: un-export devm_iio_kfifo_allocate() function'
> > I would have also wanted to un-export iio_kfifo_allocate() &
> > iio_kfifo_free(), but that still needs a bit of work to cleanup the IIO
> > dummy buffer.
>
> Yup. The lack of having a parent is a bit of pain.  We just need to fake one
> I guess however silly that seems.

I tried faking it, but it needs a rework of the
drivers/iio/industrialio-sw-device.c logic.
The whole IIO dummy driver is an IIO SW device, so maybe the sanest
thing, is to create platform devices or just parent devices in there,
and pass the parent to the IIO device.
I tried making the IIO dummy a standalone platform driver, but then
you end up having to probe() paths, 1 via platform_driver and one via
iio-sw-device.

>
> Mind you, I'd also like to see this go over to the triggered_buffer stuff
> if possible.
>
>
> > Related to patchset:
> >   https://lore.kernel.org/linux-iio/20201203095005.72252-1-alexandru.ardelean@analog.com/
> >
> > The IIO dummy driver seems to be one of those blockers in cleaning up
> > some IIO API.
> >
>
> Jonathan
>
> > Alexandru Ardelean (5):
> >   iio: adc: ti_am335x_adc: remove omitted iio_kfifo_free()
> >   iio: kfifo: add devm_iio_kfifo_buffer_setup() helper
> >   iio: make use of devm_iio_kfifo_buffer_setup() helper
> >   iio: accel: sca3000: use devm_iio_kfifo_buffer_setup() helper
> >   iio: kfifo: un-export devm_iio_kfifo_allocate() function
> >
> >  .../driver-api/driver-model/devres.rst        |  2 +-
> >  drivers/iio/accel/sca3000.c                   | 19 ++-------
> >  drivers/iio/accel/ssp_accel_sensor.c          | 14 +++----
> >  drivers/iio/adc/ina2xx-adc.c                  | 14 +++----
> >  drivers/iio/adc/ti_am335x_adc.c               | 24 +++--------
> >  drivers/iio/buffer/kfifo_buf.c                | 42 ++++++++++++++++++-
> >  .../cros_ec_sensors/cros_ec_sensors_core.c    | 13 +++---
> >  drivers/iio/gyro/ssp_gyro_sensor.c            | 14 +++----
> >  drivers/iio/health/max30100.c                 | 16 ++++---
> >  drivers/iio/health/max30102.c                 | 16 ++++---
> >  .../iio/imu/inv_icm42600/inv_icm42600_accel.c | 14 +++----
> >  .../iio/imu/inv_icm42600/inv_icm42600_gyro.c  | 13 +++---
> >  .../iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c    | 15 +++----
> >  drivers/iio/light/acpi-als.c                  | 12 +++---
> >  drivers/iio/light/apds9960.c                  | 16 ++++---
> >  .../staging/iio/impedance-analyzer/ad5933.c   | 23 ++--------
> >  include/linux/iio/kfifo_buf.h                 |  7 +++-
> >  17 files changed, 125 insertions(+), 149 deletions(-)
> >
>

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

* Re: [PATCH 0/5] iio: kfifo: define a devm_iio_kfifo_buffer_setup helper
  2021-02-14 15:05 ` [PATCH 0/5] iio: kfifo: define a devm_iio_kfifo_buffer_setup helper Jonathan Cameron
  2021-02-14 16:07   ` Alexandru Ardelean
@ 2021-02-15  7:25   ` Alexandru Ardelean
  1 sibling, 0 replies; 9+ messages in thread
From: Alexandru Ardelean @ 2021-02-15  7:25 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Alexandru Ardelean, LKML, linux-iio, Lars-Peter Clausen,
	Hennerich, Michael, Nuno Sá,
	Bogdan, Dragos

On Sun, Feb 14, 2021 at 5:06 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> On Sun, 14 Feb 2021 16:33:08 +0200
> Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:
>
> > This is a re-spin of an older set [1]:
> >  https://patchwork.kernel.org/project/linux-iio/patch/20200401125936.6398-1-alexandru.ardelean@analog.com/
> >
> > Patch 'iio: adc: ti_am335x_adc: remove omitted iio_kfifo_free()' is
> > already be present in a fixes-togreg path. It did not make it yet
> > downstream in the iio-togreg path.
> >
> > Following [1], where there was a suggestion to name this
> > 'devm_iio_device_attach_new_kfifo_buffer()', I took another look and
> > devm_iio_kfifo_buffer_setup() made more sense, since there is already a
> > '{devm_}iio_triggered_buffer_setup()' helper.
> >
> > This reduces the usage of the iio_device_attach_buffer() helper to a
> > more manage-able state.
> > This is related to comment:
> >   https://lore.kernel.org/linux-iio/CA+U=Dsp5hxd9=rNbigUMFALBpPVBqDZDRq_Pe69ggKak7p46=w@mail.gmail.com/T/#u
> This definitely reduces where we need to handle errors from iio_device_attach_buffer() which
> is good.  I guess we need a rebase of one or the other series though to make
> this all fit together.
>
> >
> > This should have gone before the multibuffer patch-set, but I was still
> > waiting on patch 'iio: adc: ti_am335x_adc: remove omitted iio_kfifo_free()'
> > to make it downstream in iio-togreg.
>
> Oops. I've been a touch slow sending things onwards recently.
>
> >
> > Regarding patch 'iio: kfifo: un-export devm_iio_kfifo_allocate() function'
> > I would have also wanted to un-export iio_kfifo_allocate() &
> > iio_kfifo_free(), but that still needs a bit of work to cleanup the IIO
> > dummy buffer.
>
> Yup. The lack of having a parent is a bit of pain.  We just need to fake one
> I guess however silly that seems.
>
> Mind you, I'd also like to see this go over to the triggered_buffer stuff
> if possible.

Not sure what should go over the triggered_buffer stuff.
I would have happily done more cleanup there as well, but I'm trying
to defer some things to a later point.
Mostly to avoid blocking myself with too many overlapping patch-sets.

>
>
> > Related to patchset:
> >   https://lore.kernel.org/linux-iio/20201203095005.72252-1-alexandru.ardelean@analog.com/
> >
> > The IIO dummy driver seems to be one of those blockers in cleaning up
> > some IIO API.
> >
>
> Jonathan
>
> > Alexandru Ardelean (5):
> >   iio: adc: ti_am335x_adc: remove omitted iio_kfifo_free()
> >   iio: kfifo: add devm_iio_kfifo_buffer_setup() helper
> >   iio: make use of devm_iio_kfifo_buffer_setup() helper
> >   iio: accel: sca3000: use devm_iio_kfifo_buffer_setup() helper
> >   iio: kfifo: un-export devm_iio_kfifo_allocate() function
> >
> >  .../driver-api/driver-model/devres.rst        |  2 +-
> >  drivers/iio/accel/sca3000.c                   | 19 ++-------
> >  drivers/iio/accel/ssp_accel_sensor.c          | 14 +++----
> >  drivers/iio/adc/ina2xx-adc.c                  | 14 +++----
> >  drivers/iio/adc/ti_am335x_adc.c               | 24 +++--------
> >  drivers/iio/buffer/kfifo_buf.c                | 42 ++++++++++++++++++-
> >  .../cros_ec_sensors/cros_ec_sensors_core.c    | 13 +++---
> >  drivers/iio/gyro/ssp_gyro_sensor.c            | 14 +++----
> >  drivers/iio/health/max30100.c                 | 16 ++++---
> >  drivers/iio/health/max30102.c                 | 16 ++++---
> >  .../iio/imu/inv_icm42600/inv_icm42600_accel.c | 14 +++----
> >  .../iio/imu/inv_icm42600/inv_icm42600_gyro.c  | 13 +++---
> >  .../iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c    | 15 +++----
> >  drivers/iio/light/acpi-als.c                  | 12 +++---
> >  drivers/iio/light/apds9960.c                  | 16 ++++---
> >  .../staging/iio/impedance-analyzer/ad5933.c   | 23 ++--------
> >  include/linux/iio/kfifo_buf.h                 |  7 +++-
> >  17 files changed, 125 insertions(+), 149 deletions(-)
> >
>

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

end of thread, other threads:[~2021-02-15  7:26 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-14 14:33 [PATCH 0/5] iio: kfifo: define a devm_iio_kfifo_buffer_setup helper Alexandru Ardelean
2021-02-14 14:33 ` [PATCH 1/5] iio: adc: ti_am335x_adc: remove omitted iio_kfifo_free() Alexandru Ardelean
2021-02-14 14:33 ` [PATCH 2/5] iio: kfifo: add devm_iio_kfifo_buffer_setup() helper Alexandru Ardelean
2021-02-14 14:33 ` [PATCH 3/5] iio: make use of " Alexandru Ardelean
2021-02-14 14:33 ` [PATCH 4/5] iio: accel: sca3000: use " Alexandru Ardelean
2021-02-14 14:33 ` [PATCH 5/5] iio: kfifo: un-export devm_iio_kfifo_allocate() function Alexandru Ardelean
2021-02-14 15:05 ` [PATCH 0/5] iio: kfifo: define a devm_iio_kfifo_buffer_setup helper Jonathan Cameron
2021-02-14 16:07   ` Alexandru Ardelean
2021-02-15  7:25   ` Alexandru Ardelean

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).