From: Javier Carrasco <javier.carrasco.cruz@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>,
Lars-Peter Clausen <lars@metafoo.de>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org,
Javier Carrasco <javier.carrasco.cruz@gmail.com>
Subject: [PATCH 1/7] iio: light: veml6070: add action for i2c_unregister_device
Date: Sun, 29 Sep 2024 22:38:46 +0200 [thread overview]
Message-ID: <20240929-veml6070-cleanup-v1-1-a9350341a646@gmail.com> (raw)
In-Reply-To: <20240929-veml6070-cleanup-v1-0-a9350341a646@gmail.com>
Simplify the code by adding an action to call i2c_unregister_device(),
which removes the need for a 'fail' label, gotos to it, and an explicit
call in veml6070_remove().
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
drivers/iio/light/veml6070.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/drivers/iio/light/veml6070.c b/drivers/iio/light/veml6070.c
index f8321d346d77..3c476b6f6122 100644
--- a/drivers/iio/light/veml6070.c
+++ b/drivers/iio/light/veml6070.c
@@ -135,6 +135,13 @@ static const struct iio_info veml6070_info = {
.read_raw = veml6070_read_raw,
};
+static void veml6070_i2c_unreg(void *p)
+{
+ struct veml6070_data *data = p;
+
+ i2c_unregister_device(data->client2);
+}
+
static int veml6070_probe(struct i2c_client *client)
{
struct veml6070_data *data;
@@ -166,17 +173,13 @@ static int veml6070_probe(struct i2c_client *client)
VEML6070_COMMAND_SD;
ret = i2c_smbus_write_byte(data->client1, data->config);
if (ret < 0)
- goto fail;
+ return ret;
- ret = iio_device_register(indio_dev);
+ ret = devm_add_action_or_reset(&client->dev, veml6070_i2c_unreg, data);
if (ret < 0)
- goto fail;
+ return ret;
- return ret;
-
-fail:
- i2c_unregister_device(data->client2);
- return ret;
+ return iio_device_register(indio_dev);
}
static void veml6070_remove(struct i2c_client *client)
@@ -185,7 +188,6 @@ static void veml6070_remove(struct i2c_client *client)
struct veml6070_data *data = iio_priv(indio_dev);
iio_device_unregister(indio_dev);
- i2c_unregister_device(data->client2);
}
static const struct i2c_device_id veml6070_id[] = {
--
2.43.0
next prev parent reply other threads:[~2024-09-29 20:38 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-29 20:38 [PATCH 0/7] iio: light: veml6070: update code to current IIO best practices Javier Carrasco
2024-09-29 20:38 ` Javier Carrasco [this message]
2024-09-29 20:38 ` [PATCH 2/7] iio: light: veml6070: use guard to handle mutex Javier Carrasco
2024-09-29 20:38 ` [PATCH 3/7] iio: light: veml6070: use device managed iio_device_register Javier Carrasco
2024-09-29 20:38 ` [PATCH 4/7] iio: light: veml6070: add support for a regulator Javier Carrasco
2024-09-29 20:38 ` [PATCH 5/7] dt-bindings: iio: light: vishay,veml6075: add vishay,veml6070 Javier Carrasco
2024-09-30 7:01 ` Krzysztof Kozlowski
2024-09-29 20:38 ` [PATCH 6/7] iio: light: veml6070: add devicetree support Javier Carrasco
2024-09-30 9:00 ` Jonathan Cameron
2024-09-29 20:38 ` [PATCH 7/7] iio: light: veml6070: use dev_err_probe in probe function Javier Carrasco
2024-09-30 9:00 ` [PATCH 0/7] iio: light: veml6070: update code to current IIO best practices Jonathan Cameron
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=20240929-veml6070-cleanup-v1-1-a9350341a646@gmail.com \
--to=javier.carrasco.cruz@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh@kernel.org \
/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