Re: [PATCH v5 05/10] iio: light: gp2ap020a00f: Fix possible error swallow
From: Jonathan Cameron
Date: Mon Feb 23 2026 - 16:16:58 EST
On Mon, 23 Feb 2026 14:05:19 +0200
Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx> wrote:
> 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.
I agree. I'm a bit confused why LLVM at least isn't moaning about this.
Anyhow, I'm not sure why it defaulted to 0 previously...
diff --git a/drivers/iio/light/gp2ap020a00f.c b/drivers/iio/light/gp2ap020a00f.c
index d2156e133b75..64be9b8ca5e3 100644
--- a/drivers/iio/light/gp2ap020a00f.c
+++ b/drivers/iio/light/gp2ap020a00f.c
@@ -1365,6 +1365,9 @@ static int gp2ap020a00f_buffer_postenable(struct iio_dev *indio_dev)
err = gp2ap020a00f_exec_cmd(data,
GP2AP020A00F_CMD_TRIGGER_PROX_EN);
break;
+ default:
+ err = -EINVAL;
+ break;
}
if (err)
return err;
@@ -1398,6 +1401,9 @@ static int gp2ap020a00f_buffer_predisable(struct iio_dev *indio_dev)
err = gp2ap020a00f_exec_cmd(data,
GP2AP020A00F_CMD_TRIGGER_PROX_DIS);
break;
+ default:
+ err = -EINVAL;
+ break;
}
if (err)
return err;
Is the tweak I applied to resolve this.
Thanks,
Jonathan
>
> > 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;
> > }
>