]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iio: light: vcnl4000: move power state function into device-managed action
authorErikas Bitovtas <xerikasxx@gmail.com>
Tue, 14 Apr 2026 12:37:20 +0000 (15:37 +0300)
committerJonathan Cameron <jic23@kernel.org>
Mon, 27 Apr 2026 08:58:21 +0000 (09:58 +0100)
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@gmail.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/iio/light/vcnl4000.c

index 52f60b372d2f186423f92b436098acfcdfad7ac7..1e636e6f51da3078529c4b43b2935171edf39a72 100644 (file)
@@ -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,19 +2057,20 @@ 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;
+               goto fail_register;
 
        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);
+
+fail_register:
+       pm_runtime_set_suspended(dev);
        return ret;
 }
 
@@ -2073,18 +2090,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)