Re: [PATCH 1/3] iio: adc: ti-ads1298: add bounds check to pga_settings index

From: Greg Kroah-Hartman

Date: Fri May 15 2026 - 11:15:18 EST


On Fri, May 15, 2026 at 03:39:13PM +0100, Jonathan Cameron wrote:
> On Thu, 14 May 2026 18:23:20 +0200
> Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> wrote:
>
> > From: Sam Daly <sam@xxxxxxxxxx>
> >
> > ads1298_pga_settings has 7 elements but ADS1298_MASK_CH_PGA can yield
> > values 0-7. If it yields a value >= 7, this causes an out-of-bounds
> > array access. Add a bounds check and return -EINVAL if the index
> > is out of range.
> >
> I'll add something about the other value be reserved whilst applying.
>
> Note that Sashiko has found a more involved similar case (I haven't
> checked it)
>
> https://sashiko.dev/#/patchset/2026051420-strudel-graves-f6cd%40gregkh
>
> Whilst ideally we should harden drivers against faulty values from
> hardware, sometimes (like that one) it gets rather involved to actually
> do! Hence I'm not suggesting we actually fix that one but if anyone
> does want to take a look - go ahead.

Right now, once a driver binds to a device, we "trust" the hardware
works properly. But "obvious issues" like this patch and the series are
good to have for some devices where the same pattern of fix has been
applied elsewhere in the tree.

thanks,

greg k-h