All of lore.kernel.org
 help / color / mirror / Atom feed
* use devm_iio_device_free on common probe failed and remove
@ 2014-02-14 15:16 Denis CIOCCA
  2014-02-14 15:16 ` [PATCH 1/4] iio:accel: call devm_iio_device_free function if common_proble fails Denis CIOCCA
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Denis CIOCCA @ 2014-02-14 15:16 UTC (permalink / raw)
  To: linux-iio

Hi all,

sorry for the previous 4 patches, are wrong!
I've sent the wrong test code. I just sent the correct series.

Thanks,
Denis


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

* [PATCH 1/4] iio:accel: call devm_iio_device_free function if common_proble fails
  2014-02-14 15:16 use devm_iio_device_free on common probe failed and remove Denis CIOCCA
@ 2014-02-14 15:16 ` Denis CIOCCA
  2014-02-14 16:11   ` Lars-Peter Clausen
  2014-02-14 15:16 ` [PATCH 2/4] iio:gyro: " Denis CIOCCA
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Denis CIOCCA @ 2014-02-14 15:16 UTC (permalink / raw)
  To: linux-iio; +Cc: Denis Ciocca

If st_accel_common_probe function fails, the device must be freed.
Added devm_iio_device_free also on common_remove function.

Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
---
 drivers/iio/accel/st_accel_core.c | 1 +
 drivers/iio/accel/st_accel_i2c.c  | 6 +++++-
 drivers/iio/accel/st_accel_spi.c  | 6 +++++-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
index 38caedc..5ba3049 100644
--- a/drivers/iio/accel/st_accel_core.c
+++ b/drivers/iio/accel/st_accel_core.c
@@ -517,6 +517,7 @@ void st_accel_common_remove(struct iio_dev *indio_dev)
 		st_sensors_deallocate_trigger(indio_dev);
 
 	st_accel_deallocate_ring(indio_dev);
+	devm_iio_device_free(adata->dev, indio_dev);
 }
 EXPORT_SYMBOL(st_accel_common_remove);
 
diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c
index d7bedbd..391b035 100644
--- a/drivers/iio/accel/st_accel_i2c.c
+++ b/drivers/iio/accel/st_accel_i2c.c
@@ -36,9 +36,13 @@ static int st_accel_i2c_probe(struct i2c_client *client,
 
 	err = st_accel_common_probe(indio_dev, client->dev.platform_data);
 	if (err < 0)
-		return err;
+		goto device_unregister;
 
 	return 0;
+
+device_unregister:
+	devm_iio_device_free(&client->dev, indio_dev);
+	return err;
 }
 
 static int st_accel_i2c_remove(struct i2c_client *client)
diff --git a/drivers/iio/accel/st_accel_spi.c b/drivers/iio/accel/st_accel_spi.c
index 1956396..52ebbdb 100644
--- a/drivers/iio/accel/st_accel_spi.c
+++ b/drivers/iio/accel/st_accel_spi.c
@@ -35,9 +35,13 @@ static int st_accel_spi_probe(struct spi_device *spi)
 
 	err = st_accel_common_probe(indio_dev, spi->dev.platform_data);
 	if (err < 0)
-		return err;
+		goto device_unregister;
 
 	return 0;
+
+device_unregister:
+	devm_iio_device_free(&spi->dev, indio_dev);
+	return err;
 }
 
 static int st_accel_spi_remove(struct spi_device *spi)
-- 
1.8.5.4


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

* [PATCH 2/4] iio:gyro: call devm_iio_device_free function if common_proble fails
  2014-02-14 15:16 use devm_iio_device_free on common probe failed and remove Denis CIOCCA
  2014-02-14 15:16 ` [PATCH 1/4] iio:accel: call devm_iio_device_free function if common_proble fails Denis CIOCCA
@ 2014-02-14 15:16 ` Denis CIOCCA
  2014-02-14 15:16 ` [PATCH 3/4] iio:magnetometer: " Denis CIOCCA
  2014-02-14 15:16 ` [PATCH 4/4] iio:pressure: " Denis CIOCCA
  3 siblings, 0 replies; 7+ messages in thread
From: Denis CIOCCA @ 2014-02-14 15:16 UTC (permalink / raw)
  To: linux-iio; +Cc: Denis Ciocca

If st_gyro_common_probe function fails, the device must be freed.
Added devm_iio_device_free also on common_remove function.

Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
---
 drivers/iio/gyro/st_gyro_core.c | 1 +
 drivers/iio/gyro/st_gyro_i2c.c  | 6 +++++-
 drivers/iio/gyro/st_gyro_spi.c  | 6 +++++-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
index a8e174a..33295ef 100644
--- a/drivers/iio/gyro/st_gyro_core.c
+++ b/drivers/iio/gyro/st_gyro_core.c
@@ -365,6 +365,7 @@ void st_gyro_common_remove(struct iio_dev *indio_dev)
 		st_sensors_deallocate_trigger(indio_dev);
 
 	st_gyro_deallocate_ring(indio_dev);
+	devm_iio_device_free(gdata->dev, indio_dev);
 }
 EXPORT_SYMBOL(st_gyro_common_remove);
 
diff --git a/drivers/iio/gyro/st_gyro_i2c.c b/drivers/iio/gyro/st_gyro_i2c.c
index 23c12f3..12c1b97 100644
--- a/drivers/iio/gyro/st_gyro_i2c.c
+++ b/drivers/iio/gyro/st_gyro_i2c.c
@@ -37,9 +37,13 @@ static int st_gyro_i2c_probe(struct i2c_client *client,
 	err = st_gyro_common_probe(indio_dev,
 				(struct st_sensors_platform_data *)&gyro_pdata);
 	if (err < 0)
-		return err;
+		goto device_unregister;
 
 	return 0;
+
+device_unregister:
+	devm_iio_device_free(&client->dev, indio_dev);
+	return err;
 }
 
 static int st_gyro_i2c_remove(struct i2c_client *client)
diff --git a/drivers/iio/gyro/st_gyro_spi.c b/drivers/iio/gyro/st_gyro_spi.c
index b4ad3be..7aaa290 100644
--- a/drivers/iio/gyro/st_gyro_spi.c
+++ b/drivers/iio/gyro/st_gyro_spi.c
@@ -36,9 +36,13 @@ static int st_gyro_spi_probe(struct spi_device *spi)
 	err = st_gyro_common_probe(indio_dev,
 				(struct st_sensors_platform_data *)&gyro_pdata);
 	if (err < 0)
-		return err;
+		goto device_unregister;
 
 	return 0;
+
+device_unregister:
+	devm_iio_device_free(&spi->dev, indio_dev);
+	return err;
 }
 
 static int st_gyro_spi_remove(struct spi_device *spi)
-- 
1.8.5.4


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

* [PATCH 3/4] iio:magnetometer: call devm_iio_device_free function if common_proble fails
  2014-02-14 15:16 use devm_iio_device_free on common probe failed and remove Denis CIOCCA
  2014-02-14 15:16 ` [PATCH 1/4] iio:accel: call devm_iio_device_free function if common_proble fails Denis CIOCCA
  2014-02-14 15:16 ` [PATCH 2/4] iio:gyro: " Denis CIOCCA
@ 2014-02-14 15:16 ` Denis CIOCCA
  2014-02-14 15:16 ` [PATCH 4/4] iio:pressure: " Denis CIOCCA
  3 siblings, 0 replies; 7+ messages in thread
From: Denis CIOCCA @ 2014-02-14 15:16 UTC (permalink / raw)
  To: linux-iio; +Cc: Denis Ciocca

If st_magn_common_probe function fails, the device must be freed.
Added devm_iio_device_free also on common_remove function.

Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
---
 drivers/iio/magnetometer/st_magn_core.c | 1 +
 drivers/iio/magnetometer/st_magn_i2c.c  | 6 +++++-
 drivers/iio/magnetometer/st_magn_spi.c  | 6 +++++-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
index 52bbcfa..018f01c 100644
--- a/drivers/iio/magnetometer/st_magn_core.c
+++ b/drivers/iio/magnetometer/st_magn_core.c
@@ -408,6 +408,7 @@ void st_magn_common_remove(struct iio_dev *indio_dev)
 		st_sensors_deallocate_trigger(indio_dev);
 
 	st_magn_deallocate_ring(indio_dev);
+	devm_iio_device_free(mdata->dev, indio_dev);
 }
 EXPORT_SYMBOL(st_magn_common_remove);
 
diff --git a/drivers/iio/magnetometer/st_magn_i2c.c b/drivers/iio/magnetometer/st_magn_i2c.c
index 892e0fe..5e33e2d 100644
--- a/drivers/iio/magnetometer/st_magn_i2c.c
+++ b/drivers/iio/magnetometer/st_magn_i2c.c
@@ -36,9 +36,13 @@ static int st_magn_i2c_probe(struct i2c_client *client,
 
 	err = st_magn_common_probe(indio_dev, NULL);
 	if (err < 0)
-		return err;
+		goto device_unregister;
 
 	return 0;
+
+device_unregister:
+	devm_iio_device_free(&client->dev, indio_dev);
+	return err;
 }
 
 static int st_magn_i2c_remove(struct i2c_client *client)
diff --git a/drivers/iio/magnetometer/st_magn_spi.c b/drivers/iio/magnetometer/st_magn_spi.c
index a6143ea..09c5845 100644
--- a/drivers/iio/magnetometer/st_magn_spi.c
+++ b/drivers/iio/magnetometer/st_magn_spi.c
@@ -35,9 +35,13 @@ static int st_magn_spi_probe(struct spi_device *spi)
 
 	err = st_magn_common_probe(indio_dev, NULL);
 	if (err < 0)
-		return err;
+		goto device_unregister;
 
 	return 0;
+
+device_unregister:
+	devm_iio_device_free(&spi->dev, indio_dev);
+	return err;
 }
 
 static int st_magn_spi_remove(struct spi_device *spi)
-- 
1.8.5.4


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

* [PATCH 4/4] iio:pressure: call devm_iio_device_free function if common_proble fails
  2014-02-14 15:16 use devm_iio_device_free on common probe failed and remove Denis CIOCCA
                   ` (2 preceding siblings ...)
  2014-02-14 15:16 ` [PATCH 3/4] iio:magnetometer: " Denis CIOCCA
@ 2014-02-14 15:16 ` Denis CIOCCA
  3 siblings, 0 replies; 7+ messages in thread
From: Denis CIOCCA @ 2014-02-14 15:16 UTC (permalink / raw)
  To: linux-iio; +Cc: Denis Ciocca

If st_press_common_probe function fails, the device must be freed.
Added devm_iio_device_free also on common_remove function.

Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
---
 drivers/iio/pressure/st_pressure_core.c | 1 +
 drivers/iio/pressure/st_pressure_i2c.c  | 6 +++++-
 drivers/iio/pressure/st_pressure_spi.c  | 6 +++++-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
index 58083f9..36c38ff 100644
--- a/drivers/iio/pressure/st_pressure_core.c
+++ b/drivers/iio/pressure/st_pressure_core.c
@@ -424,6 +424,7 @@ void st_press_common_remove(struct iio_dev *indio_dev)
 		st_sensors_deallocate_trigger(indio_dev);
 
 	st_press_deallocate_ring(indio_dev);
+	devm_iio_device_free(pdata->dev, indio_dev);
 }
 EXPORT_SYMBOL(st_press_common_remove);
 
diff --git a/drivers/iio/pressure/st_pressure_i2c.c b/drivers/iio/pressure/st_pressure_i2c.c
index 51eab7f..db0104f 100644
--- a/drivers/iio/pressure/st_pressure_i2c.c
+++ b/drivers/iio/pressure/st_pressure_i2c.c
@@ -36,9 +36,13 @@ static int st_press_i2c_probe(struct i2c_client *client,
 
 	err = st_press_common_probe(indio_dev, client->dev.platform_data);
 	if (err < 0)
-		return err;
+		goto device_unregister;
 
 	return 0;
+
+device_unregister:
+	devm_iio_device_free(&client->dev, indio_dev);
+	return err;
 }
 
 static int st_press_i2c_remove(struct i2c_client *client)
diff --git a/drivers/iio/pressure/st_pressure_spi.c b/drivers/iio/pressure/st_pressure_spi.c
index 27322af..f3d91cf 100644
--- a/drivers/iio/pressure/st_pressure_spi.c
+++ b/drivers/iio/pressure/st_pressure_spi.c
@@ -35,9 +35,13 @@ static int st_press_spi_probe(struct spi_device *spi)
 
 	err = st_press_common_probe(indio_dev, spi->dev.platform_data);
 	if (err < 0)
-		return err;
+		goto device_unregister;
 
 	return 0;
+
+device_unregister:
+	devm_iio_device_free(&spi->dev, indio_dev);
+	return err;
 }
 
 static int st_press_spi_remove(struct spi_device *spi)
-- 
1.8.5.4


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

* Re: [PATCH 1/4] iio:accel: call devm_iio_device_free function if common_proble fails
  2014-02-14 15:16 ` [PATCH 1/4] iio:accel: call devm_iio_device_free function if common_proble fails Denis CIOCCA
@ 2014-02-14 16:11   ` Lars-Peter Clausen
  2014-02-15  9:47     ` Jonathan Cameron
  0 siblings, 1 reply; 7+ messages in thread
From: Lars-Peter Clausen @ 2014-02-14 16:11 UTC (permalink / raw)
  To: Denis CIOCCA; +Cc: linux-iio

On 02/14/2014 04:16 PM, Denis CIOCCA wrote:
> If st_accel_common_probe function fails, the device must be freed.
> Added devm_iio_device_free also on common_remove function.

When the device is allocated with devm_iio_device... you do not need to 
manually free the device. If probe fails the device will be freed automatically.

- Lars

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

* Re: [PATCH 1/4] iio:accel: call devm_iio_device_free function if common_proble fails
  2014-02-14 16:11   ` Lars-Peter Clausen
@ 2014-02-15  9:47     ` Jonathan Cameron
  0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2014-02-15  9:47 UTC (permalink / raw)
  To: Lars-Peter Clausen, Denis CIOCCA; +Cc: linux-iio

On 14/02/14 16:11, Lars-Peter Clausen wrote:
> On 02/14/2014 04:16 PM, Denis CIOCCA wrote:
>> If st_accel_common_probe function fails, the device must be freed.
>> Added devm_iio_device_free also on common_remove function.
>
> When the device is allocated with devm_iio_device... you do not need to manually free the device. If probe fails the device will be freed automatically.
>
> - Lars
Indeed - the handling in these drivers appears entirely correct.
The allocs are done with devm so under any error conditions or
deliberate removal they will be cleared up.

The register should not be done using devm as that would mean the
unregister would occur late.  As the register is done last, there
are no error conditions that can require it being removed in the
probe function.  Hence the code looks fine to me as it stands.

So Denis, do you have an observed problem that prompted these patches?

Jonathan

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

end of thread, other threads:[~2014-02-15  9:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-14 15:16 use devm_iio_device_free on common probe failed and remove Denis CIOCCA
2014-02-14 15:16 ` [PATCH 1/4] iio:accel: call devm_iio_device_free function if common_proble fails Denis CIOCCA
2014-02-14 16:11   ` Lars-Peter Clausen
2014-02-15  9:47     ` Jonathan Cameron
2014-02-14 15:16 ` [PATCH 2/4] iio:gyro: " Denis CIOCCA
2014-02-14 15:16 ` [PATCH 3/4] iio:magnetometer: " Denis CIOCCA
2014-02-14 15:16 ` [PATCH 4/4] iio:pressure: " Denis CIOCCA

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.