If st_gyro_common_probe function fails, the device must be unregistered. Used devm_iio_device_unregister function instead of iio_device_unregister also in the common remove function. Signed-off-by: Denis Ciocca <denis.ciocca@xxxxxx> --- drivers/iio/gyro/st_gyro_core.c | 2 +- drivers/iio/gyro/st_gyro_i2c.c | 6 +++++- drivers/iio/gyro/st_gyro_spi.c | 6 +++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c index a8e174a..67f88ed 100644 --- a/drivers/iio/gyro/st_gyro_core.c +++ b/drivers/iio/gyro/st_gyro_core.c @@ -360,7 +360,7 @@ void st_gyro_common_remove(struct iio_dev *indio_dev) { struct st_sensor_data *gdata = iio_priv(indio_dev); - iio_device_unregister(indio_dev); + devm_iio_device_unregister(gdata->dev, indio_dev); if (gdata->get_irq_data_ready(indio_dev) > 0) st_sensors_deallocate_trigger(indio_dev); diff --git a/drivers/iio/gyro/st_gyro_i2c.c b/drivers/iio/gyro/st_gyro_i2c.c index 23c12f3..41def78 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_unregister(&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..9fc1a57 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_unregister(&spi->dev, indio_dev); + return err; } static int st_gyro_spi_remove(struct spi_device *spi) -- 1.8.5.4 -- To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html