Re: [PATCH v2 1/3] iio: adc: xilinx-ams: fix out-of-bounds channel lookup in event handling

Andy Shevchenko
2026-04-14T18:37:21Z

On Tue, Apr 14, 2026 at 07:29:17AM -0300, Guilherme Ivo Bozi wrote:
> ams_event_to_channel() may return a pointer past the end of
> dev->channels when no matching scan_index is found. This can lead
> to invalid memory access in ams_handle_event().
>
> Add a bounds check in ams_event_to_channel() and return NULL when
> no channel is found. Also guard the caller to safely handle this
> case.

...

> + if (i >= dev->num_channels)

The '==' is clearer. Otherwise, please justify the '>' part.

> + return NULL;

...

TBH I do not see how this code is not a dead code. But for the sake of
robustness it might be added. I leave it up to the maintainer.

--
With Best Regards,
Andy Shevchenko