summaryrefslogtreecommitdiff
path: root/drivers/iio
diff options
context:
space:
mode:
authorLucas Stankus <lucas.p.stankus@gmail.com>2021-03-29 00:46:04 +0300
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2021-03-29 14:17:41 +0300
commit44fc4de9bd61ca2c7f5215df5321457af3bece24 (patch)
treec59d8b2da9be4361f0b9fc39632343f026d8bf3c /drivers/iio
parentabfdfd144357e6f555db234f6a64498423a4322a (diff)
downloadlinux-44fc4de9bd61ca2c7f5215df5321457af3bece24.tar.xz
iio: adc: ad7923: use devm_add_action_or_reset for regulator disable
Adds a device-managed action to handle disabling the driver's regulator on device detach. This slightly simplifies deinitialization and enables further conversion of the driver to device-managed routines without breaking the init order. Signed-off-by: Lucas Stankus <lucas.p.stankus@gmail.com> Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com> Link: https://lore.kernel.org/r/49a7c0436ca1186313dbccf3d810d0cf38cb5b37.1616966903.git.lucas.p.stankus@gmail.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio')
-rw-r--r--drivers/iio/adc/ad7923.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/drivers/iio/adc/ad7923.c b/drivers/iio/adc/ad7923.c
index a2cc96658054..3418ef6f0857 100644
--- a/drivers/iio/adc/ad7923.c
+++ b/drivers/iio/adc/ad7923.c
@@ -293,6 +293,13 @@ static const struct iio_info ad7923_info = {
.update_scan_mode = ad7923_update_scan_mode,
};
+static void ad7923_regulator_disable(void *data)
+{
+ struct ad7923_state *st = data;
+
+ regulator_disable(st->reg);
+}
+
static int ad7923_probe(struct spi_device *spi)
{
struct ad7923_state *st;
@@ -340,10 +347,14 @@ static int ad7923_probe(struct spi_device *spi)
if (ret)
return ret;
+ ret = devm_add_action_or_reset(&spi->dev, ad7923_regulator_disable, st);
+ if (ret)
+ return ret;
+
ret = iio_triggered_buffer_setup(indio_dev, NULL,
&ad7923_trigger_handler, NULL);
if (ret)
- goto error_disable_reg;
+ return ret;
ret = iio_device_register(indio_dev);
if (ret)
@@ -353,20 +364,15 @@ static int ad7923_probe(struct spi_device *spi)
error_cleanup_ring:
iio_triggered_buffer_cleanup(indio_dev);
-error_disable_reg:
- regulator_disable(st->reg);
-
return ret;
}
static int ad7923_remove(struct spi_device *spi)
{
struct iio_dev *indio_dev = spi_get_drvdata(spi);
- struct ad7923_state *st = iio_priv(indio_dev);
iio_device_unregister(indio_dev);
iio_triggered_buffer_cleanup(indio_dev);
- regulator_disable(st->reg);
return 0;
}