Skip to contentSkip to conversation

use devm_iio_device_free on common probe failed and remove

PATCH In review Denis CIOCCA 3 participants 7 messages Feb 14, 2014 – Feb 15, 2014 IIO

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw

PATCH 1/4 iio:accel: call devm_iio_device_free function if common_proble fails

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

---
 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(-)
drivers/iio/accel/st_accel_core.c +1 -0
index 38caedc..5ba3049 100644
@@ -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);
 
drivers/iio/accel/st_accel_i2c.c +5 -1
index d7bedbd..391b035 100644
@@ -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)
drivers/iio/accel/st_accel_spi.c +5 -1
index 1956396..52ebbdb 100644
@@ -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)
Signature · 1 line
1.8.5.4
#2 lore raw

Re: [PATCH 1/4] iio:accel: call devm_iio_device_free function if common_proble fails

Quoted 2 lines · Denis CIOCCA

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

maintainer
#3 lore raw

Re: [PATCH 1/4] iio:accel: call devm_iio_device_free function if common_proble fails

Quoted 7 lines · Lars-Peter Clausen
Quoted 2 lines · Denis CIOCCA

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

#4 lore raw

PATCH 2/4 iio:gyro: call devm_iio_device_free function if common_proble fails

In reply to Denis CIOCCA

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

---
 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(-)
drivers/iio/gyro/st_gyro_core.c +1 -0
index a8e174a..33295ef 100644
@@ -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);
 
drivers/iio/gyro/st_gyro_i2c.c +5 -1
index 23c12f3..12c1b97 100644
@@ -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)
drivers/iio/gyro/st_gyro_spi.c +5 -1
index b4ad3be..7aaa290 100644
@@ -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)
Signature · 1 line
1.8.5.4
#5 lore raw

PATCH 3/4 iio:magnetometer: call devm_iio_device_free function if common_proble fails

In reply to Denis CIOCCA

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

---
 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(-)
drivers/iio/magnetometer/st_magn_core.c +1 -0
index 52bbcfa..018f01c 100644
@@ -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);
 
drivers/iio/magnetometer/st_magn_i2c.c +5 -1
index 892e0fe..5e33e2d 100644
@@ -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)
drivers/iio/magnetometer/st_magn_spi.c +5 -1
index a6143ea..09c5845 100644
@@ -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)
Signature · 1 line
1.8.5.4
#6 lore raw

PATCH 4/4 iio:pressure: call devm_iio_device_free function if common_proble fails

In reply to Denis CIOCCA

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

---
 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(-)
drivers/iio/pressure/st_pressure_core.c +1 -0
index 58083f9..36c38ff 100644
@@ -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);
 
drivers/iio/pressure/st_pressure_i2c.c +5 -1
index 51eab7f..db0104f 100644
@@ -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)
drivers/iio/pressure/st_pressure_spi.c +5 -1
index 27322af..f3d91cf 100644
@@ -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)
Signature · 1 line
1.8.5.4