use devm_iio_device_free on common probe failed and remove
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
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
@@ -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
@@ -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
@@ -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
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_probefunction fails, the device must be freed. Addeddevm_iio_device_freealso oncommon_removefunction.
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
Jonathan Cameron
maintainerRe: [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_probefunction fails, the device must be freed. Addeddevm_iio_device_freealso oncommon_removefunction.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
PATCH 2/4 iio:gyro: call devm_iio_device_free function if common_proble fails
In reply to Denis CIOCCAIf 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
@@ -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
@@ -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
@@ -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
PATCH 3/4 iio:magnetometer: call devm_iio_device_free function if common_proble fails
In reply to Denis CIOCCAIf 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
@@ -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
@@ -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
@@ -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
PATCH 4/4 iio:pressure: call devm_iio_device_free function if common_proble fails
In reply to Denis CIOCCAIf 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
@@ -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
@@ -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
@@ -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