Skip to content

Commit 947eb6f

Browse files
guilhermeivojic23
authored andcommitted
iio: adc: xilinx-ams: fix out-of-bounds channel lookup in event handling
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. Fixes: d5c7062 ("iio: adc: Add Xilinx AMS driver") Signed-off-by: Guilherme Ivo Bozi <guilherme.bozi@usp.br> Reviewed-by: Salih Erim <salih.erim@amd.com> Tested-by: Salih Erim <salih.erim@amd.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent 8402b32 commit 947eb6f

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

drivers/iio/adc/xilinx-ams.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,9 @@ static const struct iio_chan_spec *ams_event_to_channel(struct iio_dev *dev,
871871
if (dev->channels[i].scan_index == scan_index)
872872
break;
873873

874+
if (i == dev->num_channels)
875+
return NULL;
876+
874877
return &dev->channels[i];
875878
}
876879

@@ -1012,6 +1015,8 @@ static void ams_handle_event(struct iio_dev *indio_dev, u32 event)
10121015
const struct iio_chan_spec *chan;
10131016

10141017
chan = ams_event_to_channel(indio_dev, event);
1018+
if (!chan)
1019+
return;
10151020

10161021
if (chan->type == IIO_TEMP) {
10171022
/*

0 commit comments

Comments
 (0)