Re: [PATCH v4 5/9] iio: light: gp2ap020a00f: Return directly from the switch cases
From: Andy Shevchenko
Date: Thu Feb 19 2026 - 15:00:34 EST
On Thu, Feb 19, 2026 at 01:32:20PM -0600, Ethan Tidmore wrote:
> On Tue Feb 17, 2026 at 10:37 PM CST, Ethan Tidmore wrote:
...
> > By doing this, it appears to have fixed a preexisting bug, the variable
> > err in gp2ap020a00f_buffer_predisable() is only checked once for errors
> > after the for loop is finished. This could allow errors to be swallowed.
...
> > static int gp2ap020a00f_buffer_postenable(struct iio_dev *indio_dev)
> > {
> > struct gp2ap020a00f_data *data = iio_priv(indio_dev);
> > - int i, err = 0;
> > + int i, err;
> >
> > guard(mutex)(&data->lock);
> >
> > @@ -1400,15 +1378,15 @@ static int gp2ap020a00f_buffer_postenable(struct iio_dev *indio_dev)
> >
> > data->buffer = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
> > if (!data->buffer)
> > - err = -ENOMEM;
> > + return -ENOMEM;
> >
> > - return err;
> > + return 0;
> > }
>
> Looking over the code again it looks like
> gp2ap020a00f_buffer_postenable() contains the same bug you mentioned
> where the error check should have been inside of the loop?
>
>
> iio_for_each_active_channel(indio_dev, i) {
> switch (i) {
> case GP2AP020A00F_SCAN_MODE_LIGHT_CLEAR:
> err = gp2ap020a00f_exec_cmd(data,
> GP2AP020A00F_CMD_TRIGGER_CLEAR_EN);
> break;
> case GP2AP020A00F_SCAN_MODE_LIGHT_IR:
> err = gp2ap020a00f_exec_cmd(data,
> GP2AP020A00F_CMD_TRIGGER_IR_EN);
> break;
> case GP2AP020A00F_SCAN_MODE_PROXIMITY:
> err = gp2ap020a00f_exec_cmd(data,
> GP2AP020A00F_CMD_TRIGGER_PROX_EN);
> break;
> }
> }
>
> if (err < 0)
> goto error_unlock;
>
> Just wanted to confirm before putting it in the v5.
Good catch! So, these two should be split into a separate change explaining
the change in behaviour.
--
With Best Regards,
Andy Shevchenko