[PATCH v2 4/6] iio: light: vcnl4000: move power state function into device-managed action

From: Erikas Bitovtas

Date: Sun Apr 05 2026 - 12:11:23 EST


Move power state setting into a device-managed action to get rid of
fail_poweroff goto label and remove it from vcnl4000_remove() function.

Signed-off-by: Erikas Bitovtas <xerikasxx@xxxxxxxxx>
---
drivers/iio/light/vcnl4000.c | 30 ++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
index bbb84b71f226..d28c7abe7642 100644
--- a/drivers/iio/light/vcnl4000.c
+++ b/drivers/iio/light/vcnl4000.c
@@ -1970,6 +1970,18 @@ static int vcnl4010_probe_trigger(struct iio_dev *indio_dev)
return devm_iio_trigger_register(&client->dev, trigger);
}

+static void vcnl4000_cleanup(void *data)
+{
+ struct iio_dev *indio_dev = data;
+ struct vcnl4000_data *chip = iio_priv(indio_dev);
+ struct device *dev = &chip->client->dev;
+ int ret;
+
+ ret = chip->chip_spec->set_power_state(chip, false);
+ if (ret)
+ dev_warn(dev, "Failed to power down (%pe)", ERR_PTR(ret));
+}
+
static int vcnl4000_probe(struct i2c_client *client)
{
const char * const regulator_names[] = { "vdd", "vio", "vled" };
@@ -2004,6 +2016,10 @@ static int vcnl4000_probe(struct i2c_client *client)
if (ret)
return ret;

+ ret = devm_add_action_or_reset(dev, vcnl4000_cleanup, indio_dev);
+ if (ret)
+ return ret;
+
dev_dbg(dev, "%s Ambient light/proximity sensor, Rev: %02x\n",
data->chip_spec->prod, data->rev);

@@ -2041,20 +2057,17 @@ static int vcnl4000_probe(struct i2c_client *client)

ret = pm_runtime_set_active(dev);
if (ret < 0)
- goto fail_poweroff;
+ return ret;

ret = iio_device_register(indio_dev);
if (ret < 0)
- goto fail_poweroff;
+ return ret;

pm_runtime_enable(dev);
pm_runtime_set_autosuspend_delay(dev, VCNL4000_SLEEP_DELAY_MS);
pm_runtime_use_autosuspend(dev);

return 0;
-fail_poweroff:
- data->chip_spec->set_power_state(data, false);
- return ret;
}

static const struct of_device_id vcnl_4000_of_match[] = {
@@ -2073,18 +2086,11 @@ MODULE_DEVICE_TABLE(of, vcnl_4000_of_match);
static void vcnl4000_remove(struct i2c_client *client)
{
struct iio_dev *indio_dev = i2c_get_clientdata(client);
- struct vcnl4000_data *data = iio_priv(indio_dev);
- int ret;

pm_runtime_dont_use_autosuspend(&client->dev);
pm_runtime_disable(&client->dev);
iio_device_unregister(indio_dev);
pm_runtime_set_suspended(&client->dev);
-
- ret = data->chip_spec->set_power_state(data, false);
- if (ret)
- dev_warn(&client->dev, "Failed to power down (%pe)\n",
- ERR_PTR(ret));
}

static int vcnl4000_runtime_suspend(struct device *dev)

--
2.53.0