diff options
author | Jonathan Cameron <Jonathan.Cameron@huawei.com> | 2021-05-16 19:25:15 +0200 |
---|---|---|
committer | Jonathan Cameron <Jonathan.Cameron@huawei.com> | 2021-06-03 19:24:14 +0200 |
commit | 30b527dd4fc50db0490d8e3e30b37cafd6302cf7 (patch) | |
tree | 2a0221ad231f5ad1561f12eef44987799665d8d5 /drivers/iio/adc | |
parent | iio: adc: max11100: Use devm_ functions for rest of probe() (diff) | |
download | linux-30b527dd4fc50db0490d8e3e30b37cafd6302cf7.tar.xz linux-30b527dd4fc50db0490d8e3e30b37cafd6302cf7.zip |
iio: adc: max1118: Use devm_ managed functions for all of probe
This simplifies error handling and allows us to drop the remove
function entirely.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Akinobu Mita <akinobu.mita@gmail.com>
Reviewed-by: Alexandru Ardelean <aardelean@deviqon.com>
Link: https://lore.kernel.org/r/20210516172520.1398835-4-jic23@kernel.org
Diffstat (limited to 'drivers/iio/adc')
-rw-r--r-- | drivers/iio/adc/max1118.c | 46 |
1 files changed, 15 insertions, 31 deletions
diff --git a/drivers/iio/adc/max1118.c b/drivers/iio/adc/max1118.c index 6efb0b43d938..4dfbed63ad7f 100644 --- a/drivers/iio/adc/max1118.c +++ b/drivers/iio/adc/max1118.c @@ -201,6 +201,11 @@ out: return IRQ_HANDLED; } +static void max1118_reg_disable(void *reg) +{ + regulator_disable(reg); +} + static int max1118_probe(struct spi_device *spi) { struct iio_dev *indio_dev; @@ -225,6 +230,12 @@ static int max1118_probe(struct spi_device *spi) ret = regulator_enable(adc->reg); if (ret) return ret; + + ret = devm_add_action_or_reset(&spi->dev, max1118_reg_disable, + adc->reg); + if (ret) + return ret; + } spi_set_drvdata(spi, indio_dev); @@ -243,38 +254,12 @@ static int max1118_probe(struct spi_device *spi) */ max1118_read(spi, 0); - ret = iio_triggered_buffer_setup(indio_dev, NULL, - max1118_trigger_handler, NULL); + ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, NULL, + max1118_trigger_handler, NULL); if (ret) - goto err_reg_disable; - - ret = iio_device_register(indio_dev); - if (ret) - goto err_buffer_cleanup; - - return 0; - -err_buffer_cleanup: - iio_triggered_buffer_cleanup(indio_dev); -err_reg_disable: - if (id->driver_data == max1118) - regulator_disable(adc->reg); - - return ret; -} - -static int max1118_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct max1118 *adc = iio_priv(indio_dev); - const struct spi_device_id *id = spi_get_device_id(spi); - - iio_device_unregister(indio_dev); - iio_triggered_buffer_cleanup(indio_dev); - if (id->driver_data == max1118) - return regulator_disable(adc->reg); + return ret; - return 0; + return devm_iio_device_register(&spi->dev, indio_dev); } static const struct spi_device_id max1118_id[] = { @@ -299,7 +284,6 @@ static struct spi_driver max1118_spi_driver = { .of_match_table = max1118_dt_ids, }, .probe = max1118_probe, - .remove = max1118_remove, .id_table = max1118_id, }; module_spi_driver(max1118_spi_driver); |