Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH 1/3] drm/sitronix: st7920: Use DMA-safe serialized TX buffer for SPI writes
       [not found] <20261125222513.1446099-1-elkin@google.com>
@ 2026-11-25 22:25 ` Elkin Cruz
  2026-11-25 22:25 ` [PATCH 2/3] drm/sitronix: st7920: Check drm_dev_enter() in crtc atomic disable Elkin Cruz
  2026-11-25 22:25 ` [PATCH 3/3] drm/sitronix: st7920: Pass u8 row address when setting GDRAM address Elkin Cruz
  2 siblings, 0 replies; 3+ messages in thread
From: Elkin Cruz @ 2026-11-25 22:25 UTC (permalink / raw)
  To: Iker Pedrosa, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter
  Cc: dri-devel, linux-kernel, llvm, irogers, Elkin Cruz, stable

In st7920_spi_write(), u8 reg[CMD_SIZE] is allocated on the stack and
passed directly to spi_write(), violating SPI DMA safety requirements
when CONFIG_VMAP_STACK is enabled or an IOMMU is in use.

Embed an ARCH_DMA_MINALIGN-aligned TX buffer at the end of
struct st7920_device protected by a DRM-managed mutex, and pass
st7920 to st7920_spi_write().

Fixes: 88b09229f34a ("drm: Add driver for Sitronix ST7920 LCD displays")
Cc: stable@vger.kernel.org
Signed-off-by: Elkin Cruz <elkin@google.com>
---
 drivers/gpu/drm/sitronix/st7920.c | 43 +++++++++++++++++++++----------
 1 file changed, 30 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/sitronix/st7920.c b/drivers/gpu/drm/sitronix/st7920.c
index 616d83387d31..091e80d8bda5 100644
--- a/drivers/gpu/drm/sitronix/st7920.c
+++ b/drivers/gpu/drm/sitronix/st7920.c
@@ -7,9 +7,12 @@
  */
 
 #include <linux/bitrev.h>
+#include <linux/cache.h>
+#include <linux/cleanup.h>
 #include <linux/delay.h>
 #include <linux/gpio/consumer.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/regmap.h>
 #include <linux/spi/spi.h>
 
@@ -24,6 +27,7 @@
 #include <drm/drm_gem_atomic_helper.h>
 #include <drm/drm_gem_framebuffer_helper.h>
 #include <drm/drm_gem_shmem_helper.h>
+#include <drm/drm_managed.h>
 #include <drm/drm_plane.h>
 #include <drm/drm_print.h>
 #include <drm/drm_probe_helper.h>
@@ -86,6 +90,10 @@ struct st7920_device {
 
 	u32 height;
 	u32 width;
+
+	/* Serializes SPI command and GDRAM transfers using tx_buf */
+	struct mutex tx_lock;
+	u8 tx_buf[CMD_SIZE] __aligned(ARCH_DMA_MINALIGN);
 };
 
 struct st7920_plane_state {
@@ -165,16 +173,21 @@ static int st7920_store_others(int cmd, const void *data, u8 *reg)
 	return i;
 }
 
-static void st7920_spi_write(struct spi_device *spi, int cmd, const void *data,
-			     int delay_us, struct spi7920_error *err)
+static void st7920_spi_write(struct st7920_device *st7920, int cmd,
+			     const void *data, int delay_us,
+			     struct spi7920_error *err)
 {
-	u8 reg[CMD_SIZE] = {0};
+	u8 *reg = st7920->tx_buf;
 	int size = 0;
 	int ret;
 
 	if (err->errno)
 		return;
 
+	guard(mutex)(&st7920->tx_lock);
+
+	memset(reg, 0, CMD_SIZE);
+
 	/*
 	 * First the sync bits are sent: 11111WS0.
 	 * Where W is the read/write (RW) bit and S is the register/data (RS) bit.
@@ -190,7 +203,7 @@ static void st7920_spi_write(struct spi_device *spi, int cmd, const void *data,
 	else
 		size = st7920_store_others(cmd, data, reg);
 
-	ret = spi_write(spi, reg, size);
+	ret = spi_write(st7920->spi, reg, size);
 	if (ret) {
 		err->errno = ret;
 		return;
@@ -232,14 +245,14 @@ MODULE_DEVICE_TABLE(spi, st7920_spi_id);
 static void st7920_power_on(struct st7920_device *st7920,
 			    struct spi7920_error *err)
 {
-	st7920_spi_write(st7920->spi, SET_DISPLAY_ON, NULL, 72, err);
+	st7920_spi_write(st7920, SET_DISPLAY_ON, NULL, 72, err);
 }
 
 static void st7920_power_off(struct st7920_device *st7920,
 			     struct spi7920_error *err)
 {
-	st7920_spi_write(st7920->spi, SET_DISPLAY_CLEAR, NULL, 1600, err);
-	st7920_spi_write(st7920->spi, SET_DISPLAY_OFF, NULL, 72, err);
+	st7920_spi_write(st7920, SET_DISPLAY_CLEAR, NULL, 1600, err);
+	st7920_spi_write(st7920, SET_DISPLAY_OFF, NULL, 72, err);
 }
 
 static void st7920_hw_reset(struct st7920_device *st7920)
@@ -257,10 +270,10 @@ static int st7920_init(struct st7920_device *st7920)
 {
 	struct spi7920_error err = {0};
 
-	st7920_spi_write(st7920->spi, SET_BASIC_INSTRUCTION_SET, NULL, 72, &err);
+	st7920_spi_write(st7920, SET_BASIC_INSTRUCTION_SET, NULL, 72, &err);
 	st7920_power_on(st7920, &err);
-	st7920_spi_write(st7920->spi, SET_GRAPHICS_DISPLAY, NULL, 72, &err);
-	st7920_spi_write(st7920->spi, SET_DISPLAY_CLEAR, NULL, 1600, &err);
+	st7920_spi_write(st7920, SET_GRAPHICS_DISPLAY, NULL, 72, &err);
+	st7920_spi_write(st7920, SET_DISPLAY_CLEAR, NULL, 1600, &err);
 
 	return err.errno;
 }
@@ -296,8 +309,8 @@ static int st7920_update_rect(struct st7920_device *st7920,
 			data_array[array_idx++] = line_buffer[j];
 		}
 
-		st7920_spi_write(st7920->spi, SET_GDRAM_ADDRESS, &i, 72, &err);
-		st7920_spi_write(st7920->spi, SET_GDRAM_DATA, line_buffer, 72, &err);
+		st7920_spi_write(st7920, SET_GDRAM_ADDRESS, &i, 72, &err);
+		st7920_spi_write(st7920, SET_GDRAM_DATA, line_buffer, 72, &err);
 	}
 
 	return err.errno;
@@ -309,7 +322,7 @@ static void st7920_clear_screen(struct st7920_device *st7920, u8 *data_array)
 
 	memset(data_array, 0, BYTES_IN_DISPLAY);
 
-	st7920_spi_write(st7920->spi, SET_DISPLAY_CLEAR, NULL, 1600, &err);
+	st7920_spi_write(st7920, SET_DISPLAY_CLEAR, NULL, 1600, &err);
 }
 
 static int st7920_fb_blit_rect(struct drm_framebuffer *fb,
@@ -812,6 +825,10 @@ static int st7920_probe(struct spi_device *spi)
 	st7920->width = ST7920_DEFAULT_WIDTH;
 	st7920->height = ST7920_DEFAULT_HEIGHT;
 
+	ret = drmm_mutex_init(drm, &st7920->tx_lock);
+	if (ret)
+		return ret;
+
 	st7920->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
 	if (IS_ERR(st7920->reset_gpio)) {
 		ret = PTR_ERR(st7920->reset_gpio);
-- 
2.56.1.839.g22a8290db9-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/3] drm/sitronix: st7920: Check drm_dev_enter() in crtc atomic disable
       [not found] <20261125222513.1446099-1-elkin@google.com>
  2026-11-25 22:25 ` [PATCH 1/3] drm/sitronix: st7920: Use DMA-safe serialized TX buffer for SPI writes Elkin Cruz
@ 2026-11-25 22:25 ` Elkin Cruz
  2026-11-25 22:25 ` [PATCH 3/3] drm/sitronix: st7920: Pass u8 row address when setting GDRAM address Elkin Cruz
  2 siblings, 0 replies; 3+ messages in thread
From: Elkin Cruz @ 2026-11-25 22:25 UTC (permalink / raw)
  To: Iker Pedrosa, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter
  Cc: dri-devel, linux-kernel, llvm, irogers, Elkin Cruz, stable

st7920_crtc_atomic_disable() ignores the return value of
drm_dev_enter(), allowing SPI power-off writes to proceed after the DRM
device has been unplugged and unconditionally calling drm_dev_exit().

Return early when drm_dev_enter() returns false.

Fixes: 88b09229f34a ("drm: Add driver for Sitronix ST7920 LCD displays")
Cc: stable@vger.kernel.org
Signed-off-by: Elkin Cruz <elkin@google.com>
---
 drivers/gpu/drm/sitronix/st7920.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/sitronix/st7920.c b/drivers/gpu/drm/sitronix/st7920.c
index 091e80d8bda5..ea4566009c4b 100644
--- a/drivers/gpu/drm/sitronix/st7920.c
+++ b/drivers/gpu/drm/sitronix/st7920.c
@@ -580,7 +580,8 @@ static void st7920_crtc_atomic_disable(struct drm_crtc *crtc,
 	struct st7920_device *st7920 = drm_to_st7920(drm);
 	int idx;
 
-	drm_dev_enter(drm, &idx);
+	if (!drm_dev_enter(drm, &idx))
+		return;
 
 	st7920_power_off(st7920, &err);
 
-- 
2.56.1.839.g22a8290db9-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 3/3] drm/sitronix: st7920: Pass u8 row address when setting GDRAM address
       [not found] <20261125222513.1446099-1-elkin@google.com>
  2026-11-25 22:25 ` [PATCH 1/3] drm/sitronix: st7920: Use DMA-safe serialized TX buffer for SPI writes Elkin Cruz
  2026-11-25 22:25 ` [PATCH 2/3] drm/sitronix: st7920: Check drm_dev_enter() in crtc atomic disable Elkin Cruz
@ 2026-11-25 22:25 ` Elkin Cruz
  2 siblings, 0 replies; 3+ messages in thread
From: Elkin Cruz @ 2026-11-25 22:25 UTC (permalink / raw)
  To: Iker Pedrosa, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter
  Cc: dri-devel, linux-kernel, llvm, irogers, Elkin Cruz, stable

st7920_update_rect() passes &i (int *) as the data pointer for
SET_GDRAM_ADDRESS, whereas st7920_store_gdram_address() reads a single
u8 byte. On big-endian systems this reads the most significant byte (0)
instead of the row index.

Store the row index in a u8 variable and pass its address to
st7920_spi_write().

Fixes: 88b09229f34a ("drm: Add driver for Sitronix ST7920 LCD displays")
Cc: stable@vger.kernel.org
Signed-off-by: Elkin Cruz <elkin@google.com>
---
 drivers/gpu/drm/sitronix/st7920.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/sitronix/st7920.c b/drivers/gpu/drm/sitronix/st7920.c
index ea4566009c4b..005994a8f87f 100644
--- a/drivers/gpu/drm/sitronix/st7920.c
+++ b/drivers/gpu/drm/sitronix/st7920.c
@@ -309,7 +309,9 @@ static int st7920_update_rect(struct st7920_device *st7920,
 			data_array[array_idx++] = line_buffer[j];
 		}
 
-		st7920_spi_write(st7920, SET_GDRAM_ADDRESS, &i, 72, &err);
+		u8 y = i;
+
+		st7920_spi_write(st7920, SET_GDRAM_ADDRESS, &y, 72, &err);
 		st7920_spi_write(st7920, SET_GDRAM_DATA, line_buffer, 72, &err);
 	}
 
-- 
2.56.1.839.g22a8290db9-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-25 22:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261125222513.1446099-1-elkin@google.com>
2026-11-25 22:25 ` [PATCH 1/3] drm/sitronix: st7920: Use DMA-safe serialized TX buffer for SPI writes Elkin Cruz
2026-11-25 22:25 ` [PATCH 2/3] drm/sitronix: st7920: Check drm_dev_enter() in crtc atomic disable Elkin Cruz
2026-11-25 22:25 ` [PATCH 3/3] drm/sitronix: st7920: Pass u8 row address when setting GDRAM address Elkin Cruz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox