summaryrefslogtreecommitdiff
path: root/drivers/iio/health/afe4403.c
diff options
context:
space:
mode:
authorAndrew Davis <afd@ti.com>2024-01-23 17:09:15 +0300
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2024-02-17 19:16:09 +0300
commiteeb4c24a5c909be376675963767fbcd36072fc6a (patch)
tree0ccae321ca3ae728ac81e958e80f3b2d64f80f6e /drivers/iio/health/afe4403.c
parente21b4321f965d684d1b2d5dfb1ec0d5c3c71892b (diff)
downloadlinux-eeb4c24a5c909be376675963767fbcd36072fc6a.tar.xz
iio: health: afe4403: Use devm action helper for regulator disable
Use a device lifecycle managed action for regulator disable function. This helps prevent mistakes like unregistering out of order in cleanup functions and forgetting to unregister on error paths. Signed-off-by: Andrew Davis <afd@ti.com> Link: https://lore.kernel.org/r/20240123140918.215818-1-afd@ti.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio/health/afe4403.c')
-rw-r--r--drivers/iio/health/afe4403.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/drivers/iio/health/afe4403.c b/drivers/iio/health/afe4403.c
index df3bc5c3d378..9e9d6de2a7c8 100644
--- a/drivers/iio/health/afe4403.c
+++ b/drivers/iio/health/afe4403.c
@@ -346,6 +346,13 @@ err:
return IRQ_HANDLED;
}
+static void afe4403_regulator_disable(void *data)
+{
+ struct regulator *regulator = data;
+
+ regulator_disable(regulator);
+}
+
#define AFE4403_TIMING_PAIRS \
{ AFE440X_LED2STC, 0x000050 }, \
{ AFE440X_LED2ENDC, 0x0003e7 }, \
@@ -495,19 +502,24 @@ static int afe4403_probe(struct spi_device *spi)
dev_err(afe->dev, "Unable to enable regulator\n");
return ret;
}
+ ret = devm_add_action_or_reset(afe->dev, afe4403_regulator_disable, afe->regulator);
+ if (ret) {
+ dev_err(afe->dev, "Unable to add regulator disable action\n");
+ return ret;
+ }
ret = regmap_write(afe->regmap, AFE440X_CONTROL0,
AFE440X_CONTROL0_SW_RESET);
if (ret) {
dev_err(afe->dev, "Unable to reset device\n");
- goto err_disable_reg;
+ return ret;
}
ret = regmap_multi_reg_write(afe->regmap, afe4403_reg_sequences,
ARRAY_SIZE(afe4403_reg_sequences));
if (ret) {
dev_err(afe->dev, "Unable to set register defaults\n");
- goto err_disable_reg;
+ return ret;
}
indio_dev->modes = INDIO_DIRECT_MODE;
@@ -523,8 +535,7 @@ static int afe4403_probe(struct spi_device *spi)
iio_device_id(indio_dev));
if (!afe->trig) {
dev_err(afe->dev, "Unable to allocate IIO trigger\n");
- ret = -ENOMEM;
- goto err_disable_reg;
+ return -ENOMEM;
}
iio_trigger_set_drvdata(afe->trig, indio_dev);
@@ -532,7 +543,7 @@ static int afe4403_probe(struct spi_device *spi)
ret = iio_trigger_register(afe->trig);
if (ret) {
dev_err(afe->dev, "Unable to register IIO trigger\n");
- goto err_disable_reg;
+ return ret;
}
ret = devm_request_threaded_irq(afe->dev, afe->irq,
@@ -566,8 +577,6 @@ err_buff:
err_trig:
if (afe->irq > 0)
iio_trigger_unregister(afe->trig);
-err_disable_reg:
- regulator_disable(afe->regulator);
return ret;
}
@@ -584,10 +593,6 @@ static void afe4403_remove(struct spi_device *spi)
if (afe->irq > 0)
iio_trigger_unregister(afe->trig);
-
- ret = regulator_disable(afe->regulator);
- if (ret)
- dev_warn(afe->dev, "Unable to disable regulator\n");
}
static const struct spi_device_id afe4403_ids[] = {