]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
spi: Add NULL check for spi_get_device_id() in spi_get_device_match_data()
authorguoqi0226 <guoqi0226@163.com>
Tue, 16 Jun 2026 10:30:18 +0000 (18:30 +0800)
committerMark Brown <broonie@kernel.org>
Tue, 16 Jun 2026 20:25:14 +0000 (21:25 +0100)
Prevent NULL pointer dereference when spi_get_device_id() returns NULL,
which can happen when using driver_override without matching SPI ID entry.

Signed-off-by: guoqi0226 <guoqi0226@163.com>
Link: https://patch.msgid.link/20260616103018.105612-3-guoqi0226@163.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi.c

index fe7e3b3b98fc897ee1e8e35dc1a98a8444d5e45c..ab37b50bbf79c5cd4382868e9a255be4d1df4ad2 100644 (file)
@@ -355,12 +355,16 @@ EXPORT_SYMBOL_GPL(spi_get_device_id);
 const void *spi_get_device_match_data(const struct spi_device *sdev)
 {
        const void *match;
+       const struct spi_device_id *id;
 
        match = device_get_match_data(&sdev->dev);
        if (match)
                return match;
 
-       return (const void *)spi_get_device_id(sdev)->driver_data;
+       id = spi_get_device_id(sdev);
+       if (!id)
+               return NULL;
+       return (const void *)id->driver_data;
 }
 EXPORT_SYMBOL_GPL(spi_get_device_match_data);