Re: [PATCH] iio: light: gp2ap020a00f: Fix signedness bug in gp2ap020a00f_get_thresh_reg()

From: Jonathan Cameron

Date: Wed Dec 31 2025 - 12:15:54 EST


On Sat, 27 Dec 2025 17:00:46 +0200
Andy Shevchenko <andriy.shevchenko@xxxxxxxxx> wrote:

> 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).

This pattern is absolutely fine. I don't mind using an err, ret or similar
briefly like this as the real meaning of the successful value is right there
2 lines down

Jonathan

>
> ...
>
> Ditto for the other function.
>