diff mbox series

[v3,2/5] iio: light: al3000a: Fix an error handling path in al3000a_probe()

Message ID 20250402-al3010-iio-regmap-v3-2-cc3da273b5b2@ixit.cz (mailing list archive)
State New
Headers show
Series iio: light: Modernize al3010 and al3320a codebase | expand

Commit Message

David Heidelberg April 2, 2025, 7:14 p.m. UTC
From: David Heidelberg <david@ixit.cz>

If regmap_write() fails in al3000a_init(), al3000a_set_pwr_off is
not called.

In order to avoid such a situation, move the devm_add_action_or_reset()
which calls al3000a_set_pwr_off right after a successful
al3000a_set_pwr_on.

Signed-off-by: David Heidelberg <david@ixit.cz>
---
 drivers/iio/light/al3000a.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/drivers/iio/light/al3000a.c b/drivers/iio/light/al3000a.c
index e2fbb1270040f43d9f0a97838861818a8eaef813..e6208bfeb3be9040364463ef6d59a15d31e8700c 100644
--- a/drivers/iio/light/al3000a.c
+++ b/drivers/iio/light/al3000a.c
@@ -91,6 +91,10 @@  static int al3000a_init(struct al3000a_data *data)
 	if (ret)
 		return ret;
 
+	ret = devm_add_action_or_reset(&data->client->dev, al3000a_set_pwr_off, data);
+	if (ret)
+		return dev_err_probe(&data->client->dev, ret, "failed to add action\n");
+
 	ret = regmap_write(data->regmap, AL3000A_REG_SYSTEM, AL3000A_CONFIG_RESET);
 	if (ret)
 		return ret;
@@ -157,10 +161,6 @@  static int al3000a_probe(struct i2c_client *client)
 	if (ret)
 		return dev_err_probe(dev, ret, "failed to init ALS\n");
 
-	ret = devm_add_action_or_reset(dev, al3000a_set_pwr_off, data);
-	if (ret)
-		return dev_err_probe(dev, ret, "failed to add action\n");
-
 	return devm_iio_device_register(dev, indio_dev);
 }