iio: adc: tsc2046: fix memory corruption by preventing array overflow
authorOleksij Rempel <o.rempel@pengutronix.de>
Fri, 7 Jan 2022 08:14:01 +0000 (09:14 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 15 Jan 2022 18:24:10 +0000 (18:24 +0000)
commita1a31d0da52704f902f301efdbe8b806f3a6c473
treea8d55aa200c9881001526009814a82bd48d3c198
parent8f80931a3a4d6a9efd759a7edba9528489453a2d
iio: adc: tsc2046: fix memory corruption by preventing array overflow

On one side we have indio_dev->num_channels includes all physical channels +
timestamp channel. On other side we have an array allocated only for
physical channels. So, fix memory corruption by ARRAY_SIZE() instead of
num_channels variable.

Note the first case is a cleanup rather than a fix as the software
timestamp channel bit in active_scanmask is never set by the IIO core.

Fixes: 9374e8f5a38d ("iio: adc: add ADC driver for the TI TSC2046 controller")
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Link: https://lore.kernel.org/r/20220107081401.2816357-1-o.rempel@pengutronix.de
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/ti-tsc2046.c