Linux-IIO Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/4] preenable/postenable/predisable fixup for ST drivers
@ 2019-07-30  0:03 Denis Ciocca
  2019-07-30  0:03 ` [PATCH 1/4] iio:accel: preenable/postenable/predisable fixup for ST accel buffer Denis Ciocca
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Denis Ciocca @ 2019-07-30  0:03 UTC (permalink / raw)
  To: linux-iio, jic23; +Cc: alexandru.ardelean, Denis Ciocca

This series is meant to fix for good the functions listed in subject.
In a way, is continuing the task started by Alexandru for accel.


Denis Ciocca (4):
  iio:accel: preenable/postenable/predisable fixup for ST accel buffer
  iio:gyro: preenable/postenable/predisable fixup for ST gyro buffer
  iio:magn: preenable/postenable/predisable fixup for ST magn buffer
  iio:pressure: preenable/postenable/predisable fixup for ST press
    buffer

 drivers/iio/accel/st_accel_buffer.c       | 37 +++++++------------
 drivers/iio/gyro/st_gyro_buffer.c         | 45 ++++++++++-------------
 drivers/iio/magnetometer/st_magn_buffer.c | 22 +++++------
 drivers/iio/pressure/st_pressure_buffer.c | 32 ++++++----------
 4 files changed, 52 insertions(+), 84 deletions(-)

-- 
2.22.0


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

* [PATCH 1/4] iio:accel: preenable/postenable/predisable fixup for ST accel buffer
  2019-07-30  0:03 [PATCH 0/4] preenable/postenable/predisable fixup for ST drivers Denis Ciocca
@ 2019-07-30  0:03 ` Denis Ciocca
  2019-07-30  8:52   ` Ardelean, Alexandru
  2019-07-30  0:03 ` [PATCH 2/4] iio:gyro: preenable/postenable/predisable fixup for ST gyro buffer Denis Ciocca
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Denis Ciocca @ 2019-07-30  0:03 UTC (permalink / raw)
  To: linux-iio, jic23; +Cc: alexandru.ardelean, Denis Ciocca

This patch is trying to cleanup for good the buffers operation functions.
There is no need of using preenable, all can be done into
postenable.
Let's also rename the goto label using operation to perform and not
where it fails.

Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
---
 drivers/iio/accel/st_accel_buffer.c | 37 ++++++++++-------------------
 1 file changed, 13 insertions(+), 24 deletions(-)

diff --git a/drivers/iio/accel/st_accel_buffer.c b/drivers/iio/accel/st_accel_buffer.c
index 05f9aea431e2..81f89da125aa 100644
--- a/drivers/iio/accel/st_accel_buffer.c
+++ b/drivers/iio/accel/st_accel_buffer.c
@@ -29,56 +29,46 @@ int st_accel_trig_set_state(struct iio_trigger *trig, bool state)
 	return st_sensors_set_dataready_irq(indio_dev, state);
 }
 
-static int st_accel_buffer_preenable(struct iio_dev *indio_dev)
-{
-	return st_sensors_set_enable(indio_dev, true);
-}
-
 static int st_accel_buffer_postenable(struct iio_dev *indio_dev)
 {
-	int err;
 	struct st_sensor_data *adata = iio_priv(indio_dev);
+	int err;
 
 	adata->buffer_data = kmalloc(indio_dev->scan_bytes,
 				     GFP_DMA | GFP_KERNEL);
-	if (adata->buffer_data == NULL) {
-		err = -ENOMEM;
-		goto allocate_memory_error;
-	}
+	if (!adata->buffer_data)
+		return -ENOMEM;
 
 	err = iio_triggered_buffer_postenable(indio_dev);
 	if (err < 0)
-		goto st_accel_buffer_postenable_error;
+		goto st_accel_free_buffer;
 
 	err = st_sensors_set_axis_enable(indio_dev,
 					(u8)indio_dev->active_scan_mask[0]);
 	if (err < 0)
-		goto st_sensors_set_axis_enable_error;
+		goto st_accel_buffer_predisable;
 
-	return err;
+	return st_sensors_set_enable(indio_dev, true);
 
-st_sensors_set_axis_enable_error:
+st_accel_buffer_predisable:
 	iio_triggered_buffer_predisable(indio_dev);
-st_accel_buffer_postenable_error:
+st_accel_free_buffer:
 	kfree(adata->buffer_data);
-allocate_memory_error:
 	return err;
 }
 
 static int st_accel_buffer_predisable(struct iio_dev *indio_dev)
 {
-	int err, err2;
 	struct st_sensor_data *adata = iio_priv(indio_dev);
-
-	err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
-	if (err < 0)
-		goto st_accel_buffer_predisable_error;
+	int err, err2;
 
 	err = st_sensors_set_enable(indio_dev, false);
 	if (err < 0)
-		goto st_accel_buffer_predisable_error;
+		goto st_accel_buffer_predisable;
+
+	err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
 
-st_accel_buffer_predisable_error:
+st_accel_buffer_predisable:
 	err2 = iio_triggered_buffer_predisable(indio_dev);
 	if (!err)
 		err = err2;
@@ -88,7 +78,6 @@ static int st_accel_buffer_predisable(struct iio_dev *indio_dev)
 }
 
 static const struct iio_buffer_setup_ops st_accel_buffer_setup_ops = {
-	.preenable = &st_accel_buffer_preenable,
 	.postenable = &st_accel_buffer_postenable,
 	.predisable = &st_accel_buffer_predisable,
 };
-- 
2.22.0


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

* [PATCH 2/4] iio:gyro: preenable/postenable/predisable fixup for ST gyro buffer
  2019-07-30  0:03 [PATCH 0/4] preenable/postenable/predisable fixup for ST drivers Denis Ciocca
  2019-07-30  0:03 ` [PATCH 1/4] iio:accel: preenable/postenable/predisable fixup for ST accel buffer Denis Ciocca
@ 2019-07-30  0:03 ` Denis Ciocca
  2019-07-30  8:52   ` Ardelean, Alexandru
  2019-07-30  0:03 ` [PATCH 3/4] iio:magn: preenable/postenable/predisable fixup for ST magn buffer Denis Ciocca
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Denis Ciocca @ 2019-07-30  0:03 UTC (permalink / raw)
  To: linux-iio, jic23; +Cc: alexandru.ardelean, Denis Ciocca

This patch is trying to cleanup for good the buffers operation functions.
There is no need of using preenable, all can be done into
postenable. Let's also use logical sequence of operations as
already done in accel driver.
Finally also rename the goto label using operation to perform and not
where it fails.

Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
---
 drivers/iio/gyro/st_gyro_buffer.c | 45 +++++++++++++------------------
 1 file changed, 19 insertions(+), 26 deletions(-)

diff --git a/drivers/iio/gyro/st_gyro_buffer.c b/drivers/iio/gyro/st_gyro_buffer.c
index 21360681d4dd..be9f1fec2b5d 100644
--- a/drivers/iio/gyro/st_gyro_buffer.c
+++ b/drivers/iio/gyro/st_gyro_buffer.c
@@ -29,62 +29,55 @@ int st_gyro_trig_set_state(struct iio_trigger *trig, bool state)
 	return st_sensors_set_dataready_irq(indio_dev, state);
 }
 
-static int st_gyro_buffer_preenable(struct iio_dev *indio_dev)
-{
-	return st_sensors_set_enable(indio_dev, true);
-}
-
 static int st_gyro_buffer_postenable(struct iio_dev *indio_dev)
 {
-	int err;
 	struct st_sensor_data *gdata = iio_priv(indio_dev);
+	int err;
 
 	gdata->buffer_data = kmalloc(indio_dev->scan_bytes,
 				     GFP_DMA | GFP_KERNEL);
-	if (gdata->buffer_data == NULL) {
-		err = -ENOMEM;
-		goto allocate_memory_error;
-	}
+	if (!gdata->buffer_data)
+		return -ENOMEM;
 
-	err = st_sensors_set_axis_enable(indio_dev,
-					(u8)indio_dev->active_scan_mask[0]);
+	err = iio_triggered_buffer_postenable(indio_dev);
 	if (err < 0)
-		goto st_gyro_buffer_postenable_error;
+		goto st_gyro_free_buffer;
 
-	err = iio_triggered_buffer_postenable(indio_dev);
+	err = st_sensors_set_axis_enable(indio_dev,
+					 (u8)indio_dev->active_scan_mask[0]);
 	if (err < 0)
-		goto st_gyro_buffer_postenable_error;
+		goto st_gyro_buffer_predisable;
 
-	return err;
+	return st_sensors_set_enable(indio_dev, true);
 
-st_gyro_buffer_postenable_error:
+st_gyro_buffer_predisable:
+	iio_triggered_buffer_predisable(indio_dev);
+st_gyro_free_buffer:
 	kfree(gdata->buffer_data);
-allocate_memory_error:
 	return err;
 }
 
 static int st_gyro_buffer_predisable(struct iio_dev *indio_dev)
 {
-	int err;
+	int err, err2;
 	struct st_sensor_data *gdata = iio_priv(indio_dev);
 
-	err = iio_triggered_buffer_predisable(indio_dev);
+	err = st_sensors_set_enable(indio_dev, false);
 	if (err < 0)
-		goto st_gyro_buffer_predisable_error;
+		goto st_gyro_buffer_predisable;
 
 	err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
-	if (err < 0)
-		goto st_gyro_buffer_predisable_error;
 
-	err = st_sensors_set_enable(indio_dev, false);
+st_gyro_buffer_predisable:
+	err2 = iio_triggered_buffer_predisable(indio_dev);
+	if (!err)
+		err = err2;
 
-st_gyro_buffer_predisable_error:
 	kfree(gdata->buffer_data);
 	return err;
 }
 
 static const struct iio_buffer_setup_ops st_gyro_buffer_setup_ops = {
-	.preenable = &st_gyro_buffer_preenable,
 	.postenable = &st_gyro_buffer_postenable,
 	.predisable = &st_gyro_buffer_predisable,
 };
-- 
2.22.0


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

* [PATCH 3/4] iio:magn: preenable/postenable/predisable fixup for ST magn buffer
  2019-07-30  0:03 [PATCH 0/4] preenable/postenable/predisable fixup for ST drivers Denis Ciocca
  2019-07-30  0:03 ` [PATCH 1/4] iio:accel: preenable/postenable/predisable fixup for ST accel buffer Denis Ciocca
  2019-07-30  0:03 ` [PATCH 2/4] iio:gyro: preenable/postenable/predisable fixup for ST gyro buffer Denis Ciocca
@ 2019-07-30  0:03 ` Denis Ciocca
  2019-07-30  8:54   ` Ardelean, Alexandru
  2019-07-30  0:03 ` [PATCH 4/4] iio:pressure: preenable/postenable/predisable fixup for ST press buffer Denis Ciocca
  2019-07-30  9:03 ` [PATCH 0/4] preenable/postenable/predisable fixup for ST drivers Ardelean, Alexandru
  4 siblings, 1 reply; 13+ messages in thread
From: Denis Ciocca @ 2019-07-30  0:03 UTC (permalink / raw)
  To: linux-iio, jic23; +Cc: alexandru.ardelean, Denis Ciocca

This patch is trying to cleanup for good the buffers operation functions.
Let's rename the goto label using operation to perform and not
where it fails.

Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
---
 drivers/iio/magnetometer/st_magn_buffer.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/drivers/iio/magnetometer/st_magn_buffer.c b/drivers/iio/magnetometer/st_magn_buffer.c
index 9dba93539a99..8d06643a042d 100644
--- a/drivers/iio/magnetometer/st_magn_buffer.c
+++ b/drivers/iio/magnetometer/st_magn_buffer.c
@@ -31,40 +31,36 @@ int st_magn_trig_set_state(struct iio_trigger *trig, bool state)
 
 static int st_magn_buffer_postenable(struct iio_dev *indio_dev)
 {
-	int err;
 	struct st_sensor_data *mdata = iio_priv(indio_dev);
+	int err;
 
 	mdata->buffer_data = kmalloc(indio_dev->scan_bytes,
 				     GFP_DMA | GFP_KERNEL);
-	if (mdata->buffer_data == NULL) {
-		err = -ENOMEM;
-		goto allocate_memory_error;
-	}
+	if (!mdata->buffer_data)
+		return -ENOMEM;
 
 	err = iio_triggered_buffer_postenable(indio_dev);
 	if (err < 0)
-		goto st_magn_buffer_postenable_error;
+		goto st_magn_free_buffer;
 
 	return st_sensors_set_enable(indio_dev, true);
 
-st_magn_buffer_postenable_error:
+st_magn_free_buffer:
 	kfree(mdata->buffer_data);
-allocate_memory_error:
 	return err;
 }
 
 static int st_magn_buffer_predisable(struct iio_dev *indio_dev)
 {
-	int err;
 	struct st_sensor_data *mdata = iio_priv(indio_dev);
+	int err, err2;
 
 	err = st_sensors_set_enable(indio_dev, false);
-	if (err < 0)
-		goto st_magn_buffer_predisable_error;
 
-	err = iio_triggered_buffer_predisable(indio_dev);
+	err2 = iio_triggered_buffer_predisable(indio_dev);
+	if (!err)
+		err = err2;
 
-st_magn_buffer_predisable_error:
 	kfree(mdata->buffer_data);
 	return err;
 }
-- 
2.22.0


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

* [PATCH 4/4] iio:pressure: preenable/postenable/predisable fixup for ST press buffer
  2019-07-30  0:03 [PATCH 0/4] preenable/postenable/predisable fixup for ST drivers Denis Ciocca
                   ` (2 preceding siblings ...)
  2019-07-30  0:03 ` [PATCH 3/4] iio:magn: preenable/postenable/predisable fixup for ST magn buffer Denis Ciocca
@ 2019-07-30  0:03 ` Denis Ciocca
  2019-07-30  9:02   ` Ardelean, Alexandru
  2019-07-30  9:03 ` [PATCH 0/4] preenable/postenable/predisable fixup for ST drivers Ardelean, Alexandru
  4 siblings, 1 reply; 13+ messages in thread
From: Denis Ciocca @ 2019-07-30  0:03 UTC (permalink / raw)
  To: linux-iio, jic23; +Cc: alexandru.ardelean, Denis Ciocca

This patch is trying to cleanup for good the buffers operation functions.
There is no need of using preenable, all can be done into
postenable. Let's also use logical sequence of operations as
already done in accel driver.
Finally also rename the goto label using operation to perform and not
where it fails.

Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
---
 drivers/iio/pressure/st_pressure_buffer.c | 32 ++++++++---------------
 1 file changed, 11 insertions(+), 21 deletions(-)

diff --git a/drivers/iio/pressure/st_pressure_buffer.c b/drivers/iio/pressure/st_pressure_buffer.c
index f21b630abaa0..54823cfcfab5 100644
--- a/drivers/iio/pressure/st_pressure_buffer.c
+++ b/drivers/iio/pressure/st_pressure_buffer.c
@@ -29,53 +29,43 @@ int st_press_trig_set_state(struct iio_trigger *trig, bool state)
 	return st_sensors_set_dataready_irq(indio_dev, state);
 }
 
-static int st_press_buffer_preenable(struct iio_dev *indio_dev)
-{
-	return st_sensors_set_enable(indio_dev, true);
-}
-
 static int st_press_buffer_postenable(struct iio_dev *indio_dev)
 {
-	int err;
 	struct st_sensor_data *press_data = iio_priv(indio_dev);
+	int err;
 
 	press_data->buffer_data = kmalloc(indio_dev->scan_bytes,
 					  GFP_DMA | GFP_KERNEL);
-	if (press_data->buffer_data == NULL) {
-		err = -ENOMEM;
-		goto allocate_memory_error;
-	}
+	if (!press_data->buffer_data)
+		return -ENOMEM;
 
 	err = iio_triggered_buffer_postenable(indio_dev);
 	if (err < 0)
-		goto st_press_buffer_postenable_error;
+		goto st_press_free_buffer;
 
-	return err;
+	return st_sensors_set_enable(indio_dev, true);
 
-st_press_buffer_postenable_error:
+st_press_free_buffer:
 	kfree(press_data->buffer_data);
-allocate_memory_error:
 	return err;
 }
 
 static int st_press_buffer_predisable(struct iio_dev *indio_dev)
 {
-	int err;
 	struct st_sensor_data *press_data = iio_priv(indio_dev);
-
-	err = iio_triggered_buffer_predisable(indio_dev);
-	if (err < 0)
-		goto st_press_buffer_predisable_error;
+	int err, err2;
 
 	err = st_sensors_set_enable(indio_dev, false);
 
-st_press_buffer_predisable_error:
+	err2 = iio_triggered_buffer_predisable(indio_dev);
+	if (!err)
+		err = err2;
+
 	kfree(press_data->buffer_data);
 	return err;
 }
 
 static const struct iio_buffer_setup_ops st_press_buffer_setup_ops = {
-	.preenable = &st_press_buffer_preenable,
 	.postenable = &st_press_buffer_postenable,
 	.predisable = &st_press_buffer_predisable,
 };
-- 
2.22.0


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

* Re: [PATCH 1/4] iio:accel: preenable/postenable/predisable fixup for ST accel buffer
  2019-07-30  0:03 ` [PATCH 1/4] iio:accel: preenable/postenable/predisable fixup for ST accel buffer Denis Ciocca
@ 2019-07-30  8:52   ` Ardelean, Alexandru
  0 siblings, 0 replies; 13+ messages in thread
From: Ardelean, Alexandru @ 2019-07-30  8:52 UTC (permalink / raw)
  To: jic23, denis.ciocca, linux-iio

On Mon, 2019-07-29 at 17:03 -0700, Denis Ciocca wrote:
> [External]
> 
> This patch is trying to cleanup for good the buffers operation functions.
> There is no need of using preenable, all can be done into
> postenable.
> Let's also rename the goto label using operation to perform and not
> where it fails.
> 

Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com>

> Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
> ---
>  drivers/iio/accel/st_accel_buffer.c | 37 ++++++++++-------------------
>  1 file changed, 13 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/iio/accel/st_accel_buffer.c b/drivers/iio/accel/st_accel_buffer.c
> index 05f9aea431e2..81f89da125aa 100644
> --- a/drivers/iio/accel/st_accel_buffer.c
> +++ b/drivers/iio/accel/st_accel_buffer.c
> @@ -29,56 +29,46 @@ int st_accel_trig_set_state(struct iio_trigger *trig, bool state)
>  	return st_sensors_set_dataready_irq(indio_dev, state);
>  }
>  
> -static int st_accel_buffer_preenable(struct iio_dev *indio_dev)
> -{
> -	return st_sensors_set_enable(indio_dev, true);
> -}
> -
>  static int st_accel_buffer_postenable(struct iio_dev *indio_dev)
>  {
> -	int err;
>  	struct st_sensor_data *adata = iio_priv(indio_dev);
> +	int err;
>  
>  	adata->buffer_data = kmalloc(indio_dev->scan_bytes,
>  				     GFP_DMA | GFP_KERNEL);
> -	if (adata->buffer_data == NULL) {
> -		err = -ENOMEM;
> -		goto allocate_memory_error;
> -	}
> +	if (!adata->buffer_data)
> +		return -ENOMEM;
>  
>  	err = iio_triggered_buffer_postenable(indio_dev);
>  	if (err < 0)
> -		goto st_accel_buffer_postenable_error;
> +		goto st_accel_free_buffer;
>  
>  	err = st_sensors_set_axis_enable(indio_dev,
>  					(u8)indio_dev->active_scan_mask[0]);
>  	if (err < 0)
> -		goto st_sensors_set_axis_enable_error;
> +		goto st_accel_buffer_predisable;
>  
> -	return err;
> +	return st_sensors_set_enable(indio_dev, true);
>  
> -st_sensors_set_axis_enable_error:
> +st_accel_buffer_predisable:
>  	iio_triggered_buffer_predisable(indio_dev);
> -st_accel_buffer_postenable_error:
> +st_accel_free_buffer:
>  	kfree(adata->buffer_data);
> -allocate_memory_error:
>  	return err;
>  }
>  
>  static int st_accel_buffer_predisable(struct iio_dev *indio_dev)
>  {
> -	int err, err2;
>  	struct st_sensor_data *adata = iio_priv(indio_dev);
> -
> -	err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
> -	if (err < 0)
> -		goto st_accel_buffer_predisable_error;
> +	int err, err2;
>  
>  	err = st_sensors_set_enable(indio_dev, false);
>  	if (err < 0)
> -		goto st_accel_buffer_predisable_error;
> +		goto st_accel_buffer_predisable;
> +
> +	err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
>  
> -st_accel_buffer_predisable_error:
> +st_accel_buffer_predisable:
>  	err2 = iio_triggered_buffer_predisable(indio_dev);
>  	if (!err)
>  		err = err2;
> @@ -88,7 +78,6 @@ static int st_accel_buffer_predisable(struct iio_dev *indio_dev)
>  }
>  
>  static const struct iio_buffer_setup_ops st_accel_buffer_setup_ops = {
> -	.preenable = &st_accel_buffer_preenable,
>  	.postenable = &st_accel_buffer_postenable,
>  	.predisable = &st_accel_buffer_predisable,
>  };

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

* Re: [PATCH 2/4] iio:gyro: preenable/postenable/predisable fixup for ST gyro buffer
  2019-07-30  0:03 ` [PATCH 2/4] iio:gyro: preenable/postenable/predisable fixup for ST gyro buffer Denis Ciocca
@ 2019-07-30  8:52   ` Ardelean, Alexandru
  0 siblings, 0 replies; 13+ messages in thread
From: Ardelean, Alexandru @ 2019-07-30  8:52 UTC (permalink / raw)
  To: jic23, denis.ciocca, linux-iio

On Mon, 2019-07-29 at 17:03 -0700, Denis Ciocca wrote:
> [External]
> 
> This patch is trying to cleanup for good the buffers operation functions.
> There is no need of using preenable, all can be done into
> postenable. Let's also use logical sequence of operations as
> already done in accel driver.
> Finally also rename the goto label using operation to perform and not
> where it fails.
> 

Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com>

> Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
> ---
>  drivers/iio/gyro/st_gyro_buffer.c | 45 +++++++++++++------------------
>  1 file changed, 19 insertions(+), 26 deletions(-)
> 
> diff --git a/drivers/iio/gyro/st_gyro_buffer.c b/drivers/iio/gyro/st_gyro_buffer.c
> index 21360681d4dd..be9f1fec2b5d 100644
> --- a/drivers/iio/gyro/st_gyro_buffer.c
> +++ b/drivers/iio/gyro/st_gyro_buffer.c
> @@ -29,62 +29,55 @@ int st_gyro_trig_set_state(struct iio_trigger *trig, bool state)
>  	return st_sensors_set_dataready_irq(indio_dev, state);
>  }
>  
> -static int st_gyro_buffer_preenable(struct iio_dev *indio_dev)
> -{
> -	return st_sensors_set_enable(indio_dev, true);
> -}
> -
>  static int st_gyro_buffer_postenable(struct iio_dev *indio_dev)
>  {
> -	int err;
>  	struct st_sensor_data *gdata = iio_priv(indio_dev);
> +	int err;
>  
>  	gdata->buffer_data = kmalloc(indio_dev->scan_bytes,
>  				     GFP_DMA | GFP_KERNEL);
> -	if (gdata->buffer_data == NULL) {
> -		err = -ENOMEM;
> -		goto allocate_memory_error;
> -	}
> +	if (!gdata->buffer_data)
> +		return -ENOMEM;
>  
> -	err = st_sensors_set_axis_enable(indio_dev,
> -					(u8)indio_dev->active_scan_mask[0]);
> +	err = iio_triggered_buffer_postenable(indio_dev);
>  	if (err < 0)
> -		goto st_gyro_buffer_postenable_error;
> +		goto st_gyro_free_buffer;
>  
> -	err = iio_triggered_buffer_postenable(indio_dev);
> +	err = st_sensors_set_axis_enable(indio_dev,
> +					 (u8)indio_dev->active_scan_mask[0]);
>  	if (err < 0)
> -		goto st_gyro_buffer_postenable_error;
> +		goto st_gyro_buffer_predisable;
>  
> -	return err;
> +	return st_sensors_set_enable(indio_dev, true);
>  
> -st_gyro_buffer_postenable_error:
> +st_gyro_buffer_predisable:
> +	iio_triggered_buffer_predisable(indio_dev);
> +st_gyro_free_buffer:
>  	kfree(gdata->buffer_data);
> -allocate_memory_error:
>  	return err;
>  }
>  
>  static int st_gyro_buffer_predisable(struct iio_dev *indio_dev)
>  {
> -	int err;
> +	int err, err2;
>  	struct st_sensor_data *gdata = iio_priv(indio_dev);
>  
> -	err = iio_triggered_buffer_predisable(indio_dev);
> +	err = st_sensors_set_enable(indio_dev, false);
>  	if (err < 0)
> -		goto st_gyro_buffer_predisable_error;
> +		goto st_gyro_buffer_predisable;
>  
>  	err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
> -	if (err < 0)
> -		goto st_gyro_buffer_predisable_error;
>  
> -	err = st_sensors_set_enable(indio_dev, false);
> +st_gyro_buffer_predisable:
> +	err2 = iio_triggered_buffer_predisable(indio_dev);
> +	if (!err)
> +		err = err2;
>  
> -st_gyro_buffer_predisable_error:
>  	kfree(gdata->buffer_data);
>  	return err;
>  }
>  
>  static const struct iio_buffer_setup_ops st_gyro_buffer_setup_ops = {
> -	.preenable = &st_gyro_buffer_preenable,
>  	.postenable = &st_gyro_buffer_postenable,
>  	.predisable = &st_gyro_buffer_predisable,
>  };

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

* Re: [PATCH 3/4] iio:magn: preenable/postenable/predisable fixup for ST magn buffer
  2019-07-30  0:03 ` [PATCH 3/4] iio:magn: preenable/postenable/predisable fixup for ST magn buffer Denis Ciocca
@ 2019-07-30  8:54   ` Ardelean, Alexandru
  0 siblings, 0 replies; 13+ messages in thread
From: Ardelean, Alexandru @ 2019-07-30  8:54 UTC (permalink / raw)
  To: jic23, denis.ciocca, linux-iio

On Mon, 2019-07-29 at 17:03 -0700, Denis Ciocca wrote:
> [External]
> 
> This patch is trying to cleanup for good the buffers operation functions.
> Let's rename the goto label using operation to perform and not
> where it fails.

1 minor comment inline

Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com>

> 
> Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
> ---
>  drivers/iio/magnetometer/st_magn_buffer.c | 22 +++++++++-------------
>  1 file changed, 9 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/iio/magnetometer/st_magn_buffer.c b/drivers/iio/magnetometer/st_magn_buffer.c
> index 9dba93539a99..8d06643a042d 100644
> --- a/drivers/iio/magnetometer/st_magn_buffer.c
> +++ b/drivers/iio/magnetometer/st_magn_buffer.c
> @@ -31,40 +31,36 @@ int st_magn_trig_set_state(struct iio_trigger *trig, bool state)
>  
>  static int st_magn_buffer_postenable(struct iio_dev *indio_dev)
>  {
> -	int err;
>  	struct st_sensor_data *mdata = iio_priv(indio_dev);
> +	int err;

This looks more like style-change; but not a problem.

>  
>  	mdata->buffer_data = kmalloc(indio_dev->scan_bytes,
>  				     GFP_DMA | GFP_KERNEL);
> -	if (mdata->buffer_data == NULL) {
> -		err = -ENOMEM;
> -		goto allocate_memory_error;
> -	}
> +	if (!mdata->buffer_data)
> +		return -ENOMEM;
>  
>  	err = iio_triggered_buffer_postenable(indio_dev);
>  	if (err < 0)
> -		goto st_magn_buffer_postenable_error;
> +		goto st_magn_free_buffer;
>  
>  	return st_sensors_set_enable(indio_dev, true);
>  
> -st_magn_buffer_postenable_error:
> +st_magn_free_buffer:
>  	kfree(mdata->buffer_data);
> -allocate_memory_error:
>  	return err;
>  }
>  
>  static int st_magn_buffer_predisable(struct iio_dev *indio_dev)
>  {
> -	int err;
>  	struct st_sensor_data *mdata = iio_priv(indio_dev);
> +	int err, err2;
>  
>  	err = st_sensors_set_enable(indio_dev, false);
> -	if (err < 0)
> -		goto st_magn_buffer_predisable_error;
>  
> -	err = iio_triggered_buffer_predisable(indio_dev);
> +	err2 = iio_triggered_buffer_predisable(indio_dev);
> +	if (!err)
> +		err = err2;
>  
> -st_magn_buffer_predisable_error:
>  	kfree(mdata->buffer_data);
>  	return err;
>  }

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

* Re: [PATCH 4/4] iio:pressure: preenable/postenable/predisable fixup for ST press buffer
  2019-07-30  0:03 ` [PATCH 4/4] iio:pressure: preenable/postenable/predisable fixup for ST press buffer Denis Ciocca
@ 2019-07-30  9:02   ` Ardelean, Alexandru
  2019-07-30 16:08     ` Denis CIOCCA
  0 siblings, 1 reply; 13+ messages in thread
From: Ardelean, Alexandru @ 2019-07-30  9:02 UTC (permalink / raw)
  To: jic23, denis.ciocca, linux-iio

On Mon, 2019-07-29 at 17:03 -0700, Denis Ciocca wrote:
> [External]
> 
> This patch is trying to cleanup for good the buffers operation functions.
> There is no need of using preenable, all can be done into
> postenable. Let's also use logical sequence of operations as
> already done in accel driver.
> Finally also rename the goto label using operation to perform and not
> where it fails.
> 

Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com>


Unrelated to this patch, I was thinking that it would be a neat idea to move the `buffer_data` allocation in
`drivers/iio/common/st_sensors/st_sensors_buffer.c`

This would remove some duplication of this alloc + free in drivers.

Maybe in st_sensors_trigger_handler() something like:

if (!sdata->buffer_data) {
    sdata->buffer_data = devm_kmalloc()
    if (!sdata->buffer_data) {
        dev_err(indio_dev->dev, "Failed to allocate buffer data\n");
        goto st_sensors_get_buffer_element_error;
    }
}

Using devm_kmalloc() or a similar devm_ variant would be neat, since it gets free'd when the device gets removed.

Thanks
Alex

> Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
> ---
>  drivers/iio/pressure/st_pressure_buffer.c | 32 ++++++++---------------
>  1 file changed, 11 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/iio/pressure/st_pressure_buffer.c b/drivers/iio/pressure/st_pressure_buffer.c
> index f21b630abaa0..54823cfcfab5 100644
> --- a/drivers/iio/pressure/st_pressure_buffer.c
> +++ b/drivers/iio/pressure/st_pressure_buffer.c
> @@ -29,53 +29,43 @@ int st_press_trig_set_state(struct iio_trigger *trig, bool state)
>  	return st_sensors_set_dataready_irq(indio_dev, state);
>  }
>  
> -static int st_press_buffer_preenable(struct iio_dev *indio_dev)
> -{
> -	return st_sensors_set_enable(indio_dev, true);
> -}
> -
>  static int st_press_buffer_postenable(struct iio_dev *indio_dev)
>  {
> -	int err;
>  	struct st_sensor_data *press_data = iio_priv(indio_dev);
> +	int err;
>  
>  	press_data->buffer_data = kmalloc(indio_dev->scan_bytes,
>  					  GFP_DMA | GFP_KERNEL);
> -	if (press_data->buffer_data == NULL) {
> -		err = -ENOMEM;
> -		goto allocate_memory_error;
> -	}
> +	if (!press_data->buffer_data)
> +		return -ENOMEM;
>  
>  	err = iio_triggered_buffer_postenable(indio_dev);
>  	if (err < 0)
> -		goto st_press_buffer_postenable_error;
> +		goto st_press_free_buffer;
>  
> -	return err;
> +	return st_sensors_set_enable(indio_dev, true);
>  
> -st_press_buffer_postenable_error:
> +st_press_free_buffer:
>  	kfree(press_data->buffer_data);
> -allocate_memory_error:
>  	return err;
>  }
>  
>  static int st_press_buffer_predisable(struct iio_dev *indio_dev)
>  {
> -	int err;
>  	struct st_sensor_data *press_data = iio_priv(indio_dev);
> -
> -	err = iio_triggered_buffer_predisable(indio_dev);
> -	if (err < 0)
> -		goto st_press_buffer_predisable_error;
> +	int err, err2;
>  
>  	err = st_sensors_set_enable(indio_dev, false);
>  
> -st_press_buffer_predisable_error:
> +	err2 = iio_triggered_buffer_predisable(indio_dev);
> +	if (!err)
> +		err = err2;
> +
>  	kfree(press_data->buffer_data);
>  	return err;
>  }
>  
>  static const struct iio_buffer_setup_ops st_press_buffer_setup_ops = {
> -	.preenable = &st_press_buffer_preenable,
>  	.postenable = &st_press_buffer_postenable,
>  	.predisable = &st_press_buffer_predisable,
>  };

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

* Re: [PATCH 0/4] preenable/postenable/predisable fixup for ST drivers
  2019-07-30  0:03 [PATCH 0/4] preenable/postenable/predisable fixup for ST drivers Denis Ciocca
                   ` (3 preceding siblings ...)
  2019-07-30  0:03 ` [PATCH 4/4] iio:pressure: preenable/postenable/predisable fixup for ST press buffer Denis Ciocca
@ 2019-07-30  9:03 ` Ardelean, Alexandru
  4 siblings, 0 replies; 13+ messages in thread
From: Ardelean, Alexandru @ 2019-07-30  9:03 UTC (permalink / raw)
  To: jic23, denis.ciocca, linux-iio

On Mon, 2019-07-29 at 17:03 -0700, Denis Ciocca wrote:
> [External]
> 
> This series is meant to fix for good the functions listed in subject.
> In a way, is continuing the task started by Alexandru for accel.
> 

Many thanks for this series.
It's now fewer drivers I need to not worry about.

Alex

> 
> Denis Ciocca (4):
>   iio:accel: preenable/postenable/predisable fixup for ST accel buffer
>   iio:gyro: preenable/postenable/predisable fixup for ST gyro buffer
>   iio:magn: preenable/postenable/predisable fixup for ST magn buffer
>   iio:pressure: preenable/postenable/predisable fixup for ST press
>     buffer
> 
>  drivers/iio/accel/st_accel_buffer.c       | 37 +++++++------------
>  drivers/iio/gyro/st_gyro_buffer.c         | 45 ++++++++++-------------
>  drivers/iio/magnetometer/st_magn_buffer.c | 22 +++++------
>  drivers/iio/pressure/st_pressure_buffer.c | 32 ++++++----------
>  4 files changed, 52 insertions(+), 84 deletions(-)
> 

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

* RE: [PATCH 4/4] iio:pressure: preenable/postenable/predisable fixup for ST press buffer
  2019-07-30  9:02   ` Ardelean, Alexandru
@ 2019-07-30 16:08     ` Denis CIOCCA
  2019-07-31  6:58       ` Ardelean, Alexandru
  0 siblings, 1 reply; 13+ messages in thread
From: Denis CIOCCA @ 2019-07-30 16:08 UTC (permalink / raw)
  To: Ardelean, Alexandru, jic23, linux-iio

Hi Alexandru,

> -----Original Message-----
> From: Ardelean, Alexandru <alexandru.Ardelean@analog.com>
> Sent: Tuesday, July 30, 2019 2:02 AM
> To: jic23@kernel.org; Denis CIOCCA <denis.ciocca@st.com>; linux-
> iio@vger.kernel.org
> Subject: Re: [PATCH 4/4] iio:pressure: preenable/postenable/predisable
> fixup for ST press buffer
> 
> On Mon, 2019-07-29 at 17:03 -0700, Denis Ciocca wrote:
> > [External]
> >
> > This patch is trying to cleanup for good the buffers operation functions.
> > There is no need of using preenable, all can be done into postenable.
> > Let's also use logical sequence of operations as already done in accel
> > driver.
> > Finally also rename the goto label using operation to perform and not
> > where it fails.
> >
> 
> Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> 
> 
> Unrelated to this patch, I was thinking that it would be a neat idea to move
> the `buffer_data` allocation in
> `drivers/iio/common/st_sensors/st_sensors_buffer.c`
> 
> This would remove some duplication of this alloc + free in drivers.
> 
> Maybe in st_sensors_trigger_handler() something like:
> 
> if (!sdata->buffer_data) {
>     sdata->buffer_data = devm_kmalloc()
>     if (!sdata->buffer_data) {
>         dev_err(indio_dev->dev, "Failed to allocate buffer data\n");
>         goto st_sensors_get_buffer_element_error;
>     }
> }
> 
> Using devm_kmalloc() or a similar devm_ variant would be neat, since it gets
> free'd when the device gets removed.

Not sure about the solution proposed.
Memory allocation is actually related to how many channels are enabled,
one possibility could be to allocate the maximum but not sure it's worth...
Moreover the memory allocation there could let driver miss the first sample I guess.


> 
> Thanks
> Alex
> 
> > Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
> > ---
> >  drivers/iio/pressure/st_pressure_buffer.c | 32
> > ++++++++---------------
> >  1 file changed, 11 insertions(+), 21 deletions(-)
> >
> > diff --git a/drivers/iio/pressure/st_pressure_buffer.c
> > b/drivers/iio/pressure/st_pressure_buffer.c
> > index f21b630abaa0..54823cfcfab5 100644
> > --- a/drivers/iio/pressure/st_pressure_buffer.c
> > +++ b/drivers/iio/pressure/st_pressure_buffer.c
> > @@ -29,53 +29,43 @@ int st_press_trig_set_state(struct iio_trigger *trig,
> bool state)
> >  	return st_sensors_set_dataready_irq(indio_dev, state);  }
> >
> > -static int st_press_buffer_preenable(struct iio_dev *indio_dev) -{
> > -	return st_sensors_set_enable(indio_dev, true);
> > -}
> > -
> >  static int st_press_buffer_postenable(struct iio_dev *indio_dev)  {
> > -	int err;
> >  	struct st_sensor_data *press_data = iio_priv(indio_dev);
> > +	int err;
> >
> >  	press_data->buffer_data = kmalloc(indio_dev->scan_bytes,
> >  					  GFP_DMA | GFP_KERNEL);
> > -	if (press_data->buffer_data == NULL) {
> > -		err = -ENOMEM;
> > -		goto allocate_memory_error;
> > -	}
> > +	if (!press_data->buffer_data)
> > +		return -ENOMEM;
> >
> >  	err = iio_triggered_buffer_postenable(indio_dev);
> >  	if (err < 0)
> > -		goto st_press_buffer_postenable_error;
> > +		goto st_press_free_buffer;
> >
> > -	return err;
> > +	return st_sensors_set_enable(indio_dev, true);
> >
> > -st_press_buffer_postenable_error:
> > +st_press_free_buffer:
> >  	kfree(press_data->buffer_data);
> > -allocate_memory_error:
> >  	return err;
> >  }
> >
> >  static int st_press_buffer_predisable(struct iio_dev *indio_dev)
> >  {
> > -	int err;
> >  	struct st_sensor_data *press_data = iio_priv(indio_dev);
> > -
> > -	err = iio_triggered_buffer_predisable(indio_dev);
> > -	if (err < 0)
> > -		goto st_press_buffer_predisable_error;
> > +	int err, err2;
> >
> >  	err = st_sensors_set_enable(indio_dev, false);
> >
> > -st_press_buffer_predisable_error:
> > +	err2 = iio_triggered_buffer_predisable(indio_dev);
> > +	if (!err)
> > +		err = err2;
> > +
> >  	kfree(press_data->buffer_data);
> >  	return err;
> >  }
> >
> >  static const struct iio_buffer_setup_ops st_press_buffer_setup_ops = {
> > -	.preenable = &st_press_buffer_preenable,
> >  	.postenable = &st_press_buffer_postenable,
> >  	.predisable = &st_press_buffer_predisable,
> >  };

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

* Re: [PATCH 4/4] iio:pressure: preenable/postenable/predisable fixup for ST press buffer
  2019-07-30 16:08     ` Denis CIOCCA
@ 2019-07-31  6:58       ` Ardelean, Alexandru
  2019-07-31 21:48         ` Denis CIOCCA
  0 siblings, 1 reply; 13+ messages in thread
From: Ardelean, Alexandru @ 2019-07-31  6:58 UTC (permalink / raw)
  To: jic23, denis.ciocca, linux-iio

On Tue, 2019-07-30 at 16:08 +0000, Denis CIOCCA wrote:
> [External]
> 
> Hi Alexandru,
> 
> > -----Original Message-----
> > From: Ardelean, Alexandru <alexandru.Ardelean@analog.com>
> > Sent: Tuesday, July 30, 2019 2:02 AM
> > To: jic23@kernel.org; Denis CIOCCA <denis.ciocca@st.com>; linux-
> > iio@vger.kernel.org
> > Subject: Re: [PATCH 4/4] iio:pressure: preenable/postenable/predisable
> > fixup for ST press buffer
> > 
> > On Mon, 2019-07-29 at 17:03 -0700, Denis Ciocca wrote:
> > > [External]
> > > 
> > > This patch is trying to cleanup for good the buffers operation functions.
> > > There is no need of using preenable, all can be done into postenable.
> > > Let's also use logical sequence of operations as already done in accel
> > > driver.
> > > Finally also rename the goto label using operation to perform and not
> > > where it fails.
> > > 
> > 
> > Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> > 
> > 
> > Unrelated to this patch, I was thinking that it would be a neat idea to move
> > the `buffer_data` allocation in
> > `drivers/iio/common/st_sensors/st_sensors_buffer.c`
> > 
> > This would remove some duplication of this alloc + free in drivers.
> > 
> > Maybe in st_sensors_trigger_handler() something like:
> > 
> > if (!sdata->buffer_data) {
> >     sdata->buffer_data = devm_kmalloc()
> >     if (!sdata->buffer_data) {
> >         dev_err(indio_dev->dev, "Failed to allocate buffer data\n");
> >         goto st_sensors_get_buffer_element_error;
> >     }
> > }
> > 
> > Using devm_kmalloc() or a similar devm_ variant would be neat, since it gets
> > free'd when the device gets removed.
> 
> Not sure about the solution proposed.
> Memory allocation is actually related to how many channels are enabled,
> one possibility could be to allocate the maximum but not sure it's worth...
> Moreover the memory allocation there could let driver miss the first sample I guess.
> 

I see.
Would [then] moving the allocation in preenable work? and the free in postdisable?

Thing is: when iio_triggered_buffer_postenable() and iio_triggered_buffer_predisable() get removed (and logic moved into
core), then the order changes, and the attach pollfunc gets called before the allocation.


The final destination for these changes is this commit:
https://github.com/analogdevicesinc/linux/commit/eee97d12665fef8c#diff-0a87744ce945d2c1c89ea19f21fb35bbR722
[this an older form]
In this commit, the attach/detach of the poll_func is moved into core, since that is all that the 2 functions do
(iio_triggered_buffer_postenable() and iio_triggered_buffer_predisable())

When the move happens [for the ST drivers in particular] the poll_func is attached, and then the allocation is done, and
the free is done first, and then the poll_func is detached.


> 
> > Thanks
> > Alex
> > 
> > > Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
> > > ---
> > >  drivers/iio/pressure/st_pressure_buffer.c | 32
> > > ++++++++---------------
> > >  1 file changed, 11 insertions(+), 21 deletions(-)
> > > 
> > > diff --git a/drivers/iio/pressure/st_pressure_buffer.c
> > > b/drivers/iio/pressure/st_pressure_buffer.c
> > > index f21b630abaa0..54823cfcfab5 100644
> > > --- a/drivers/iio/pressure/st_pressure_buffer.c
> > > +++ b/drivers/iio/pressure/st_pressure_buffer.c
> > > @@ -29,53 +29,43 @@ int st_press_trig_set_state(struct iio_trigger *trig,
> > bool state)
> > >  	return st_sensors_set_dataready_irq(indio_dev, state);  }
> > > 
> > > -static int st_press_buffer_preenable(struct iio_dev *indio_dev) -{
> > > -	return st_sensors_set_enable(indio_dev, true);
> > > -}
> > > -
> > >  static int st_press_buffer_postenable(struct iio_dev *indio_dev)  {
> > > -	int err;
> > >  	struct st_sensor_data *press_data = iio_priv(indio_dev);
> > > +	int err;
> > > 
> > >  	press_data->buffer_data = kmalloc(indio_dev->scan_bytes,
> > >  					  GFP_DMA | GFP_KERNEL);
> > > -	if (press_data->buffer_data == NULL) {
> > > -		err = -ENOMEM;
> > > -		goto allocate_memory_error;
> > > -	}
> > > +	if (!press_data->buffer_data)
> > > +		return -ENOMEM;
> > > 
> > >  	err = iio_triggered_buffer_postenable(indio_dev);
> > >  	if (err < 0)
> > > -		goto st_press_buffer_postenable_error;
> > > +		goto st_press_free_buffer;
> > > 
> > > -	return err;
> > > +	return st_sensors_set_enable(indio_dev, true);
> > > 
> > > -st_press_buffer_postenable_error:
> > > +st_press_free_buffer:
> > >  	kfree(press_data->buffer_data);
> > > -allocate_memory_error:
> > >  	return err;
> > >  }
> > > 
> > >  static int st_press_buffer_predisable(struct iio_dev *indio_dev)
> > >  {
> > > -	int err;
> > >  	struct st_sensor_data *press_data = iio_priv(indio_dev);
> > > -
> > > -	err = iio_triggered_buffer_predisable(indio_dev);
> > > -	if (err < 0)
> > > -		goto st_press_buffer_predisable_error;
> > > +	int err, err2;
> > > 
> > >  	err = st_sensors_set_enable(indio_dev, false);
> > > 
> > > -st_press_buffer_predisable_error:
> > > +	err2 = iio_triggered_buffer_predisable(indio_dev);
> > > +	if (!err)
> > > +		err = err2;
> > > +
> > >  	kfree(press_data->buffer_data);
> > >  	return err;
> > >  }
> > > 
> > >  static const struct iio_buffer_setup_ops st_press_buffer_setup_ops = {
> > > -	.preenable = &st_press_buffer_preenable,
> > >  	.postenable = &st_press_buffer_postenable,
> > >  	.predisable = &st_press_buffer_predisable,
> > >  };

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

* RE: [PATCH 4/4] iio:pressure: preenable/postenable/predisable fixup for ST press buffer
  2019-07-31  6:58       ` Ardelean, Alexandru
@ 2019-07-31 21:48         ` Denis CIOCCA
  0 siblings, 0 replies; 13+ messages in thread
From: Denis CIOCCA @ 2019-07-31 21:48 UTC (permalink / raw)
  To: Ardelean, Alexandru, jic23, linux-iio

> -----Original Message-----
> From: Ardelean, Alexandru <alexandru.Ardelean@analog.com>
> Sent: Tuesday, July 30, 2019 11:59 PM
> To: jic23@kernel.org; Denis CIOCCA <denis.ciocca@st.com>; linux-
> iio@vger.kernel.org
> Subject: Re: [PATCH 4/4] iio:pressure: preenable/postenable/predisable
> fixup for ST press buffer
> 
> On Tue, 2019-07-30 at 16:08 +0000, Denis CIOCCA wrote:
> > [External]
> >
> > Hi Alexandru,
> >
> > > -----Original Message-----
> > > From: Ardelean, Alexandru <alexandru.Ardelean@analog.com>
> > > Sent: Tuesday, July 30, 2019 2:02 AM
> > > To: jic23@kernel.org; Denis CIOCCA <denis.ciocca@st.com>; linux-
> > > iio@vger.kernel.org
> > > Subject: Re: [PATCH 4/4] iio:pressure:
> > > preenable/postenable/predisable fixup for ST press buffer
> > >
> > > On Mon, 2019-07-29 at 17:03 -0700, Denis Ciocca wrote:
> > > > [External]
> > > >
> > > > This patch is trying to cleanup for good the buffers operation functions.
> > > > There is no need of using preenable, all can be done into postenable.
> > > > Let's also use logical sequence of operations as already done in
> > > > accel driver.
> > > > Finally also rename the goto label using operation to perform and
> > > > not where it fails.
> > > >
> > >
> > > Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> > >
> > >
> > > Unrelated to this patch, I was thinking that it would be a neat idea
> > > to move the `buffer_data` allocation in
> > > `drivers/iio/common/st_sensors/st_sensors_buffer.c`
> > >
> > > This would remove some duplication of this alloc + free in drivers.
> > >
> > > Maybe in st_sensors_trigger_handler() something like:
> > >
> > > if (!sdata->buffer_data) {
> > >     sdata->buffer_data = devm_kmalloc()
> > >     if (!sdata->buffer_data) {
> > >         dev_err(indio_dev->dev, "Failed to allocate buffer data\n");
> > >         goto st_sensors_get_buffer_element_error;
> > >     }
> > > }
> > >
> > > Using devm_kmalloc() or a similar devm_ variant would be neat, since
> > > it gets free'd when the device gets removed.
> >
> > Not sure about the solution proposed.
> > Memory allocation is actually related to how many channels are
> > enabled, one possibility could be to allocate the maximum but not sure it's
> worth...
> > Moreover the memory allocation there could let driver miss the first
> sample I guess.
> >
> 
> I see.
> Would [then] moving the allocation in preenable work? and the free in
> postdisable?

Yeah, I think will work just fine. I've tested a preliminary version, I'll share soon.



> 
> Thing is: when iio_triggered_buffer_postenable() and
> iio_triggered_buffer_predisable() get removed (and logic moved into core),
> then the order changes, and the attach pollfunc gets called before the
> allocation.
> 
> 
> The final destination for these changes is this commit:
> https://github.com/analogdevicesinc/linux/commit/eee97d12665fef8c#diff-
> 0a87744ce945d2c1c89ea19f21fb35bbR722
> [this an older form]
> In this commit, the attach/detach of the poll_func is moved into core, since
> that is all that the 2 functions do
> (iio_triggered_buffer_postenable() and iio_triggered_buffer_predisable())
> 
> When the move happens [for the ST drivers in particular] the poll_func is
> attached, and then the allocation is done, and the free is done first, and then
> the poll_func is detached.
> 
> 
> >
> > > Thanks
> > > Alex
> > >
> > > > Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
> > > > ---
> > > >  drivers/iio/pressure/st_pressure_buffer.c | 32
> > > > ++++++++---------------
> > > >  1 file changed, 11 insertions(+), 21 deletions(-)
> > > >
> > > > diff --git a/drivers/iio/pressure/st_pressure_buffer.c
> > > > b/drivers/iio/pressure/st_pressure_buffer.c
> > > > index f21b630abaa0..54823cfcfab5 100644
> > > > --- a/drivers/iio/pressure/st_pressure_buffer.c
> > > > +++ b/drivers/iio/pressure/st_pressure_buffer.c
> > > > @@ -29,53 +29,43 @@ int st_press_trig_set_state(struct iio_trigger
> > > > *trig,
> > > bool state)
> > > >  	return st_sensors_set_dataready_irq(indio_dev, state);  }
> > > >
> > > > -static int st_press_buffer_preenable(struct iio_dev *indio_dev) -{
> > > > -	return st_sensors_set_enable(indio_dev, true);
> > > > -}
> > > > -
> > > >  static int st_press_buffer_postenable(struct iio_dev *indio_dev)  {
> > > > -	int err;
> > > >  	struct st_sensor_data *press_data = iio_priv(indio_dev);
> > > > +	int err;
> > > >
> > > >  	press_data->buffer_data = kmalloc(indio_dev->scan_bytes,
> > > >  					  GFP_DMA | GFP_KERNEL);
> > > > -	if (press_data->buffer_data == NULL) {
> > > > -		err = -ENOMEM;
> > > > -		goto allocate_memory_error;
> > > > -	}
> > > > +	if (!press_data->buffer_data)
> > > > +		return -ENOMEM;
> > > >
> > > >  	err = iio_triggered_buffer_postenable(indio_dev);
> > > >  	if (err < 0)
> > > > -		goto st_press_buffer_postenable_error;
> > > > +		goto st_press_free_buffer;
> > > >
> > > > -	return err;
> > > > +	return st_sensors_set_enable(indio_dev, true);
> > > >
> > > > -st_press_buffer_postenable_error:
> > > > +st_press_free_buffer:
> > > >  	kfree(press_data->buffer_data);
> > > > -allocate_memory_error:
> > > >  	return err;
> > > >  }
> > > >
> > > >  static int st_press_buffer_predisable(struct iio_dev *indio_dev)
> > > > {
> > > > -	int err;
> > > >  	struct st_sensor_data *press_data = iio_priv(indio_dev);
> > > > -
> > > > -	err = iio_triggered_buffer_predisable(indio_dev);
> > > > -	if (err < 0)
> > > > -		goto st_press_buffer_predisable_error;
> > > > +	int err, err2;
> > > >
> > > >  	err = st_sensors_set_enable(indio_dev, false);
> > > >
> > > > -st_press_buffer_predisable_error:
> > > > +	err2 = iio_triggered_buffer_predisable(indio_dev);
> > > > +	if (!err)
> > > > +		err = err2;
> > > > +
> > > >  	kfree(press_data->buffer_data);
> > > >  	return err;
> > > >  }
> > > >
> > > >  static const struct iio_buffer_setup_ops st_press_buffer_setup_ops =
> {
> > > > -	.preenable = &st_press_buffer_preenable,
> > > >  	.postenable = &st_press_buffer_postenable,
> > > >  	.predisable = &st_press_buffer_predisable,  };

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

end of thread, back to index

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-30  0:03 [PATCH 0/4] preenable/postenable/predisable fixup for ST drivers Denis Ciocca
2019-07-30  0:03 ` [PATCH 1/4] iio:accel: preenable/postenable/predisable fixup for ST accel buffer Denis Ciocca
2019-07-30  8:52   ` Ardelean, Alexandru
2019-07-30  0:03 ` [PATCH 2/4] iio:gyro: preenable/postenable/predisable fixup for ST gyro buffer Denis Ciocca
2019-07-30  8:52   ` Ardelean, Alexandru
2019-07-30  0:03 ` [PATCH 3/4] iio:magn: preenable/postenable/predisable fixup for ST magn buffer Denis Ciocca
2019-07-30  8:54   ` Ardelean, Alexandru
2019-07-30  0:03 ` [PATCH 4/4] iio:pressure: preenable/postenable/predisable fixup for ST press buffer Denis Ciocca
2019-07-30  9:02   ` Ardelean, Alexandru
2019-07-30 16:08     ` Denis CIOCCA
2019-07-31  6:58       ` Ardelean, Alexandru
2019-07-31 21:48         ` Denis CIOCCA
2019-07-30  9:03 ` [PATCH 0/4] preenable/postenable/predisable fixup for ST drivers Ardelean, Alexandru

Linux-IIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iio/0 linux-iio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iio linux-iio/ https://lore.kernel.org/linux-iio \
		linux-iio@vger.kernel.org linux-iio@archiver.kernel.org
	public-inbox-index linux-iio


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-iio


AGPL code for this site: git clone https://public-inbox.org/ public-inbox