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

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@intel.com>
Signed-off-by: Arnav Kapoor <kapoorarnav43@gmail.com>
---
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@gmail.com/

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


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

* Re: [PATCH v2] iio: adc: mcp3564: reject devices without match data
  2026-10-23 18:58 [PATCH v2] iio: adc: mcp3564: reject devices without match data Arnav Kapoor
@ 2026-10-24  1:58 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2026-10-24  1:58 UTC (permalink / raw)
  To: Arnav Kapoor
  Cc: Marius Cristea, David Lechner, Nuno Sá,
	Andy Shevchenko, Andy Shevchenko, linux-iio, linux-kernel

On Sat, 24 Oct 2026 00:28:34 +0530
Arnav Kapoor <kapoorarnav43@gmail.com> wrote:

> 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@intel.com>
> Signed-off-by: Arnav Kapoor <kapoorarnav43@gmail.com>
Applied

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


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

end of thread, other threads:[~2026-10-24  1:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-23 18:58 [PATCH v2] iio: adc: mcp3564: reject devices without match data Arnav Kapoor
2026-10-24  1:58 ` Jonathan Cameron

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®