From: Jiale Yao A device bound through driver_override need not match an entry in the driver tables. In that case spi_get_device_match_data() returns NULL, but mcp251xfd_probe() dereferences the result while copying the device type data. Reject devices without match data before continuing probe. Fixes: 9cdae370c4ec ("can: mcp251xfd: simplify with spi_get_device_match_data()") Signed-off-by: Jiale Yao Link: https://patch.msgid.link/20260925133716.2230252-1-yaojiale02@163.com Signed-off-by: Marc Kleine-Budde --- drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c index f441f2265299..8759bc05bd8f 100644 --- a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +++ b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c @@ -2213,6 +2213,7 @@ MODULE_DEVICE_TABLE(spi, mcp251xfd_id_table); static int mcp251xfd_probe(struct spi_device *spi) { + const struct mcp251xfd_devtype_data *devtype_data; struct net_device *ndev; struct mcp251xfd_priv *priv; struct gpio_desc *rx_int; @@ -2222,6 +2223,10 @@ static int mcp251xfd_probe(struct spi_device *spi) u32 freq = 0; int err; + devtype_data = spi_get_device_match_data(spi); + if (!devtype_data) + return -ENODATA; + if (!spi->irq) return dev_err_probe(&spi->dev, -ENXIO, "No IRQ specified (maybe node \"interrupts-extended\" in DT missing)!\n"); @@ -2307,7 +2312,7 @@ static int mcp251xfd_probe(struct spi_device *spi) priv->reg_vdd = reg_vdd; priv->reg_xceiver = reg_xceiver; priv->xstbyen = device_property_present(&spi->dev, "microchip,xstbyen"); - priv->devtype_data = *(struct mcp251xfd_devtype_data *)spi_get_device_match_data(spi); + priv->devtype_data = *devtype_data; /* Errata Reference: * mcp2517fd: DS80000792C 5., mcp2518fd: DS80000789E 4., -- 2.53.0