[PATCH 10/10] Input: goodix_berlin_spi - validate ic_data and SPI max transfer size
From: Lee Jones
Date: Fri Nov 27 2026 - 15:12:15 EST
goodix_berlin_spi_probe() dereferences ic_data without checking
spi_get_device_match_data() for NULL, and subtracts the SPI read and
write prefix lengths from spi_max_transfer_size() without checking that
max_size exceeds both prefix lengths. A controller reporting a small
maximum transfer size causes an unsigned size_t underflow (or zero
max_raw_read/write), bypassing regmap transfer chunking.
Return -EINVAL if ic_data is NULL or if max_size is not strictly greater
than both the read and write prefix lengths.
Fixes: 3aa182bbc5b6 ("Input: goodix-berlin - add SPI support for Goodix Berlin Touchscreen IC")
Fixes: 4d395cb071a3 ("Input: goodix_berlin - add support for Berlin-A series")
Closes: https://sashiko.dev/#/bug/linux-a8b8e506-08b4-44c4-bf67-3c8ef31c6da7
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/input/touchscreen/goodix_berlin_spi.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/input/touchscreen/goodix_berlin_spi.c b/drivers/input/touchscreen/goodix_berlin_spi.c
index 01f850f484c2..377c81a3e3c5 100644
--- a/drivers/input/touchscreen/goodix_berlin_spi.c
+++ b/drivers/input/touchscreen/goodix_berlin_spi.c
@@ -133,6 +133,9 @@ static int goodix_berlin_spi_probe(struct spi_device *spi)
size_t max_size;
int error = 0;
+ if (!ic_data)
+ return -EINVAL;
+
spi->mode = SPI_MODE_0;
spi->bits_per_word = 8;
error = spi_setup(spi);
@@ -140,6 +143,9 @@ static int goodix_berlin_spi_probe(struct spi_device *spi)
return error;
max_size = spi_max_transfer_size(spi);
+ if (max_size <= max_t(size_t, ic_data->read_prefix_len,
+ GOODIX_BERLIN_SPI_WRITE_PREFIX_LEN))
+ return -EINVAL;
regmap_config = goodix_berlin_spi_regmap_conf;
regmap_config.max_raw_read = max_size - ic_data->read_prefix_len;
--
2.56.1.839.g22a8290db9-goog