Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Luo Liu" <Luo.Liu@cixtech.com>
Cc: dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v6 4/5] drm/bridge: trilinear: add the DPTX core and build glue
Date: Fri, 27 Nov 2026 06:14:39 +0000	[thread overview]
Message-ID: <sashiko-outbox-236697@kernel.org> (raw)
In-Reply-To: <20261127055807.109667-5-Luo.Liu@cixtech.com>

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 <Luo.Liu@cixtech.com>

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/20261127055807.109667-1-Luo.Liu@cixtech.com?part=4

  reply	other threads:[~2026-11-27  6:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27  5:58 [PATCH v6 0/5] drm/bridge: trilinear: add the Sky1 DisplayPort transmitter Luo Liu
2026-11-27  5:58 ` [PATCH v6 1/5] dt-bindings: display: add CIX " Luo Liu
2026-11-27  6:10   ` sashiko-bot
2026-11-27  5:58 ` [PATCH v6 2/5] drm/bridge: trilinear: add the DPTX hardware layer Luo Liu
2026-11-27  5:58 ` [PATCH v6 3/5] drm/bridge: trilinear: add the DPTX DRM bridge Luo Liu
2026-11-27  5:58 ` [PATCH v6 4/5] drm/bridge: trilinear: add the DPTX core and build glue Luo Liu
2026-11-27  6:14   ` sashiko-bot [this message]
2026-11-27  5:58 ` [PATCH v6 5/5] drm/cix: add the Sky1 DisplayPort platform glue Luo Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-236697@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Luo.Liu@cixtech.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox