Commit 5ff7ea50 authored by Andrew Davis's avatar Andrew Davis Committed by Jonathan Cameron

iio: health: afe4404: 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: default avatarAndrew Davis <afd@ti.com>
Link: https://lore.kernel.org/r/20240123140918.215818-3-afd@ti.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent e73a640f
...@@ -349,6 +349,13 @@ static irqreturn_t afe4404_trigger_handler(int irq, void *private) ...@@ -349,6 +349,13 @@ static irqreturn_t afe4404_trigger_handler(int irq, void *private)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
static void afe4404_regulator_disable(void *data)
{
struct regulator *regulator = data;
regulator_disable(regulator);
}
/* Default timings from data-sheet */ /* Default timings from data-sheet */
#define AFE4404_TIMING_PAIRS \ #define AFE4404_TIMING_PAIRS \
{ AFE440X_PRPCOUNT, 39999 }, \ { AFE440X_PRPCOUNT, 39999 }, \
...@@ -502,19 +509,24 @@ static int afe4404_probe(struct i2c_client *client) ...@@ -502,19 +509,24 @@ static int afe4404_probe(struct i2c_client *client)
dev_err(afe->dev, "Unable to enable regulator\n"); dev_err(afe->dev, "Unable to enable regulator\n");
return ret; return ret;
} }
ret = devm_add_action_or_reset(afe->dev, afe4404_regulator_disable, afe->regulator);
if (ret) {
dev_err(afe->dev, "Unable to enable regulator\n");
return ret;
}
ret = regmap_write(afe->regmap, AFE440X_CONTROL0, ret = regmap_write(afe->regmap, AFE440X_CONTROL0,
AFE440X_CONTROL0_SW_RESET); AFE440X_CONTROL0_SW_RESET);
if (ret) { if (ret) {
dev_err(afe->dev, "Unable to reset device\n"); dev_err(afe->dev, "Unable to reset device\n");
goto disable_reg; return ret;
} }
ret = regmap_multi_reg_write(afe->regmap, afe4404_reg_sequences, ret = regmap_multi_reg_write(afe->regmap, afe4404_reg_sequences,
ARRAY_SIZE(afe4404_reg_sequences)); ARRAY_SIZE(afe4404_reg_sequences));
if (ret) { if (ret) {
dev_err(afe->dev, "Unable to set register defaults\n"); dev_err(afe->dev, "Unable to set register defaults\n");
goto disable_reg; return ret;
} }
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
...@@ -530,8 +542,7 @@ static int afe4404_probe(struct i2c_client *client) ...@@ -530,8 +542,7 @@ static int afe4404_probe(struct i2c_client *client)
iio_device_id(indio_dev)); iio_device_id(indio_dev));
if (!afe->trig) { if (!afe->trig) {
dev_err(afe->dev, "Unable to allocate IIO trigger\n"); dev_err(afe->dev, "Unable to allocate IIO trigger\n");
ret = -ENOMEM; return -ENOMEM;
goto disable_reg;
} }
iio_trigger_set_drvdata(afe->trig, indio_dev); iio_trigger_set_drvdata(afe->trig, indio_dev);
...@@ -539,7 +550,7 @@ static int afe4404_probe(struct i2c_client *client) ...@@ -539,7 +550,7 @@ static int afe4404_probe(struct i2c_client *client)
ret = iio_trigger_register(afe->trig); ret = iio_trigger_register(afe->trig);
if (ret) { if (ret) {
dev_err(afe->dev, "Unable to register IIO trigger\n"); dev_err(afe->dev, "Unable to register IIO trigger\n");
goto disable_reg; return ret;
} }
ret = devm_request_threaded_irq(afe->dev, afe->irq, ret = devm_request_threaded_irq(afe->dev, afe->irq,
...@@ -549,7 +560,7 @@ static int afe4404_probe(struct i2c_client *client) ...@@ -549,7 +560,7 @@ static int afe4404_probe(struct i2c_client *client)
afe->trig); afe->trig);
if (ret) { if (ret) {
dev_err(afe->dev, "Unable to request IRQ\n"); dev_err(afe->dev, "Unable to request IRQ\n");
goto disable_reg; return ret;
} }
} }
...@@ -573,8 +584,6 @@ static int afe4404_probe(struct i2c_client *client) ...@@ -573,8 +584,6 @@ static int afe4404_probe(struct i2c_client *client)
unregister_trigger: unregister_trigger:
if (afe->irq > 0) if (afe->irq > 0)
iio_trigger_unregister(afe->trig); iio_trigger_unregister(afe->trig);
disable_reg:
regulator_disable(afe->regulator);
return ret; return ret;
} }
...@@ -591,10 +600,6 @@ static void afe4404_remove(struct i2c_client *client) ...@@ -591,10 +600,6 @@ static void afe4404_remove(struct i2c_client *client)
if (afe->irq > 0) if (afe->irq > 0)
iio_trigger_unregister(afe->trig); iio_trigger_unregister(afe->trig);
ret = regulator_disable(afe->regulator);
if (ret)
dev_err(afe->dev, "Unable to disable regulator\n");
} }
static const struct i2c_device_id afe4404_ids[] = { static const struct i2c_device_id afe4404_ids[] = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment