[PATCH] iio: adc: mcp3564: reject devices without match data

From: Arnav Kapoor

Date: Wed Oct 21 2026 - 18:54:54 EST


The driver identifies the chip by reading its ID registers. If that
fails, e.g. for a newer part number, it falls back to the match data
provided by the device tree.

spi_get_device_match_data() returns NULL when the device is bound with
the "spi: override" property, as in that case no match data is set and
the device name doesn't match any of the entries of the driver's id
table.

The driver dereferences the returned pointer without checking it, which
leads to a NULL pointer dereference and a kernel oops.

Return -ENODATA if no match data is available, like the other IIO SPI
drivers do.

Signed-off-by: Arnav Kapoor <kapoorarnav43@xxxxxxxxx>
---
drivers/iio/adc/mcp3564.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/iio/adc/mcp3564.c b/drivers/iio/adc/mcp3564.c
index 259ac4ebdedf..91796a47e412 100644
--- a/drivers/iio/adc/mcp3564.c
+++ b/drivers/iio/adc/mcp3564.c
@@ -1204,6 +1204,9 @@ static int mcp3564_config(struct iio_dev *indio_dev, bool *use_internal_vref_att
* try using fallback compatible in device tree to deal with some newer part number.
*/
adc->chip_info = spi_get_device_match_data(adc->spi);
+ if (!adc->chip_info)
+ return -ENODATA;
+
adc->have_vref = adc->chip_info->have_vref;
} else {
adc->chip_info = &mcp3564_chip_infos_tbl[ids];