Skip to contentSkip to conversation

drm/trigger5: Add MCT Trigger 5 USB display driver

PATCH Superseded Ho Jie Feng 3 participants 5 messages Sep 10 – Sep 14

Subsystems (2)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/trigger5: Add MCT Trigger 5 USB display driver

Add a DRM driver for MCT Trigger 5 USB display adapters. The driver implements modesetting and USB framebuffer updates, connector detection, and EDID retrieval.

The protocol is based on reverse-engineering work by Forest Crossman (cyrozap) at: https://github.com/cyrozap/mct-usb-display-adapter-re
and usb packet captures between the Windows driver and the device.

Only the HDMI path has been tested. VGA selection is inferred from the absence of USB audio interfaces.

Tested on JUA355. The list of USB device IDs are taken from the Windows driver INF.

---
 MAINTAINERS                                   |   7 +
 drivers/gpu/drm/Kconfig                       |   1 +
 drivers/gpu/drm/Makefile                      |   1 +
 drivers/gpu/drm/trigger5/Kconfig              |  14 +
 drivers/gpu/drm/trigger5/Makefile             |   4 +
 drivers/gpu/drm/trigger5/trigger5.h           | 121 +++
 drivers/gpu/drm/trigger5/trigger5_connector.c | 102 ++
 drivers/gpu/drm/trigger5/trigger5_drv.c       | 904 ++++++++++++++++++
 8 files changed, 1154 insertions(+)
 create mode 100644 drivers/gpu/drm/trigger5/Kconfig
 create mode 100644 drivers/gpu/drm/trigger5/Makefile
 create mode 100644 drivers/gpu/drm/trigger5/trigger5.h
 create mode 100644 drivers/gpu/drm/trigger5/trigger5_connector.c
 create mode 100644 drivers/gpu/drm/trigger5/trigger5_drv.c
MAINTAINERS +7 -0
index 5b5a4e4b35cf4..f40a6fb9c3c2e 100644
@@ -8250,6 +8250,13 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/display/panel/mantix,mlaf057we51-x.yaml
 F:	drivers/gpu/drm/panel/panel-mantix-mlaf057we51.c
 
+DRM DRIVER FOR MCT TRIGGER 5 USB DISPLAY ADAPTERS
+M:	Ho Jie Feng <[email protected]>
+L:	[email protected]
+S:	Maintained
+T:	git https://gitlab.freedesktop.org/drm/misc/kernel.git
+F:	drivers/gpu/drm/trigger5/
+
 DRM DRIVER FOR MGA G200 GRAPHICS CHIPS
 M:	Dave Airlie <[email protected]>
 R:	Thomas Zimmermann <[email protected]>
drivers/gpu/drm/Kconfig +1 -0
index 323422861e8f6..75b5f5f4e94d4 100644
@@ -350,6 +350,7 @@ source "drivers/gpu/drm/tegra/Kconfig"
 source "drivers/gpu/drm/tidss/Kconfig"
 source "drivers/gpu/drm/tilcdc/Kconfig"
 source "drivers/gpu/drm/tiny/Kconfig"
+source "drivers/gpu/drm/trigger5/Kconfig"
 source "drivers/gpu/drm/tve200/Kconfig"
 source "drivers/gpu/drm/tyr/Kconfig"
 source "drivers/gpu/drm/udl/Kconfig"
drivers/gpu/drm/Makefile +1 -0
index e635fcffd3790..85a2dbfa643d9 100644
@@ -238,6 +238,7 @@ obj-$(CONFIG_DRM_SPRD) += sprd/
 obj-$(CONFIG_DRM_LOONGSON) += loongson/
 obj-$(CONFIG_DRM_POWERVR) += imagination/
 obj-$(CONFIG_DRM_VERISILICON_DC) += verisilicon/
+obj-$(CONFIG_DRM_TRIGGER5) += trigger5/
 
 # Ensure drm headers are self-contained and pass kernel-doc
 hdrtest-files := \
drivers/gpu/drm/trigger5/Kconfig new file +14 -0
new file mode 100644
index 0000000000000..e489db641f3e1
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config DRM_TRIGGER5
+	tristate "MCT Trigger 5 USB display adapters"
+	depends on DRM && USB && MMU
+	select DRM_CLIENT_SELECTION
+	select DRM_GEM_SHMEM_HELPER
+	select DRM_KMS_HELPER
+	help
+	  DRM driver for USB display adapters based on the MCT Trigger 5
+	  chipset, including the StarTech USB32VGAES and USB32HDES and the
+	  j5create JUA310 and JUA350.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called trigger5.
drivers/gpu/drm/trigger5/Makefile new file +4 -0
new file mode 100644
index 0000000000000..03b146e2fe813
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+trigger5-y := trigger5_drv.o trigger5_connector.o
+obj-$(CONFIG_DRM_TRIGGER5) += trigger5.o
drivers/gpu/drm/trigger5/trigger5.h new file +121 -0

121 lines not on this page · raw message

drivers/gpu/drm/trigger5/trigger5_connector.c new file +102 -0

102 lines not on this page · raw message

drivers/gpu/drm/trigger5/trigger5_drv.c new file +904 -0

904 lines not on this page · raw message

base-commit: 3ab04dcce43cd4fdaed94f08f4e6289be4921ea4

Signature · 1 line
2.55.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Sleeping functions and blocking waits are called from atomic DRM callbacks (plane update, CRTC…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Sleeping functions and blocking waits are called from atomic DRM callbacks (plane update, CRTC enable/disable), violating KMS atomic context rules. --

commit d1b842a91c5fa632149bc045bac81f4636faed1b
Author: Ho Jie Feng <[email protected]> drm/trigger5: Add MCT Trigger 5 USB display driver

This commit adds a DRM driver for MCT Trigger 5 USB display adapters. It implements modesetting, USB framebuffer updates, connector detection, and EDID retrieval.

Quoted 3 lines
drivers/gpu/drm/trigger5/trigger5_drv.c new file +0 -0

[ ... ]

Quoted 3 lines
drivers/gpu/drm/trigger5/trigger5_drv.c new file +3 -0
+static void trigger5_crtc_atomic_enable(struct drm_crtc *crtc,
+					struct drm_atomic_commit *state)
+{

[ ... ]

drivers/gpu/drm/trigger5/trigger5_drv.c line 301

Quoted 4 lines
drivers/gpu/drm/trigger5/trigger5_drv.c new file +4 -0
+	if (!drm_dev_enter(crtc->dev, &idx))
+		return;
+
+	trigger5_stop_io(trigger5);

[Severity: High]
Can this cause a "scheduling while atomic" bug? The CRTC atomic enable callback runs in atomic context, but trigger5_stop_io() calls flush_workqueue() and cancel_delayed_work_sync(), both of which can sleep.

drivers/gpu/drm/trigger5/trigger5_drv.c line 309

Quoted 8 lines
drivers/gpu/drm/trigger5/trigger5_drv.c new file +8 -0
+
+	/* Sequence recovered from USB captures. */
+	ret = usb_control_msg_recv(udev, 0,
+				   TRIGGER5_REQUEST_FIRMWARE_RESET,
+				   USB_DIR_IN | USB_TYPE_VENDOR |
+					   USB_RECIP_DEVICE,
+				   0x0000, 0x0000, data, 1,
+				   USB_CTRL_GET_TIMEOUT, GFP_KERNEL);

[Severity: High]
Does this synchronous USB transfer sleep? usb_control_msg_recv() allocates with GFP_KERNEL and blocks for the transfer. Running this in the CRTC atomic enable path violates the non-blocking requirement of atomic context.

[ ... ]

Quoted 3 lines
drivers/gpu/drm/trigger5/trigger5_drv.c new file +3 -0
+static void trigger5_crtc_atomic_disable(struct drm_crtc *crtc,
+					 struct drm_atomic_commit *state)
+{

[ ... ]

drivers/gpu/drm/trigger5/trigger5_drv.c line 414

Quoted 8 lines
drivers/gpu/drm/trigger5/trigger5_drv.c new file +8 -0
+	trigger5_stop_io(trigger5);
+
+	ret = usb_control_msg_recv(udev, 0,
+				   TRIGGER5_REQUEST_FIRMWARE_RESET,
+				   USB_DIR_IN | USB_TYPE_VENDOR |
+					   USB_RECIP_DEVICE,
+				   0x0001, 0x0000, &data, 1,
+				   USB_CTRL_GET_TIMEOUT, GFP_KERNEL);

[Severity: High]
Similarly, could this cause a deadlock or crash? The CRTC atomic disable callback runs in atomic context, but this executes a blocking USB transfer and uses GFP_KERNEL allocations.

[ ... ]

Quoted 3 lines
drivers/gpu/drm/trigger5/trigger5_drv.c new file +3 -0
+static void trigger5_plane_atomic_update(struct drm_plane *plane,
+					 struct drm_atomic_commit *atomic_state)
+{

[ ... ]

drivers/gpu/drm/trigger5/trigger5_drv.c line 570

Quoted 7 lines
drivers/gpu/drm/trigger5/trigger5_drv.c new file +7 -0
+	/*
+	 * This should almost never wait because we have should have a
+	 * pending transfer ready to be de-queued above in case the transfer
+	 * hasn't finished, but do a bounded wait just in case it gets stuck
+	 */
+	if (!wait_for_completion_timeout(&current_transfer->frame_complete,
+					 msecs_to_jiffies(20)))

[Severity: High]
Is it safe to perform a blocking wait directly inside the plane's atomic update callback? Plane atomic updates run in atomic context and must not sleep.

[ ... ]

drivers/gpu/drm/trigger5/trigger5_drv.c line 585

Quoted 11 lines
drivers/gpu/drm/trigger5/trigger5_drv.c new file +11 -0
+	/* Resize buffer to the current resolution for lower memory footprint */
+	max_len = array3_size(drm_rect_width(&src_rect),
+			      drm_rect_height(&src_rect), 3);
+	max_len = size_add(max_len, sizeof(*header));
+
+	/*
+	 * Allocation failure leaves the old buffer available for smaller
+	 * partial updates.
+	 */
+	if (max_len != current_transfer->frame_alloc_len)
+		trigger5_resize_bulk_buffer(current_transfer, max_len);

[Severity: High]
Does this invoke memory allocations from an atomic context? trigger5_resize_bulk_buffer() calls vmalloc_32() and kmalloc_array() with GFP_KERNEL, which will sleep and lead to system instability in the atomic update path.

[ ... ]

drivers/gpu/drm/trigger5/trigger5_drv.c line 612

Quoted 4 lines
drivers/gpu/drm/trigger5/trigger5_drv.c new file +4 -0
+	iosys_map_set_vaddr(&data_map,
+			    current_transfer->frame_data + sizeof(*header));
+
+	ret = drm_gem_fb_begin_cpu_access(state->fb, DMA_FROM_DEVICE);

[Severity: High]
Can this attempt to take dma_resv locks and wait for fences in atomic context? Also, is this call redundant here since the DRM_GEM_SHADOW_PLANE_HELPER_FUNCS prepare_fb callback already maps it asynchronously?

Quoted 4 lines
drivers/gpu/drm/trigger5/trigger5_drv.c new file +4 -0
+	if (ret < 0) {
+		complete(&current_transfer->frame_complete);
+		goto exit_save_pending;
+	}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Ho Jie Feng
kernel test robot noticed the following build warnings:

Hi Ho,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 3ab04dcce43cd4fdaed94f08f4e6289be4921ea4]

url:    https://github.com/intel-lab-lkp/linux/commits/Ho-Jie-Feng/drm-trigger5-Add-MCT-Trigger-5-USB-display-driver/20260911-011705
base:   3ab04dcce43cd4fdaed94f08f4e6289be4921ea4
patch link:    https://lore.kernel.org/r/20260910171709.396071-1-hjf3108%40gmail.com
patch subject: [PATCH] drm/trigger5: Add MCT Trigger 5 USB display driver
config: sparc64-allmodconfig (https://download.01.org/0day-ci/archive/20260911/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260911/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/gpu/drm/trigger5/trigger5_drv.c:435:19: warning: result of comparison of constant 65536 with expression of type 'const u16' (aka 'const unsigned short') is always false [-Wtautological-constant-out-of-range-compare]
     435 |             mode->htotal > U16_MAX + 1)
         |             ~~~~~~~~~~~~ ^ ~~~~~~~~~~~
   drivers/gpu/drm/trigger5/trigger5_drv.c:440:19: warning: result of comparison of constant 65536 with expression of type 'const u16' (aka 'const unsigned short') is always false [-Wtautological-constant-out-of-range-compare]
     440 |             mode->vtotal > U16_MAX + 1)
         |             ~~~~~~~~~~~~ ^ ~~~~~~~~~~~

2 warnings generated.

vim +435 drivers/gpu/drm/trigger5/trigger5_drv.c

420
421 static enum drm_mode_status
422 trigger5_crtc_mode_valid(struct drm_crtc *crtc,
423 const struct drm_display_mode *mode)
424 {
425 struct trigger5_pll pll;
426 size_t frame_len, payload_len;
427 u64 err, ppm;
428
429 /*
430 * The protocol stores totals, sync pulses, and back porches minus one
431 * in 16-bit fields.
432 */
433 if (mode->hsync_end <= mode->hsync_start ||
434 mode->htotal <= mode->hsync_end ||

 > 435		    mode->htotal > U16_MAX + 1)

436 return MODE_H_ILLEGAL;
437
438 if (mode->vsync_end <= mode->vsync_start ||
439 mode->vtotal <= mode->vsync_end ||
440 mode->vtotal > U16_MAX + 1)
441 return MODE_V_ILLEGAL;
442
443 payload_len = array3_size(mode->hdisplay, mode->vdisplay, 3);
444 frame_len = size_add(payload_len, sizeof(struct trigger5_bulk_header));
445 if (frame_len > SZ_16M)
446 return MODE_MEM;
447
448 err = trigger5_calculate_pll(&pll, mode->clock);
449 ppm = div64_u64(err * 1000, mode->clock);
450 if (ppm > 10000)
451 return MODE_CLOCK_RANGE;
452
453 return MODE_OK;
454 }
455

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

#3 lore raw

PATCH v2 1/1 drm/trigger5: Add MCT Trigger 5 USB display driver

In reply to Ho Jie Feng

Add a DRM driver for MCT Trigger 5 USB display adapters. The driver implements modesetting and USB framebuffer updates, connector detection, and EDID retrieval.

The protocol is based on reverse-engineering work by Forest Crossman (cyrozap) at: https://github.com/cyrozap/mct-usb-display-adapter-re
and usb packet captures between the Windows driver and the device.

Only the HDMI path has been tested. VGA selection is inferred from the absence of USB audio interfaces.

Tested on JUA355. The list of USB device IDs are taken from the Windows driver INF.

---
Changes in v2:
- Move the buffer resizing to crtc_* functions so that we can report out of memory errors to userspace
- Change the PLL search function so that it is faster and doesn't produce checkpatch warnings
- Update drm functions: crtc reset becomes create_state
- Fix warnings reported by kernel test robot

sashiko review false positives in v1:
- atomic in these function names mean that the changes should go through through at once or not at all, nothing to do with atomic context. Furthermore other drivers also have similar patterns
- drm_gem_fb_begin_cpu_access is also required

 MAINTAINERS                                   |    7 +
 drivers/gpu/drm/Kconfig                       |    1 +
 drivers/gpu/drm/Makefile                      |    1 +
 drivers/gpu/drm/trigger5/Kconfig              |   14 +
 drivers/gpu/drm/trigger5/Makefile             |    4 +
 drivers/gpu/drm/trigger5/trigger5.h           |  141 +++
 drivers/gpu/drm/trigger5/trigger5_connector.c |  102 ++
 drivers/gpu/drm/trigger5/trigger5_drv.c       | 1010 +++++++++++++++++
 8 files changed, 1280 insertions(+)
 create mode 100644 drivers/gpu/drm/trigger5/Kconfig
 create mode 100644 drivers/gpu/drm/trigger5/Makefile
 create mode 100644 drivers/gpu/drm/trigger5/trigger5.h
 create mode 100644 drivers/gpu/drm/trigger5/trigger5_connector.c
 create mode 100644 drivers/gpu/drm/trigger5/trigger5_drv.c
MAINTAINERS +7 -0
index 5b5a4e4b35cf4..f40a6fb9c3c2e 100644
@@ -8250,6 +8250,13 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/display/panel/mantix,mlaf057we51-x.yaml
 F:	drivers/gpu/drm/panel/panel-mantix-mlaf057we51.c
 
+DRM DRIVER FOR MCT TRIGGER 5 USB DISPLAY ADAPTERS
+M:	Ho Jie Feng <[email protected]>
+L:	[email protected]
+S:	Maintained
+T:	git https://gitlab.freedesktop.org/drm/misc/kernel.git
+F:	drivers/gpu/drm/trigger5/
+
 DRM DRIVER FOR MGA G200 GRAPHICS CHIPS
 M:	Dave Airlie <[email protected]>
 R:	Thomas Zimmermann <[email protected]>
drivers/gpu/drm/Kconfig +1 -0
index 323422861e8f6..75b5f5f4e94d4 100644
@@ -350,6 +350,7 @@ source "drivers/gpu/drm/tegra/Kconfig"
 source "drivers/gpu/drm/tidss/Kconfig"
 source "drivers/gpu/drm/tilcdc/Kconfig"
 source "drivers/gpu/drm/tiny/Kconfig"
+source "drivers/gpu/drm/trigger5/Kconfig"
 source "drivers/gpu/drm/tve200/Kconfig"
 source "drivers/gpu/drm/tyr/Kconfig"
 source "drivers/gpu/drm/udl/Kconfig"
drivers/gpu/drm/Makefile +1 -0
index e635fcffd3790..85a2dbfa643d9 100644
@@ -238,6 +238,7 @@ obj-$(CONFIG_DRM_SPRD) += sprd/
 obj-$(CONFIG_DRM_LOONGSON) += loongson/
 obj-$(CONFIG_DRM_POWERVR) += imagination/
 obj-$(CONFIG_DRM_VERISILICON_DC) += verisilicon/
+obj-$(CONFIG_DRM_TRIGGER5) += trigger5/
 
 # Ensure drm headers are self-contained and pass kernel-doc
 hdrtest-files := \
drivers/gpu/drm/trigger5/Kconfig new file +14 -0
new file mode 100644
index 0000000000000..e489db641f3e1
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config DRM_TRIGGER5
+	tristate "MCT Trigger 5 USB display adapters"
+	depends on DRM && USB && MMU
+	select DRM_CLIENT_SELECTION
+	select DRM_GEM_SHMEM_HELPER
+	select DRM_KMS_HELPER
+	help
+	  DRM driver for USB display adapters based on the MCT Trigger 5
+	  chipset, including the StarTech USB32VGAES and USB32HDES and the
+	  j5create JUA310 and JUA350.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called trigger5.
drivers/gpu/drm/trigger5/Makefile new file +4 -0
new file mode 100644
index 0000000000000..03b146e2fe813
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+trigger5-y := trigger5_drv.o trigger5_connector.o
+obj-$(CONFIG_DRM_TRIGGER5) += trigger5.o
drivers/gpu/drm/trigger5/trigger5.h new file +141 -0

141 lines not on this page · raw message

drivers/gpu/drm/trigger5/trigger5_connector.c new file +102 -0

102 lines not on this page · raw message

drivers/gpu/drm/trigger5/trigger5_drv.c new file +1010 -0

1,010 lines not on this page · raw message

base-commit: 3e391b0b516b007dafcbbd8742886717ebaf8cf9

Signature · 1 line
2.55.0
#4 lore raw
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] Sleeping functions and blocking memory allocations are called within DRM atomic commit callbacks…

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Sleeping functions and blocking memory allocations are called within DRM atomic commit callbacks, which are strictly defined as atomic context paths by subsystem guidelines.
- [High] trigger5_crtc_create_state() returns ERR_PTR(-ENOMEM) instead of NULL on allocation failure, causing a crash in the DRM core.
- [High] Missing cache flush for the vmalloc DMA buffer before initiating USB transfer.
- [Medium] The USB bulk header's horizontal and vertical offsets are populated with raw framebuffer coordinates instead of screen coordinates.
--

commit e87cbb95a349285fc94e00546c2aa86f1ff4d509
Author: Ho Jie Feng <[email protected]>

drm/trigger5: Add MCT Trigger 5 USB display driver

Add a DRM driver for MCT Trigger 5 USB display adapters. The driver implements modesetting and USB framebuffer updates, connector detection, and EDID retrieval.

drivers/gpu/drm/trigger5/trigger5_drv.c static void trigger5_atomic_commit_tail(struct drm_atomic_commit *state) · line 252

Quoted 9 lines
drivers/gpu/drm/trigger5/trigger5_drv.c +0 -0
@@ -248,8 +248,9 @@ static void trigger5_atomic_commit_tail(struct drm_atomic_commit *state)
 
 	if (!drm_dev_enter(state->dev, &idx))
 		goto commit;
 
 	trigger5_stop_io(trigger5);

[Severity: High]
Is it safe to block in this atomic commit tail callback? The DRM subsystem guidelines explicitly designate drm_atomic_helper_commit_tail() as an atomic context path where sleeping or blocking operations (like flushing workqueues inside trigger5_stop_io()) are strictly forbidden, which could lead to deadlocks or kernel warnings.

[ ... ]

Quoted 11 lines
drivers/gpu/drm/trigger5/trigger5_drv.c +0 -0
@@ -282,10 +282,10 @@ static int trigger5_alloc_bulk_buffer(struct trigger5_transfer_buf *buf,
 
 	/* Large transfer buffer requires vmalloc and a scatterlist. */
 	data = vmalloc_32(len);
 	if (!data)
 		return -ENOMEM;
 
 	num_pages = DIV_ROUND_UP(len, PAGE_SIZE);
 	pages = kmalloc_array(num_pages, sizeof(struct page *), GFP_KERNEL);
 	if (!pages) {
 		ret = -ENOMEM;

drivers/gpu/drm/trigger5/trigger5_drv.c

Quoted 6 lines
drivers/gpu/drm/trigger5/trigger5_drv.c +0 -0
 		goto err_vfree;
 	}
 	for (i = 0, ptr = data; i < num_pages; i++, ptr += PAGE_SIZE)
 		pages[i] = vmalloc_to_page(ptr);
 	ret = sg_alloc_table_from_pages(&buf->sgt, pages,
 					num_pages, 0, len, GFP_KERNEL);

[Severity: High]
Since this DMA buffer is allocated with vmalloc_32() and mapped to an SG table, will the CPU cache for the vmalloc alias need to be explicitly flushed after writes?

[ ... ]

drivers/gpu/drm/trigger5/trigger5_drv.c static struct drm_crtc_state * · line 329

Quoted 7 lines
drivers/gpu/drm/trigger5/trigger5_drv.c +0 -0
@@ -324,10 +324,10 @@ static struct drm_crtc_state *
 trigger5_crtc_create_state(struct drm_crtc *crtc)
 {
 	struct trigger5_crtc_state *tstate = kzalloc_obj(*tstate);
 
 	if (!tstate)
 		return ERR_PTR(-ENOMEM);

[Severity: High]
Could this cause a crash in the DRM core? The DRM API contract requires atomic_create_state callbacks to return NULL on memory allocation failure. Returning ERR_PTR(-ENOMEM) creates a non-NULL pointer that could evade existing checks, leading to a dereference of the error pointer.

[ ... ]

drivers/gpu/drm/trigger5/trigger5_drv.c static void trigger5_crtc_atomic_enable(struct drm_crtc *crtc, · line 385

Quoted 10 lines
drivers/gpu/drm/trigger5/trigger5_drv.c +0 -0
@@ -377,10 +377,10 @@ static void trigger5_crtc_atomic_enable(struct drm_crtc *crtc,
 	trigger5_stop_io(trigger5);
 
 	/* Sequence recovered from USB captures. */
 	ret = usb_control_msg_recv(udev, 0,
 				   TRIGGER5_REQUEST_FIRMWARE_RESET,
 				   USB_DIR_IN | USB_TYPE_VENDOR |
 					   USB_RECIP_DEVICE,
 				   0x0000, 0x0000, data, 1,
 				   USB_CTRL_GET_TIMEOUT, GFP_KERNEL);

[Severity: High]
Could calling synchronous USB control message APIs with GFP_KERNEL here cause system instability? The CRTC atomic enable callback runs in an atomic context path where sleeping is strictly forbidden.

[ ... ]

drivers/gpu/drm/trigger5/trigger5_drv.c static void trigger5_crtc_atomic_disable(struct drm_crtc *crtc, · line 463

Quoted 9 lines
drivers/gpu/drm/trigger5/trigger5_drv.c +0 -0
@@ -456,10 +456,10 @@ static void trigger5_crtc_atomic_disable(struct drm_crtc *crtc,
 	trigger5_stop_io(trigger5);
 
 	ret = usb_control_msg_recv(udev, 0,
 				   TRIGGER5_REQUEST_FIRMWARE_RESET,
 				   USB_DIR_IN | USB_TYPE_VENDOR |
 					   USB_RECIP_DEVICE,
 				   0x0001, 0x0000, &data, 1,
 				   USB_CTRL_GET_TIMEOUT, GFP_KERNEL);

[Severity: High]
Could this sleep in atomic context? Similar to the enable callback, this disable callback runs in a path where sleeping is forbidden.

[ ... ]

drivers/gpu/drm/trigger5/trigger5_drv.c static void trigger5_plane_atomic_update(struct drm_plane *plane, · line 642

Quoted 9 lines
drivers/gpu/drm/trigger5/trigger5_drv.c +0 -0
@@ -635,10 +635,10 @@ static void trigger5_plane_atomic_update(struct drm_plane *plane,
 	/*
 	 * This should almost never wait because we have should have a
 	 * pending transfer ready to be de-queued above in case the transfer
 	 * hasn't finished, but do a bounded wait just in case it gets stuck
 	 */
 	if (!wait_for_completion_timeout(&current_transfer->frame_complete,
 					 msecs_to_jiffies(20)))
 		goto exit_save_pending;

[Severity: High]
Is it safe to wait on a completion here? wait_for_completion_timeout() can sleep, but plane atomic update callbacks run in an atomic context.

drivers/gpu/drm/trigger5/trigger5_drv.c

Quoted 11 lines
drivers/gpu/drm/trigger5/trigger5_drv.c +0 -0
 	current_transfer->transfer_rect = current_rect;
 
drivers/gpu/drm/trigger5/trigger5_drv.c +0 -0
 	current_transfer->frame_len = frame_len;
 	header = current_transfer->buf.data;
 	header->magic = 0xfb;
 	header->length = 0x14;
 	/* flags 0: uncompressed 24-bit RGB888. */
 	header->counter =
 		cpu_to_le16((trigger5->frame_counter++) & 0xfff);
 	header->horizontal_offset = cpu_to_le16(current_rect.x1);
 	header->vertical_offset = cpu_to_le16(current_rect.y1);

[Severity: Medium]
Does this correctly populate the USB bulk header coordinates?

If the display is panned (i.e. has a non-zero source offset via state->src_x or state->src_y), the hardware typically needs to receive screen coordinates rather than raw framebuffer coordinates. Since current_rect.x1 and current_rect.y1 are in the coordinate space of the framebuffer, could this result in visual corruption when panning?

drivers/gpu/drm/trigger5/trigger5_drv.c

Quoted 12 lines
drivers/gpu/drm/trigger5/trigger5_drv.c +0 -0
 	header->width = cpu_to_le16(width);
 	header->height = cpu_to_le16(height);
 	header->payload_length = cpu_to_le32((u32)payload_len);
 	header->flags = 0x1;
 	header->unknown1 = 0;
 	header->unknown2 = 0;
 	header->checksum = trigger5_bulk_header_checksum(header);
 
 	iosys_map_set_vaddr(&data_map,
 			    current_transfer->buf.data + sizeof(*header));
 
 	ret = drm_gem_fb_begin_cpu_access(state->fb, DMA_FROM_DEVICE);

[Severity: High]
Could drm_gem_fb_begin_cpu_access() sleep here? This is also called in the atomic context path.

drivers/gpu/drm/trigger5/trigger5_drv.c

Quoted 13 lines
drivers/gpu/drm/trigger5/trigger5_drv.c +0 -0
 	if (ret < 0) {
 		complete(&current_transfer->frame_complete);
 		goto exit_save_pending;
 	}
 
 	drm_fb_xrgb8888_to_rgb888(&data_map, NULL,
 				  &shadow_plane_state->data[0],
 				  state->fb, &current_rect,
 				  &shadow_plane_state->fmtcnv_state);
 
 	drm_gem_fb_end_cpu_access(state->fb, DMA_FROM_DEVICE);
 
 	queue_work(trigger5->transfer_wq, &current_transfer->transfer_work);

[Severity: High]
Does the vmap cache need to be flushed before queueing the transfer work?

The DMA API manages cache coherency for the direct physical map, but not the vmalloc alias used when the CPU writes the pixel data. Should flush_kernel_vmap_range() be called here to avoid silent data corruption on architectures with non-coherent DMA and virtually indexed caches?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1