[PATCH v2] iio: adc: mcp3564: reject devices without match data
From: Arnav Kapoor
Date: Fri Oct 23 2026 - 14:58:54 EST
When the chip can't be identified from its ID registers, the driver
falls back to spi_get_device_match_data() and dereferences the result
unconditionally. That returns NULL for a device bound through
driver_override whose name isn't in the id table, causing an oops.
Return -ENODATA in that case.
Fixes: 33ec3e5fc1ea ("iio: adc: adding support for MCP3564 ADC")
Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>
Signed-off-by: Arnav Kapoor <kapoorarnav43@xxxxxxxxx>
---
Changes in v2:
- Shorten the commit message (Andy)
- Add Fixes tag
- Collect Andy's Reviewed-by
- Rebase on fixes-togreg
v1: https://lore.kernel.org/all/20261021225431.627718-1-kapoorarnav43@xxxxxxxxx/
Compile-tested only (W=1); I don't have MCP3564 hardware.
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];
base-commit: 2ef6f5c4ee56e90c237c5f7687f09e635f7d30a9
--
2.53.0