[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240929-veml6070-cleanup-v1-1-a9350341a646@gmail.com>
Date: Sun, 29 Sep 2024 22:38:46 +0200
From: Javier Carrasco <javier.carrasco.cruz@...il.com>
To: Jonathan Cameron <jic23@...nel.org>,
Lars-Peter Clausen <lars@...afoo.de>, Rob Herring <robh@...nel.org>,
Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>
Cc: linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org,
devicetree@...r.kernel.org,
Javier Carrasco <javier.carrasco.cruz@...il.com>
Subject: [PATCH 1/7] iio: light: veml6070: add action for
i2c_unregister_device
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@...il.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
Powered by blists - more mailing lists