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

v2 changes:
This second version is necessary in order to fix the possible failure of
set_enable (last function of postenable).

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       | 45 +++++++++------------
 drivers/iio/gyro/st_gyro_buffer.c         | 49 +++++++++++------------
 drivers/iio/magnetometer/st_magn_buffer.c | 30 +++++++-------
 drivers/iio/pressure/st_pressure_buffer.c | 38 ++++++++----------
 4 files changed, 77 insertions(+), 85 deletions(-)

-- 
2.22.0


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

* [PATCH v2 1/4] iio:accel: preenable/postenable/predisable fixup for ST accel buffer
  2019-07-31 21:48 [PATCH v2 0/4] preenable/postenable/predisable fixup for ST drivers Denis Ciocca
@ 2019-07-31 21:48 ` Denis Ciocca
  2019-08-01  8:21   ` Ardelean, Alexandru
  2019-07-31 21:48 ` [PATCH v2 2/4] iio:gyro: preenable/postenable/predisable fixup for ST gyro buffer Denis Ciocca
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 13+ messages in thread
From: Denis Ciocca @ 2019-07-31 21:48 UTC (permalink / raw)
  To: linux-iio, alexandru.Ardelean, jic23; +Cc: 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 | 45 +++++++++++++----------------
 1 file changed, 20 insertions(+), 25 deletions(-)

diff --git a/drivers/iio/accel/st_accel_buffer.c b/drivers/iio/accel/st_accel_buffer.c
index 05f9aea431e2..59dcef02ec19 100644
--- a/drivers/iio/accel/st_accel_buffer.c
+++ b/drivers/iio/accel/st_accel_buffer.c
@@ -29,56 +29,52 @@ 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]);
+					 (u8)indio_dev->active_scan_mask[0]);
 	if (err < 0)
-		goto st_sensors_set_axis_enable_error;
+		goto st_accel_buffer_predisable;
 
-	return err;
+	err = st_sensors_set_enable(indio_dev, true);
+	if (err < 0)
+		goto st_accel_buffer_enable_all_axis;
+
+	return 0;
 
-st_sensors_set_axis_enable_error:
+st_accel_buffer_enable_all_axis:
+	st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
+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 +84,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 v2 2/4] iio:gyro: preenable/postenable/predisable fixup for ST gyro buffer
  2019-07-31 21:48 [PATCH v2 0/4] preenable/postenable/predisable fixup for ST drivers Denis Ciocca
  2019-07-31 21:48 ` [PATCH v2 1/4] iio:accel: preenable/postenable/predisable fixup for ST accel buffer Denis Ciocca
@ 2019-07-31 21:48 ` Denis Ciocca
  2019-08-01  8:22   ` Ardelean, Alexandru
  2019-07-31 21:48 ` [PATCH v2 3/4] iio:magn: preenable/postenable/predisable fixup for ST magn buffer Denis Ciocca
  2019-07-31 21:49 ` [PATCH v2 4/4] iio:pressure: preenable/postenable/predisable fixup for ST press buffer Denis Ciocca
  3 siblings, 1 reply; 13+ messages in thread
From: Denis Ciocca @ 2019-07-31 21:48 UTC (permalink / raw)
  To: linux-iio, alexandru.Ardelean, jic23; +Cc: 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 | 49 +++++++++++++++----------------
 1 file changed, 24 insertions(+), 25 deletions(-)

diff --git a/drivers/iio/gyro/st_gyro_buffer.c b/drivers/iio/gyro/st_gyro_buffer.c
index 21360681d4dd..c6ddfecc1fc3 100644
--- a/drivers/iio/gyro/st_gyro_buffer.c
+++ b/drivers/iio/gyro/st_gyro_buffer.c
@@ -29,62 +29,61 @@ 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 = iio_triggered_buffer_postenable(indio_dev);
+	if (err < 0)
+		goto st_gyro_free_buffer;
 
 	err = st_sensors_set_axis_enable(indio_dev,
-					(u8)indio_dev->active_scan_mask[0]);
+					 (u8)indio_dev->active_scan_mask[0]);
 	if (err < 0)
-		goto st_gyro_buffer_postenable_error;
+		goto st_gyro_buffer_predisable;
 
-	err = iio_triggered_buffer_postenable(indio_dev);
+	err = st_sensors_set_enable(indio_dev, true);
 	if (err < 0)
-		goto st_gyro_buffer_postenable_error;
+		goto st_gyro_buffer_enable_all_axis;
 
-	return err;
+	return 0;
 
-st_gyro_buffer_postenable_error:
+st_gyro_buffer_enable_all_axis:
+	st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
+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 v2 3/4] iio:magn: preenable/postenable/predisable fixup for ST magn buffer
  2019-07-31 21:48 [PATCH v2 0/4] preenable/postenable/predisable fixup for ST drivers Denis Ciocca
  2019-07-31 21:48 ` [PATCH v2 1/4] iio:accel: preenable/postenable/predisable fixup for ST accel buffer Denis Ciocca
  2019-07-31 21:48 ` [PATCH v2 2/4] iio:gyro: preenable/postenable/predisable fixup for ST gyro buffer Denis Ciocca
@ 2019-07-31 21:48 ` Denis Ciocca
  2019-08-01  8:22   ` Ardelean, Alexandru
  2019-07-31 21:49 ` [PATCH v2 4/4] iio:pressure: preenable/postenable/predisable fixup for ST press buffer Denis Ciocca
  3 siblings, 1 reply; 13+ messages in thread
From: Denis Ciocca @ 2019-07-31 21:48 UTC (permalink / raw)
  To: linux-iio, alexandru.Ardelean, jic23; +Cc: 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 | 30 ++++++++++++-----------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/drivers/iio/magnetometer/st_magn_buffer.c b/drivers/iio/magnetometer/st_magn_buffer.c
index 9dba93539a99..658d627dad8e 100644
--- a/drivers/iio/magnetometer/st_magn_buffer.c
+++ b/drivers/iio/magnetometer/st_magn_buffer.c
@@ -31,40 +31,42 @@ 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;
+
+	err = st_sensors_set_enable(indio_dev, true);
+	if (err < 0)
+		goto st_magn_buffer_predisable;
 
-	return st_sensors_set_enable(indio_dev, true);
+	return 0;
 
-st_magn_buffer_postenable_error:
+st_magn_buffer_predisable:
+	iio_triggered_buffer_predisable(indio_dev);
+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 v2 4/4] iio:pressure: preenable/postenable/predisable fixup for ST press buffer
  2019-07-31 21:48 [PATCH v2 0/4] preenable/postenable/predisable fixup for ST drivers Denis Ciocca
                   ` (2 preceding siblings ...)
  2019-07-31 21:48 ` [PATCH v2 3/4] iio:magn: preenable/postenable/predisable fixup for ST magn buffer Denis Ciocca
@ 2019-07-31 21:49 ` Denis Ciocca
  2019-08-01  8:22   ` Ardelean, Alexandru
  3 siblings, 1 reply; 13+ messages in thread
From: Denis Ciocca @ 2019-07-31 21:49 UTC (permalink / raw)
  To: linux-iio, alexandru.Ardelean, jic23; +Cc: 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 | 38 ++++++++++-------------
 1 file changed, 17 insertions(+), 21 deletions(-)

diff --git a/drivers/iio/pressure/st_pressure_buffer.c b/drivers/iio/pressure/st_pressure_buffer.c
index f21b630abaa0..77cb2d862f19 100644
--- a/drivers/iio/pressure/st_pressure_buffer.c
+++ b/drivers/iio/pressure/st_pressure_buffer.c
@@ -29,53 +29,49 @@ 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;
+	err = st_sensors_set_enable(indio_dev, true);
+	if (err < 0)
+		goto st_press_buffer_predisable;
+
+	return 0;
 
-st_press_buffer_postenable_error:
+st_press_buffer_predisable:
+	iio_triggered_buffer_predisable(indio_dev);
+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 v2 1/4] iio:accel: preenable/postenable/predisable fixup for ST accel buffer
  2019-07-31 21:48 ` [PATCH v2 1/4] iio:accel: preenable/postenable/predisable fixup for ST accel buffer Denis Ciocca
@ 2019-08-01  8:21   ` Ardelean, Alexandru
  2019-08-05 14:46     ` Jonathan Cameron
  0 siblings, 1 reply; 13+ messages in thread
From: Ardelean, Alexandru @ 2019-08-01  8:21 UTC (permalink / raw)
  To: jic23, denis.ciocca, linux-iio

On Wed, 2019-07-31 at 14:48 -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 | 45 +++++++++++++----------------
>  1 file changed, 20 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/iio/accel/st_accel_buffer.c b/drivers/iio/accel/st_accel_buffer.c
> index 05f9aea431e2..59dcef02ec19 100644
> --- a/drivers/iio/accel/st_accel_buffer.c
> +++ b/drivers/iio/accel/st_accel_buffer.c
> @@ -29,56 +29,52 @@ 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]);
> +					 (u8)indio_dev->active_scan_mask[0]);
>  	if (err < 0)
> -		goto st_sensors_set_axis_enable_error;
> +		goto st_accel_buffer_predisable;
>  
> -	return err;
> +	err = st_sensors_set_enable(indio_dev, true);
> +	if (err < 0)
> +		goto st_accel_buffer_enable_all_axis;
> +
> +	return 0;
>  
> -st_sensors_set_axis_enable_error:
> +st_accel_buffer_enable_all_axis:
> +	st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
> +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 +84,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 v2 2/4] iio:gyro: preenable/postenable/predisable fixup for ST gyro buffer
  2019-07-31 21:48 ` [PATCH v2 2/4] iio:gyro: preenable/postenable/predisable fixup for ST gyro buffer Denis Ciocca
@ 2019-08-01  8:22   ` Ardelean, Alexandru
  2019-08-05 14:46     ` Jonathan Cameron
  0 siblings, 1 reply; 13+ messages in thread
From: Ardelean, Alexandru @ 2019-08-01  8:22 UTC (permalink / raw)
  To: jic23, denis.ciocca, linux-iio

On Wed, 2019-07-31 at 14:48 -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 | 49 +++++++++++++++----------------
>  1 file changed, 24 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/iio/gyro/st_gyro_buffer.c b/drivers/iio/gyro/st_gyro_buffer.c
> index 21360681d4dd..c6ddfecc1fc3 100644
> --- a/drivers/iio/gyro/st_gyro_buffer.c
> +++ b/drivers/iio/gyro/st_gyro_buffer.c
> @@ -29,62 +29,61 @@ 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 = iio_triggered_buffer_postenable(indio_dev);
> +	if (err < 0)
> +		goto st_gyro_free_buffer;
>  
>  	err = st_sensors_set_axis_enable(indio_dev,
> -					(u8)indio_dev->active_scan_mask[0]);
> +					 (u8)indio_dev->active_scan_mask[0]);
>  	if (err < 0)
> -		goto st_gyro_buffer_postenable_error;
> +		goto st_gyro_buffer_predisable;
>  
> -	err = iio_triggered_buffer_postenable(indio_dev);
> +	err = st_sensors_set_enable(indio_dev, true);
>  	if (err < 0)
> -		goto st_gyro_buffer_postenable_error;
> +		goto st_gyro_buffer_enable_all_axis;
>  
> -	return err;
> +	return 0;
>  
> -st_gyro_buffer_postenable_error:
> +st_gyro_buffer_enable_all_axis:
> +	st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
> +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 v2 3/4] iio:magn: preenable/postenable/predisable fixup for ST magn buffer
  2019-07-31 21:48 ` [PATCH v2 3/4] iio:magn: preenable/postenable/predisable fixup for ST magn buffer Denis Ciocca
@ 2019-08-01  8:22   ` Ardelean, Alexandru
  2019-08-05 14:47     ` Jonathan Cameron
  0 siblings, 1 reply; 13+ messages in thread
From: Ardelean, Alexandru @ 2019-08-01  8:22 UTC (permalink / raw)
  To: jic23, denis.ciocca, linux-iio

On Wed, 2019-07-31 at 14:48 -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.
> 

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

> Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
> ---
>  drivers/iio/magnetometer/st_magn_buffer.c | 30 ++++++++++++-----------
>  1 file changed, 16 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/iio/magnetometer/st_magn_buffer.c b/drivers/iio/magnetometer/st_magn_buffer.c
> index 9dba93539a99..658d627dad8e 100644
> --- a/drivers/iio/magnetometer/st_magn_buffer.c
> +++ b/drivers/iio/magnetometer/st_magn_buffer.c
> @@ -31,40 +31,42 @@ 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;
> +
> +	err = st_sensors_set_enable(indio_dev, true);
> +	if (err < 0)
> +		goto st_magn_buffer_predisable;
>  
> -	return st_sensors_set_enable(indio_dev, true);
> +	return 0;
>  
> -st_magn_buffer_postenable_error:
> +st_magn_buffer_predisable:
> +	iio_triggered_buffer_predisable(indio_dev);
> +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 v2 4/4] iio:pressure: preenable/postenable/predisable fixup for ST press buffer
  2019-07-31 21:49 ` [PATCH v2 4/4] iio:pressure: preenable/postenable/predisable fixup for ST press buffer Denis Ciocca
@ 2019-08-01  8:22   ` Ardelean, Alexandru
  2019-08-05 14:49     ` Jonathan Cameron
  0 siblings, 1 reply; 13+ messages in thread
From: Ardelean, Alexandru @ 2019-08-01  8:22 UTC (permalink / raw)
  To: jic23, denis.ciocca, linux-iio

On Wed, 2019-07-31 at 14:49 -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/pressure/st_pressure_buffer.c | 38 ++++++++++-------------
>  1 file changed, 17 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/iio/pressure/st_pressure_buffer.c b/drivers/iio/pressure/st_pressure_buffer.c
> index f21b630abaa0..77cb2d862f19 100644
> --- a/drivers/iio/pressure/st_pressure_buffer.c
> +++ b/drivers/iio/pressure/st_pressure_buffer.c
> @@ -29,53 +29,49 @@ 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;
> +	err = st_sensors_set_enable(indio_dev, true);
> +	if (err < 0)
> +		goto st_press_buffer_predisable;
> +
> +	return 0;
>  
> -st_press_buffer_postenable_error:
> +st_press_buffer_predisable:
> +	iio_triggered_buffer_predisable(indio_dev);
> +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 v2 1/4] iio:accel: preenable/postenable/predisable fixup for ST accel buffer
  2019-08-01  8:21   ` Ardelean, Alexandru
@ 2019-08-05 14:46     ` Jonathan Cameron
  0 siblings, 0 replies; 13+ messages in thread
From: Jonathan Cameron @ 2019-08-05 14:46 UTC (permalink / raw)
  To: Ardelean, Alexandru; +Cc: denis.ciocca, linux-iio

On Thu, 1 Aug 2019 08:21:53 +0000
"Ardelean, Alexandru" <alexandru.Ardelean@analog.com> wrote:

> On Wed, 2019-07-31 at 14:48 -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>

Applied.

Thanks,

J
> 
> > Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
> > ---
> >  drivers/iio/accel/st_accel_buffer.c | 45 +++++++++++++----------------
> >  1 file changed, 20 insertions(+), 25 deletions(-)
> > 
> > diff --git a/drivers/iio/accel/st_accel_buffer.c b/drivers/iio/accel/st_accel_buffer.c
> > index 05f9aea431e2..59dcef02ec19 100644
> > --- a/drivers/iio/accel/st_accel_buffer.c
> > +++ b/drivers/iio/accel/st_accel_buffer.c
> > @@ -29,56 +29,52 @@ 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]);
> > +					 (u8)indio_dev->active_scan_mask[0]);
> >  	if (err < 0)
> > -		goto st_sensors_set_axis_enable_error;
> > +		goto st_accel_buffer_predisable;
> >  
> > -	return err;
> > +	err = st_sensors_set_enable(indio_dev, true);
> > +	if (err < 0)
> > +		goto st_accel_buffer_enable_all_axis;
> > +
> > +	return 0;
> >  
> > -st_sensors_set_axis_enable_error:
> > +st_accel_buffer_enable_all_axis:
> > +	st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
> > +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 +84,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 v2 2/4] iio:gyro: preenable/postenable/predisable fixup for ST gyro buffer
  2019-08-01  8:22   ` Ardelean, Alexandru
@ 2019-08-05 14:46     ` Jonathan Cameron
  0 siblings, 0 replies; 13+ messages in thread
From: Jonathan Cameron @ 2019-08-05 14:46 UTC (permalink / raw)
  To: Ardelean, Alexandru; +Cc: denis.ciocca, linux-iio

On Thu, 1 Aug 2019 08:22:00 +0000
"Ardelean, Alexandru" <alexandru.Ardelean@analog.com> wrote:

> On Wed, 2019-07-31 at 14:48 -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>
Applied.

Thanks,

J
> 
> > 
> > Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
> > ---
> >  drivers/iio/gyro/st_gyro_buffer.c | 49 +++++++++++++++----------------
> >  1 file changed, 24 insertions(+), 25 deletions(-)
> > 
> > diff --git a/drivers/iio/gyro/st_gyro_buffer.c b/drivers/iio/gyro/st_gyro_buffer.c
> > index 21360681d4dd..c6ddfecc1fc3 100644
> > --- a/drivers/iio/gyro/st_gyro_buffer.c
> > +++ b/drivers/iio/gyro/st_gyro_buffer.c
> > @@ -29,62 +29,61 @@ 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 = iio_triggered_buffer_postenable(indio_dev);
> > +	if (err < 0)
> > +		goto st_gyro_free_buffer;
> >  
> >  	err = st_sensors_set_axis_enable(indio_dev,
> > -					(u8)indio_dev->active_scan_mask[0]);
> > +					 (u8)indio_dev->active_scan_mask[0]);
> >  	if (err < 0)
> > -		goto st_gyro_buffer_postenable_error;
> > +		goto st_gyro_buffer_predisable;
> >  
> > -	err = iio_triggered_buffer_postenable(indio_dev);
> > +	err = st_sensors_set_enable(indio_dev, true);
> >  	if (err < 0)
> > -		goto st_gyro_buffer_postenable_error;
> > +		goto st_gyro_buffer_enable_all_axis;
> >  
> > -	return err;
> > +	return 0;
> >  
> > -st_gyro_buffer_postenable_error:
> > +st_gyro_buffer_enable_all_axis:
> > +	st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
> > +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 v2 3/4] iio:magn: preenable/postenable/predisable fixup for ST magn buffer
  2019-08-01  8:22   ` Ardelean, Alexandru
@ 2019-08-05 14:47     ` Jonathan Cameron
  0 siblings, 0 replies; 13+ messages in thread
From: Jonathan Cameron @ 2019-08-05 14:47 UTC (permalink / raw)
  To: Ardelean, Alexandru; +Cc: denis.ciocca, linux-iio

On Thu, 1 Aug 2019 08:22:07 +0000
"Ardelean, Alexandru" <alexandru.Ardelean@analog.com> wrote:

> On Wed, 2019-07-31 at 14:48 -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.
> >   
> 
> Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
I'm not overly keen on the if (!err) block, but not significant enough
to not take this and get this issue tidied up.

Applied to the togreg branch of iio.git and pushed out as testing for the
autobuilders to play with it.

Thanks,

J
> 
> > Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
> > ---
> >  drivers/iio/magnetometer/st_magn_buffer.c | 30 ++++++++++++-----------
> >  1 file changed, 16 insertions(+), 14 deletions(-)
> > 
> > diff --git a/drivers/iio/magnetometer/st_magn_buffer.c b/drivers/iio/magnetometer/st_magn_buffer.c
> > index 9dba93539a99..658d627dad8e 100644
> > --- a/drivers/iio/magnetometer/st_magn_buffer.c
> > +++ b/drivers/iio/magnetometer/st_magn_buffer.c
> > @@ -31,40 +31,42 @@ 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;
> > +
> > +	err = st_sensors_set_enable(indio_dev, true);
> > +	if (err < 0)
> > +		goto st_magn_buffer_predisable;
> >  
> > -	return st_sensors_set_enable(indio_dev, true);
> > +	return 0;
> >  
> > -st_magn_buffer_postenable_error:
> > +st_magn_buffer_predisable:
> > +	iio_triggered_buffer_predisable(indio_dev);
> > +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 v2 4/4] iio:pressure: preenable/postenable/predisable fixup for ST press buffer
  2019-08-01  8:22   ` Ardelean, Alexandru
@ 2019-08-05 14:49     ` Jonathan Cameron
  0 siblings, 0 replies; 13+ messages in thread
From: Jonathan Cameron @ 2019-08-05 14:49 UTC (permalink / raw)
  To: Ardelean, Alexandru; +Cc: denis.ciocca, linux-iio

On Thu, 1 Aug 2019 08:22:16 +0000
"Ardelean, Alexandru" <alexandru.Ardelean@analog.com> wrote:

> On Wed, 2019-07-31 at 14:49 -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>

Applied

Thanks,

Jonathan

> 
> > Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
> > ---
> >  drivers/iio/pressure/st_pressure_buffer.c | 38 ++++++++++-------------
> >  1 file changed, 17 insertions(+), 21 deletions(-)
> > 
> > diff --git a/drivers/iio/pressure/st_pressure_buffer.c b/drivers/iio/pressure/st_pressure_buffer.c
> > index f21b630abaa0..77cb2d862f19 100644
> > --- a/drivers/iio/pressure/st_pressure_buffer.c
> > +++ b/drivers/iio/pressure/st_pressure_buffer.c
> > @@ -29,53 +29,49 @@ 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;
> > +	err = st_sensors_set_enable(indio_dev, true);
> > +	if (err < 0)
> > +		goto st_press_buffer_predisable;
> > +
> > +	return 0;
> >  
> > -st_press_buffer_postenable_error:
> > +st_press_buffer_predisable:
> > +	iio_triggered_buffer_predisable(indio_dev);
> > +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-31 21:48 [PATCH v2 0/4] preenable/postenable/predisable fixup for ST drivers Denis Ciocca
2019-07-31 21:48 ` [PATCH v2 1/4] iio:accel: preenable/postenable/predisable fixup for ST accel buffer Denis Ciocca
2019-08-01  8:21   ` Ardelean, Alexandru
2019-08-05 14:46     ` Jonathan Cameron
2019-07-31 21:48 ` [PATCH v2 2/4] iio:gyro: preenable/postenable/predisable fixup for ST gyro buffer Denis Ciocca
2019-08-01  8:22   ` Ardelean, Alexandru
2019-08-05 14:46     ` Jonathan Cameron
2019-07-31 21:48 ` [PATCH v2 3/4] iio:magn: preenable/postenable/predisable fixup for ST magn buffer Denis Ciocca
2019-08-01  8:22   ` Ardelean, Alexandru
2019-08-05 14:47     ` Jonathan Cameron
2019-07-31 21:49 ` [PATCH v2 4/4] iio:pressure: preenable/postenable/predisable fixup for ST press buffer Denis Ciocca
2019-08-01  8:22   ` Ardelean, Alexandru
2019-08-05 14:49     ` Jonathan Cameron

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
	public-inbox-index linux-iio

Example config snippet for mirrors

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