From: Erikas Bitovtas Date: Tue, 14 Apr 2026 12:37:20 +0000 (+0300) Subject: iio: light: vcnl4000: move power state function into device-managed action X-Git-Tag: v7.2-rc1~67^2~5^2~214 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=857cb79df06b2890c2338295ab2f35e943f30d7b;p=thirdparty%2Fkernel%2Flinux.git iio: light: vcnl4000: move power state function into device-managed action 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 Signed-off-by: Jonathan Cameron --- diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c index 52f60b372d2f1..1e636e6f51da3 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,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)