* [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
* Re: [PATCH] iio: adc: mcp3564: reject devices without match data
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
0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2026-10-22 16:41 UTC (permalink / raw)
To: Arnav Kapoor
Cc: Marius Cristea, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, linux-iio, linux-kernel
On Thu, Oct 22, 2026 at 04:24:28AM +0530, Arnav Kapoor wrote:
> 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.
Fine, but I hope we will have something to land to actually do it differently
for the drivers that don't want to use driver_override mechanism.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Please, shrink the commit message to the point.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: adc: mcp3564: reject devices without match data
2026-10-22 16:41 ` Andy Shevchenko
@ 2026-10-22 16:44 ` Arnav Kapoor
0 siblings, 0 replies; 3+ messages in thread
From: Arnav Kapoor @ 2026-10-22 16:44 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Marius Cristea, Jonathan Cameron, David Lechner, Nuno Sa,
Andy Shevchenko, linux-iio, linux-kernel
On Thu, Oct 22, 2026 at 07:41:58PM +0300, Andy Shevchenko wrote:
> Fine, but I hope we will have something to land to actually do it differently
> for the drivers that don't want to use driver_override mechanism.
Agreed, a check in every driver is only a stopgap.
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> Please, shrink the commit message to the point.
Thanks for the review! I'll send a v2 with a shorter commit message and
your tag.
Arnav
^ 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®