[PATCH] drm/tiny: sharp-memory: reject devices without match data

From: Jiale Yao

Date: Fri Sep 25 2026 - 08:38:54 EST


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: stable@xxxxxxxxxxxxxxx
Signed-off-by: Jiale Yao <yaojiale02@xxxxxxx>
---
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