SPI driver_override allows a device to bind to this driver without
matching either the OF or SPI device ID table. In that case,
spi_get_device_match_data() returns NULL.
sharp_memory_probe() immediately dereferences the returned display mode
to calculate the pitch and transmit buffer size, causing a NULL pointer
dereference.
Commit 572a00852635 ("iio: dac: ad5686: missing NULL check on match
data") fixed the same driver_override issue in another SPI driver.
Reject devices without match data before using the display mode.
Fixes: b8f9f21716fe ("drm/tiny: Add driver for Sharp Memory LCD")
Cc: [email protected]
Signed-off-by: Jiale Yao <[email protected]>
---
drivers/gpu/drm/tiny/sharp-memory.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/gpu/drm/tiny/sharp-memory.c
b/drivers/gpu/drm/tiny/sharp-memory.c
index 7efd7b567f3b..049e98f657f3 100644
--- a/drivers/gpu/drm/tiny/sharp-memory.c
+++ b/drivers/gpu/drm/tiny/sharp-memory.c
@@ -557,6 +557,8 @@ static int sharp_memory_probe(struct spi_device *spi)
drm->mode_config.funcs = &sharp_memory_mode_config_funcs;
smd->mode = spi_get_device_match_data(spi);
+ if (!smd->mode)
+ return -ENODATA;
smd->pitch = (SHARP_ADDR_PERIOD + smd->mode->hdisplay +
SHARP_DUMMY_PERIOD) / 8;
smd->tx_buffer_size = (SHARP_MODE_PERIOD +
--
2.34.1