Re: [PATCH v5 05/10] iio: light: gp2ap020a00f: Fix possible error swallow

From: Andy Shevchenko

Date: Mon Feb 23 2026 - 07:10:21 EST


On Sun, Feb 22, 2026 at 09:40:15PM -0600, Ethan Tidmore wrote:
> Move error check into for loop in gp2ap020a00f_buffer_postenable() and
> gp2ap020a00f_buffer_predisable(), this fixes a possible error swallow.

...

> - int i, err = 0;
> + int i, err;

I believe we can't do that without introducing a 'default' case.

> guard(mutex)(&data->lock);
>
> @@ -1366,11 +1366,10 @@ static int gp2ap020a00f_buffer_postenable(struct iio_dev *indio_dev)
> GP2AP020A00F_CMD_TRIGGER_PROX_EN);
> break;
> }
> + if (err)
> + return err;
> }
>
> - if (err < 0)
> - return err;

(Also you might want to mention dropping '< 0' for making the style consistent
taking into account that those functions won't return any positive values.)

> data->buffer = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
> if (!data->buffer)
> return -ENOMEM;
> @@ -1381,7 +1380,7 @@ static int gp2ap020a00f_buffer_postenable(struct iio_dev *indio_dev)
> static int gp2ap020a00f_buffer_predisable(struct iio_dev *indio_dev)
> {
> struct gp2ap020a00f_data *data = iio_priv(indio_dev);
> - int i, err = 0;
> + int i, err;

Ditto.

> guard(mutex)(&data->lock);
>
> @@ -1400,11 +1399,10 @@ static int gp2ap020a00f_buffer_predisable(struct iio_dev *indio_dev)
> GP2AP020A00F_CMD_TRIGGER_PROX_DIS);
> break;
> }
> + if (err)
> + return err;
> }
>
> - if (err)
> - return err;
> -
> kfree(data->buffer);
> return 0;
> }

--
With Best Regards,
Andy Shevchenko