[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241001-veml6035-v3-7-d789f6ff147c@gmail.com>
Date: Tue, 01 Oct 2024 22:21:20 +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>, Rishi Gupta <gupt21@...il.com>
Cc: linux-iio@...r.kernel.org, devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org,
Jonathan Cameron <Jonathan.Cameron@...wei.com>,
Javier Carrasco <javier.carrasco.cruz@...il.com>
Subject: [PATCH v3 7/9] iio: light: veml6030: power off device in probe
error paths
Move devm_add_action_or_reset() with a device shut down action to the
hardware initialization function to ensure that any error path after
powering on the device leads to a power off. Add struct device *dev
to the argument list to clarify the device the action is registered
against, and use it wherever &client->dev was used.
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@...il.com>
---
drivers/iio/light/veml6030.c | 32 +++++++++++++-------------------
1 file changed, 13 insertions(+), 19 deletions(-)
diff --git a/drivers/iio/light/veml6030.c b/drivers/iio/light/veml6030.c
index 677374e401b3..0e4c36e8a566 100644
--- a/drivers/iio/light/veml6030.c
+++ b/drivers/iio/light/veml6030.c
@@ -740,45 +740,44 @@ static irqreturn_t veml6030_event_handler(int irq, void *private)
* interrupt disabled by default. First shutdown the sensor,
* update registers and then power on the sensor.
*/
-static int veml6030_hw_init(struct iio_dev *indio_dev)
+static int veml6030_hw_init(struct iio_dev *indio_dev, struct device *dev)
{
int ret, val;
struct veml6030_data *data = iio_priv(indio_dev);
- struct i2c_client *client = data->client;
ret = veml6030_als_shut_down(data);
if (ret)
- return dev_err_probe(&client->dev, ret, "can't shutdown als\n");
+ return dev_err_probe(dev, ret, "can't shutdown als\n");
ret = regmap_write(data->regmap, VEML6030_REG_ALS_CONF, 0x1001);
if (ret)
- return dev_err_probe(&client->dev, ret,
- "can't setup als configs\n");
+ return dev_err_probe(dev, ret, "can't setup als configs\n");
ret = regmap_update_bits(data->regmap, VEML6030_REG_ALS_PSM,
VEML6030_PSM | VEML6030_PSM_EN, 0x03);
if (ret)
- return dev_err_probe(&client->dev, ret,
- "can't setup default PSM\n");
+ return dev_err_probe(dev, ret, "can't setup default PSM\n");
ret = regmap_write(data->regmap, VEML6030_REG_ALS_WH, 0xFFFF);
if (ret)
- return dev_err_probe(&client->dev, ret,
- "can't setup high threshold\n");
+ return dev_err_probe(dev, ret, "can't setup high threshold\n");
ret = regmap_write(data->regmap, VEML6030_REG_ALS_WL, 0x0000);
if (ret)
- return dev_err_probe(&client->dev, ret,
- "can't setup low threshold\n");
+ return dev_err_probe(dev, ret, "can't setup low threshold\n");
ret = veml6030_als_pwr_on(data);
if (ret)
- return dev_err_probe(&client->dev, ret, "can't poweron als\n");
+ return dev_err_probe(dev, ret, "can't poweron als\n");
+
+ ret = devm_add_action_or_reset(dev, veml6030_als_shut_down_action, data);
+ if (ret < 0)
+ return ret;
/* Clear stale interrupt status bits if any during start */
ret = regmap_read(data->regmap, VEML6030_REG_ALS_INT, &val);
if (ret < 0)
- return dev_err_probe(&client->dev, ret,
+ return dev_err_probe(dev, ret,
"can't clear als interrupt status\n");
/* Cache currently active measurement parameters */
@@ -839,12 +838,7 @@ static int veml6030_probe(struct i2c_client *client)
indio_dev->info = &veml6030_info_no_irq;
}
- ret = veml6030_hw_init(indio_dev);
- if (ret < 0)
- return ret;
-
- ret = devm_add_action_or_reset(&client->dev,
- veml6030_als_shut_down_action, data);
+ ret = veml6030_hw_init(indio_dev, &client->dev);
if (ret < 0)
return ret;
--
2.43.0
Powered by blists - more mailing lists