Re: [PATCH v1 1/4] iio: light: Unshadow error codes in ->store()

"Maxwell Doose" <[email protected]>
Newsgroups org.kernel.vger.linux-iio,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
On Thu Aug 13, 2026 at 2:16 AM CDT
Andy Shevchenko <[email protected]> wrote:

> kstrtox() may return different error codes.
>
> Unshadow them in the ->store() callback to give better error report.
>
> While at it, add missing kstrtox.h inclusion.
>
> Signed-off-by: Andy Shevchenko <[email protected]>
> ---
>  drivers/iio/light/isl29018.c   |  7 +++++--
>  drivers/iio/light/lm3533-als.c | 11 +++++++----
>  drivers/iio/light/tsl2583.c    | 15 +++++++++++----
>  drivers/iio/light/tsl2772.c    | 16 ++++++++++++----
>  4 files changed, 35 insertions(+), 14 deletions(-)
>
...
> diff --git a/drivers/iio/light/tsl2583.c b/drivers/iio/light/tsl2583.c
> index 53fd423aa7ae..2d041b7530e6 100644
> --- a/drivers/iio/light/tsl2583.c
> +++ b/drivers/iio/light/tsl2583.c
> @@ -7,10 +7,11 @@
>   * Copyright (c) 2016-2017 Brian Masney <[email protected]>
>   */
>  
> -#include <linux/kernel.h>
>  #include <linux/i2c.h>
>  #include <linux/errno.h>
>  #include <linux/delay.h>
> +#include <linux/kernel.h>

Stray change? The ordering's messed up (seems to be case for many of
these drivers) so perhaps we can send a patch to fix the ordering.

Otherwise,

Reviewed-by: Maxwell Doose <[email protected]>

thanks,
max

> +#include <linux/kstrtox.h>
>  #include <linux/string.h>
>  #include <linux/mutex.h>
>  #include <linux/unistd.h>
> @@ -483,9 +484,12 @@ static ssize_t in_illuminance_input_target_store(struct device *dev,
>  {
>  	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
>  	struct tsl2583_chip *chip = iio_priv(indio_dev);
> -	int value;
> +	int value, ret;
>  
> -	if (kstrtoint(buf, 0, &value) || !value)
> +	ret = kstrtoint(buf, 0, &value);
> +	if (ret)
> +		return ret;
> +	if (!value)
>  		return -EINVAL;
>  
>  	mutex_lock(&chip->als_mutex);
> @@ -503,7 +507,10 @@ static ssize_t in_illuminance_calibrate_store(struct device *dev,
>  	struct tsl2583_chip *chip = iio_priv(indio_dev);
>  	int value, ret;
>  
> -	if (kstrtoint(buf, 0, &value) || value != 1)
> +	ret = kstrtoint(buf, 0, &value);
> +	if (ret)
> +		return ret;
> +	if (value != 1)
>  		return -EINVAL;
>  
>  	mutex_lock(&chip->als_mutex);
> diff --git a/drivers/iio/light/tsl2772.c b/drivers/iio/light/tsl2772.c
> index 4486a1d9d84d..c8a7afc65c1f 100644
> --- a/drivers/iio/light/tsl2772.c
> +++ b/drivers/iio/light/tsl2772.c
> @@ -13,6 +13,7 @@
>  #include <linux/i2c.h>
>  #include <linux/interrupt.h>
>  #include <linux/kernel.h>
> +#include <linux/kstrtox.h>
>  #include <linux/module.h>
>  #include <linux/mutex.h>
>  #include <linux/property.h>
> @@ -951,8 +952,9 @@ static ssize_t in_illuminance0_target_input_store(struct device *dev,
>  	u16 value;
>  	int ret;
>  
> -	if (kstrtou16(buf, 0, &value))
> -		return -EINVAL;
> +	ret = kstrtou16(buf, 0, &value);
> +	if (ret)
> +		return ret;
>  
>  	chip->settings.als_cal_target = value;
>  	ret = tsl2772_invoke_change(indio_dev);
> @@ -970,7 +972,10 @@ static ssize_t in_illuminance0_calibrate_store(struct device *dev,
>  	bool value;
>  	int ret;
>  
> -	if (kstrtobool(buf, &value) || !value)
> +	ret = kstrtobool(buf, &value);
> +	if (ret)
> +		return ret;
> +	if (!value)
>  		return -EINVAL;
>  
>  	ret = tsl2772_als_calibrate(indio_dev);
> @@ -1061,7 +1066,10 @@ static ssize_t in_proximity0_calibrate_store(struct device *dev,
>  	bool value;
>  	int ret;
>  
> -	if (kstrtobool(buf, &value) || !value)
> +	ret = kstrtobool(buf, &value);
> +	if (ret)
> +		return ret;
> +	if (!value)
>  		return -EINVAL;
>  
>  	ret = tsl2772_prox_cal(indio_dev);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.