Re: [PATCH] iio: light: gp2ap020a00f: Fix signedness bug in gp2ap020a00f_get_thresh_reg()
From: Andy Shevchenko
Date: Sat Dec 27 2025 - 10:01:04 EST
On Fri, Dec 26, 2025 at 06:45:21PM +0300, Alper Ak wrote:
> gp2ap020a00f_get_thresh_reg() returns -EINVAL on error,
> but it was declared as a u8.
>
> Change the return type to int and update callers to use int type for
> the return value and properly check for negative error codes.
...
> thresh_reg_l = gp2ap020a00f_get_thresh_reg(chan, dir);
> +
This blank line is redundant.
> + if (thresh_reg_l < 0) {
> + err = thresh_reg_l;
> + goto error_unlock;
> + }
And entire code can be rewritten in a shorter way
(in this case the type not needed to be changed):
err = gp2ap020a00f_get_thresh_reg(chan, dir);
if (err < 0)
goto error_unlock;
thresh_reg_l = err;
but this one is up to maintainers as I know Jonathan likes the clear naming
to be assigned to (however when written as above it clear to me what's the
semantics of the non-negative returns).
...
Ditto for the other function.
--
With Best Regards,
Andy Shevchenko