diff mbox series

[v4,1/5] iio: light: al3010: Improve al3010_init error handling with dev_err_probe()

Message ID 20250402-al3010-iio-regmap-v4-1-d189bea87261@ixit.cz (mailing list archive)
State New
Headers show
Series iio: light: Modernize al3010 and al3320a codebase | expand

Commit Message

David Heidelberg April 2, 2025, 7:33 p.m. UTC
From: David Heidelberg <david@ixit.cz>

Minor code simplifications and improved error reporting.

Signed-off-by: David Heidelberg <david@ixit.cz>
---
 drivers/iio/light/al3010.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

Comments

Christophe JAILLET April 3, 2025, 6:01 p.m. UTC | #1
Le 02/04/2025 à 21:33, David Heidelberg via B4 Relay a écrit :
> From: David Heidelberg <david-W22tF5X+A20@public.gmane.org>
> 
> Minor code simplifications and improved error reporting.
> 
> Signed-off-by: David Heidelberg <david-W22tF5X+A20@public.gmane.org>
> ---
>   drivers/iio/light/al3010.c | 10 ++++------
>   1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/iio/light/al3010.c b/drivers/iio/light/al3010.c
> index 8c004a9239aef246a8c6f6c3f4acd6b760ee8249..34a29a51c5f9e8aa143d3ba195b79a19793e4f88 100644
> --- a/drivers/iio/light/al3010.c
> +++ b/drivers/iio/light/al3010.c
> @@ -92,8 +92,8 @@ static int al3010_init(struct al3010_data *data)
>   	ret = devm_add_action_or_reset(&data->client->dev,
>   				       al3010_set_pwr_off,
>   				       data);
> -	if (ret < 0)
> -		return ret;
> +	if (ret)
> +		return dev_err_probe(&data->client->dev, ret, "failed to add action\n");

Not sure this new message is needed.

The error is unlikely, and kmalloc(), which is used in is 
devm_add_action_or_reset(), is already verbose.

CJ

>   
>   	ret = i2c_smbus_write_byte_data(data->client, AL3010_REG_CONFIG,
>   					FIELD_PREP(AL3010_GAIN_MASK,
> @@ -190,10 +190,8 @@ static int al3010_probe(struct i2c_client *client)
>   	indio_dev->modes = INDIO_DIRECT_MODE;
>   
>   	ret = al3010_init(data);
> -	if (ret < 0) {
> -		dev_err(dev, "al3010 chip init failed\n");
> -		return ret;
> -	}
> +	if (ret)
> +		return dev_err_probe(dev, ret, "failed to init ALS\n");
>   
>   	return devm_iio_device_register(dev, indio_dev);
>   }
>
diff mbox series

Patch

diff --git a/drivers/iio/light/al3010.c b/drivers/iio/light/al3010.c
index 8c004a9239aef246a8c6f6c3f4acd6b760ee8249..34a29a51c5f9e8aa143d3ba195b79a19793e4f88 100644
--- a/drivers/iio/light/al3010.c
+++ b/drivers/iio/light/al3010.c
@@ -92,8 +92,8 @@  static int al3010_init(struct al3010_data *data)
 	ret = devm_add_action_or_reset(&data->client->dev,
 				       al3010_set_pwr_off,
 				       data);
-	if (ret < 0)
-		return ret;
+	if (ret)
+		return dev_err_probe(&data->client->dev, ret, "failed to add action\n");
 
 	ret = i2c_smbus_write_byte_data(data->client, AL3010_REG_CONFIG,
 					FIELD_PREP(AL3010_GAIN_MASK,
@@ -190,10 +190,8 @@  static int al3010_probe(struct i2c_client *client)
 	indio_dev->modes = INDIO_DIRECT_MODE;
 
 	ret = al3010_init(data);
-	if (ret < 0) {
-		dev_err(dev, "al3010 chip init failed\n");
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to init ALS\n");
 
 	return devm_iio_device_register(dev, indio_dev);
 }