]> git.ipfire.org Git - thirdparty/linux.git/commit
iio: adc: ad4851: fix ad4858 chan pointer handling
authorAntoniu Miclaus <antoniu.miclaus@analog.com>
Fri, 9 May 2025 10:16:57 +0000 (13:16 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 11 May 2025 13:12:49 +0000 (14:12 +0100)
commit499a8cee812588905cc940837e69918c1649a19e
treefb60f3506d0261810e297b0f96e77e0f108ec52e
parente2f820014239df9360064079ae93f838ff3b7f8c
iio: adc: ad4851: fix ad4858 chan pointer handling

The pointer returned from ad4851_parse_channels_common() is incremented
internally as each channel is populated. In ad4858_parse_channels(),
the same pointer was further incremented while setting ext_scan_type
fields for each channel. This resulted in indio_dev->channels being set
to a pointer past the end of the allocated array, potentially causing
memory corruption or undefined behavior.

Fix this by iterating over the channels using an explicit index instead
of incrementing the pointer. This preserves the original base pointer
and ensures all channel metadata is set correctly.

Fixes: 6250803fe2ec ("iio: adc: ad4851: add ad485x driver")
Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Link: https://patch.msgid.link/20250509101657.6742-1-antoniu.miclaus@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/ad4851.c