mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] iio: adc: mcp3564: reject devices without match data
@ 2026-10-21 22:54 Arnav Kapoor
  2026-10-22 16:41 ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Arnav Kapoor @ 2026-10-21 22:54 UTC (permalink / raw)
  To: Marius Cristea, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko
  Cc: Arnav Kapoor, linux-iio, linux-kernel

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@gmail.com>
---
 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];

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-22 16:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-21 22:54 [PATCH] iio: adc: mcp3564: reject devices without match data Arnav Kapoor
2026-10-22 16:41 ` Andy Shevchenko
2026-10-22 16:44   ` Arnav Kapoor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®