Re: [PATCH] iio: light: cm32181: return zero after writing calibscale

David Lechner <[email protected]> Sat, 1 Aug 2026 10:24:08 -0500
Newsgroups org.kernel.vger.linux-iio,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
On 7/31/26 8:20 AM, Giorgi Tchankvetadze wrote:
> From: Giorgi Tchankvetadze <[email protected]>
> 
> The write_raw callback is documented to return 0 on success or a
> negative error code.  However, the IIO_CHAN_INFO_CALIBSCALE case
> returns 'val' (the user-supplied value) instead of 0.
> 
> Fix it by returning 0 on success, matching the behavior of other
> calibscale implementations in the subsystem.
> 
> Fixes: 971672c0b3cc ("iio: add Capella CM32181 ambient light sensor driver.")
> Signed-off-by: Giorgi Tchankvetadze <[email protected]>
> ---
>  drivers/iio/light/cm32181.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/light/cm32181.c b/drivers/iio/light/cm32181.c
> index 2590fc8fd154..b32a94028f09 100644
> --- a/drivers/iio/light/cm32181.c
> +++ b/drivers/iio/light/cm32181.c
> @@ -368,7 +368,7 @@ static int cm32181_write_raw(struct iio_dev *indio_dev,
>  	switch (mask) {
>  	case IIO_CHAN_INFO_CALIBSCALE:
>  		cm32181->calibscale = val;
> -		return val;
> +		return 0;
>  	case IIO_CHAN_INFO_INT_TIME:
>  		ret = cm32181_write_als_it(cm32181, val2);
>  		return ret;

While we are looking at this, it looks like we can follow this up
with another patch to return cm32181_write_als_it() directly and
drop the ret local variable.

There are also a couple of switch statements where we could move
the return -EINVAL into a default: case as we usually do in IIO.
(A separate patch for this as well.)