From: Erikas Bitovtas <xerikasxx@gmail.com>
To: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
Erikas Bitovtas <xerikasxx@gmail.com>
Subject: [PATCH v3 4/6] iio: light: vcnl4000: move power state function into device-managed action
Date: Fri, 10 Apr 2026 19:11:20 +0300 [thread overview]
Message-ID: <20260410-vcnl4000-drop-enum-v3-4-2ea2bc6f5dfb@gmail.com> (raw)
In-Reply-To: <20260410-vcnl4000-drop-enum-v3-0-2ea2bc6f5dfb@gmail.com>
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>
---
drivers/iio/light/vcnl4000.c | 32 +++++++++++++++++++++-----------
1 file changed, 21 insertions(+), 11 deletions(-)
diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
index bbb84b71f226..1a8672564cc4 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)
--
2.53.0
next prev parent reply other threads:[~2026-04-10 16:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-10 16:11 [PATCH v3 0/6] iio: light: vcnl4000: drop enum ID table and use device-managed register Erikas Bitovtas
2026-04-10 16:11 ` [PATCH v3 1/6] iio: light: vcnl4000: validate device by prod ID instead of table ID Erikas Bitovtas
2026-04-10 16:11 ` [PATCH v3 2/6] iio: light: vcnl4000: drop enum id table in favor of chip structs Erikas Bitovtas
2026-04-10 16:11 ` [PATCH v3 3/6] iio: light: vcnl4000: move device tree entries into one line Erikas Bitovtas
2026-04-10 16:11 ` Erikas Bitovtas [this message]
2026-04-10 16:11 ` [PATCH v3 5/6] iio: light: vcnl4000: make pm_runtime_enable() device-managed Erikas Bitovtas
2026-04-10 16:11 ` [PATCH v3 6/6] iio: light: vcnl4000: register an IIO device with a device-managed function Erikas Bitovtas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260410-vcnl4000-drop-enum-v3-4-2ea2bc6f5dfb@gmail.com \
--to=xerikasxx@gmail.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox