Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] drm/bridge: trilinear: wrong link rate units in dptx_mode_configure() downshift - [High] drm/bridge: trilinear: suspend race in dptx_prepare() and dptx_unprepare() --
commit b3d05377faa95646f17c1b45523d133f49a7ccb6 Author: Luo Liu <[email protected]> drm/bridge: trilinear: add the DPTX core and build glue This commit adds the Trilinear DPTX bridge core implementation, including probe, system sleep, hotplug handling, and link training, and hooks the driver into the DRM bridge Kconfig and Makefile. > diff --git a/drivers/gpu/drm/bridge/trilinear/dptx_core.c > b/drivers/gpu/drm/bridge/trilinear/dptx_core.c > new file mode 100644 > index 0000000000000..bfe339afe5873 > --- /dev/null > +++ b/drivers/gpu/drm/bridge/trilinear/dptx_core.c [ ... ] > +static int dptx_mode_configure(struct dptx_dev *dp, int pclk, u8 bw, u8 bpp, > + bool downshift) > +{ > + int lane_cnt; > + int bw_code; > + int link_rate; > + > + if (!downshift) { > + bw_code = bw; > + } else { > + link_rate = drm_dp_bw_code_to_link_rate(bw); > + if (link_rate > 5400) > + bw_code = DP_LINK_BW_5_4; > + else if (link_rate > 2700) > + bw_code = DP_LINK_BW_2_7; > + else if (link_rate > 1620) > + bw_code = DP_LINK_BW_1_62; > + else > + return -EINVAL; > + } [Severity: High] Does the downshift branch in dptx_mode_configure() compare link_rate against the wrong units? drm_dp_bw_code_to_link_rate() returns the rate in kHz (162000 to 810000), so link_rate > 5400 is always true for every valid bandwidth code. When link training fails in dptx_train_loop(), downshifting always selects DP_LINK_BW_5_4 instead of stepping down to 2.7 or 1.62 Gbps, never returns -EINVAL to terminate the inner loop, and can upshift a 1.62 or 2.7 Gbps link to 5.4 Gbps. [ ... ] > +static int dptx_pm_prepare(struct dptx_dev *dp, bool shutdown) > +{ > + scoped_guard(mutex, &dp->lock) { > + dptx_irq_off(dp); > + dp->state |= DPTX_STATE_SUSPENDED; > + if (shutdown) > + dp->state |= DPTX_STATE_SHUTDOWN; > + } > + > + dptx_cancel_hpd_works(dp); > + > + scoped_guard(mutex, &dp->lock) { > + if (!(dp->state & DPTX_STATE_SUSPENDED)) { > + dptx_irq_off(dp); > + dp->state |= DPTX_STATE_SUSPENDED; > + } > + > + if (shutdown) > + dptx_stop_streams(dp); > + if (!dp->active_stream_cnt) > + dptx_host_deinit(dp); > + dp->state &= ~DPTX_STATE_CONNECTED; > + } > + > + return 0; > +} [ ... ] > +static int dptx_prepare(struct dptx_dev *dp) > +{ > + int ret; > + > + guard(mutex)(&dp->lock); > + > + if (dp->released || (dp->state & DPTX_STATE_SHUTDOWN)) > + return -ENODEV; > + > + /* The controller's resume commit can precede dptx_pm_complete(). */ > + ret = dptx_host_resume(dp); > + if (ret) > + return ret; [ ... ] > +static int dptx_unprepare(struct dptx_dev *dp) > +{ > + if (dp->active_stream_cnt) > + return 0; > + > + if (!(dp->state & (DPTX_STATE_ENABLED | DPTX_STATE_READY))) > + return 0; > + > + dptx_core_off(dp); > + > + /* dptx_pm_prepare() may have run before this suspend-time commit. */ > + if (dp->state & DPTX_STATE_SUSPENDED) > + dptx_host_deinit(dp); > + > + dp->state &= ~DPTX_STATE_ENABLED; > + > + return 0; > +} [Severity: High] Can an atomic enable racing with trilinear_dptx_suspend() leave the host initialized and dp->irq enabled across system suspend? CPU0 CPU1 trilinear_dptx_suspend() dptx_pm_prepare(dp, false) lock(&dp->lock) dptx_irq_off(dp) dp->state |= DPTX_STATE_SUSPENDED unlock(&dp->lock) dptx_cancel_hpd_works(dp) lock(&dp->lock) dptx_host_deinit(dp) unlock(&dp->lock) dptx_bridge_atomic_enable() dptx_prepare(dp) dptx_host_resume(dp) dptx_host_init(dp) enable_irq(dp->irq) dp->state &= ~DPTX_STATE_SUSPENDED Because dptx_prepare() cannot tell a suspend-time commit apart from an early resume commit, calling dptx_host_resume() after dptx_pm_prepare() finishes clears DPTX_STATE_SUSPENDED and re-enables dp->irq; a later suspend-time dptx_unprepare() then sees DPTX_STATE_SUSPENDED cleared and skips dptx_host_deinit(). Even when dptx_pm_prepare() runs its second critical section after dptx_prepare() and reinstates DPTX_STATE_SUSPENDED, two issues remain. First, if dptx_bridge_atomic_enable() fails in dptx_bridge_mode_set() or dptx_core_on(), neither DPTX_STATE_ENABLED nor DPTX_STATE_READY is set when err_unprepare calls dptx_unprepare(), so dptx_unprepare() returns early before checking DPTX_STATE_SUSPENDED and leaves the host initialized. Second, while dptx_prepare() has dp->irq enabled during dptx_cancel_hpd_works(), an HPD interrupt can re-queue hpd_event_work or hpd_irq_work after dptx_cancel_hpd_works() returns, and if the racing dptx_bridge_atomic_enable() completes dptx_encoder_enable() before dptx_pm_prepare() re-locks dp->lock, dp->active_stream_cnt is non-zero and dptx_pm_prepare(dp, false) skips dptx_host_deinit(). -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=4
