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 v10 4/5] drm/bridge: trilinear: add the DPTX core and build glue
Date: Fri, 04 Dec 2026 12:15:57 +0000 [thread overview]
Message-ID: <sashiko-outbox-249774@kernel.org> (raw)
In-Reply-To: <20261204114332.280808-5-Luo.Liu@cixtech.com>
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [High] drm/bridge: trilinear: dptx_hw_link_vs_emph() returns byte
count as error
- [Medium] drm/bridge: trilinear: UAF on dp->dev calling
device_link_remove() unlocked
- [Medium] drm/bridge: trilinear: dptx_deinit() lets detach skip
aux_unregister()
- [Medium] drm/bridge: trilinear: UAF of dp->dev in
dptx_bridge_mode_set()
- [Medium] drm/bridge: trilinear: port@1 chaining breaks OOB HPD replay
and notify
- [Low] drm/bridge: trilinear: dptx_init() leaks IRQ_DISABLE_UNLAZY on
error
- [Low] drm/bridge: trilinear: redundant OF lookup and __free() style in
probe
--
commit 73b96bebc6d815be1eb22b178ab9b6dfb9d2585a
Author: Luo Liu <Luo.Liu@cixtech.com>
drm/bridge: trilinear: add the DPTX core and build glue
This commit adds the Trilinear DisplayPort transmitter core driver
(probe, PM callbacks, hotplug workers, and stream/link state machine),
exports trilinear_dptx_remove(), 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..5ca90acfb981f
> --- /dev/null
> +++ b/drivers/gpu/drm/bridge/trilinear/dptx_core.c
[ ... ]
> +static int dptx_train_loop(struct dptx_dev *dp)
> +{
[ ... ]
> + ret = dp->hw->ops->link_train(dp->hw, dp->phy,
> + mode->bw_code,
> + mode->lane_cnt);
> + if (!ret) {
> + if (dp->active_stream_cnt &&
> + (mode->bw_code != prev_bw ||
> + mode->lane_cnt != prev_lanes))
> + dptx_active_streams(dp);
> + return 0;
> + }
> +
> + if (ret != -EIO)
> + goto err_restore;
[Severity: High]
Will link training always fail here when the first DPCD write succeeds?
In drivers/gpu/drm/bridge/trilinear/dptx_hw.c, dptx_hw_link_vs_emph()
returns the result of drm_dp_dpcd_write() directly, which is the positive
byte count (lane_cnt) on success rather than 0:
drivers/gpu/drm/bridge/trilinear/dptx_hw.c:dptx_hw_link_vs_emph() {
...
return drm_dp_dpcd_write(&hw->aux, DP_TRAINING_LANE0_SET,
hw->train_setting, lane_cnt);
}
Both dptx_hw_link_clock_recovery() and dptx_hw_link_channel_equalization()
treat any non-zero return as an error (if (ret) return ret;), so positive
lane_cnt propagates back to dptx_train_loop(), hits the ret != -EIO branch,
and causes dptx_core_on() to power down the link on every enable.
Using drm_dp_dpcd_write_data() in dptx_hw_link_vs_emph() (or normalizing a
non-negative return to 0) would fix this.
[ ... ]
> +static int dptx_init(struct dptx_dev *dp)
> +{
[ ... ]
> + irq_set_status_flags(dp->irq, IRQ_DISABLE_UNLAZY);
> + ret = devm_request_threaded_irq(dp->dev, dp->irq, NULL,
> + dptx_irq_handler, IRQF_ONESHOT,
> + dev_name(dp->dev), dp);
> + if (ret < 0)
> + goto err_deinit;
> +
> + return 0;
> +
> +err_deinit:
> + dptx_host_deinit(dp);
> +err_configured:
> + dp->state &= ~DPTX_STATE_CONFIGURED;
> + return ret;
> +}
[Severity: Low]
Does the err_deinit path leave IRQ_DISABLE_UNLAZY set on dp->irq if
devm_request_threaded_irq() fails?
__free_irq() only clears IRQ_DISABLE_UNLAZY when freeing a registered
action, so a failed request leaks the flag on the IRQ descriptor. Setting
IRQ_DISABLE_UNLAZY after devm_request_threaded_irq() succeeds (or clearing
it on err_deinit) avoids that.
> +
> +static void dptx_deinit(struct dptx_dev *dp)
> +{
> + struct device *consumer = NULL;
> +
> + scoped_guard(mutex, &dp->lock) {
> + if (!(dp->state & DPTX_STATE_CONFIGURED))
> + return;
> +
> + WRITE_ONCE(dp->hpd_stopped, true);
> + dp->released = true;
> + dptx_irq_off(dp);
> + }
[Severity: Medium]
Can dptx_bridge_mode_set() hit a use-after-free on dp->dev if platform
removal runs between dp->ops->detect() and acquiring dp->lock?
Because dp->dev is not refcounted and the DL_FLAG_STATELESS device link
does not unbind the display controller when the DPTX device is removed,
trilinear_dptx_remove() can run concurrently with a modeset:
CPU0 CPU1
dptx_bridge_mode_set()
dp->ops->detect(dp)
mutex_lock(&dp->lock)
...
mutex_unlock(&dp->lock)
trilinear_dptx_remove()
dptx_deinit()
dp->released = true
device_del(dp->dev)
put_device(dp->dev) (freed)
mutex_lock(&dp->lock)
...
dev_dbg(dp->dev, ...) <-- use-after-free
dptx_bridge_mode_set() in dptx_drm.c does not recheck dp->released after
acquiring dp->lock before calling dev_dbg(dp->dev, ...). Rechecking
dp->released under dp->lock (or logging with drm_dbg_kms(dp->bridge.dev,
...)) avoids dereferencing a freed dp->dev.
> +
> + dptx_cancel_hpd_works(dp);
> +
> + scoped_guard(mutex, &dp->lock) {
> + dptx_stop_streams(dp);
> + dptx_host_deinit(dp);
> + dp->hw->ops->aux_unregister(dp->hw);
[Severity: Medium]
Can setting dp->released before dptx_cancel_hpd_works() cause
dptx_bridge_detach() to skip aux_unregister() and leave aux->drm_dev
dangling?
In dptx_drm.c, dptx_bridge_detach() only calls aux_unregister() when
!dp->released:
CPU0 CPU1
dptx_deinit()
mutex_lock(&dp->lock)
dp->released = true
mutex_unlock(&dp->lock)
dptx_cancel_hpd_works()
dptx_bridge_detach()
mutex_lock(&dp->lock)
/* dp->released is true: skips
aux_unregister() */
mutex_unlock(&dp->lock)
drm_dev_release(bridge->dev) (freed)
mutex_lock(&dp->lock)
dptx_host_deinit()
dptx_hw_dpcd_power_down()
drm_dp_dpcd_readb(&hw->aux) <-- use-after-free
aux_unregister(dp->hw)
While /dev/drm_dp_auxN and the I2C adapter stay registered, both
dptx_hw_dpcd_power_down() (via drm_dp_dump_access() -> drm_dbg_dp()) and
concurrent userspace AUX transfers can dereference the freed
struct drm_device. Since dptx_hw_aux_unregister() is idempotent,
dptx_bridge_detach() can unregister AUX unconditionally under dp->lock,
and dptx_deinit() should avoid DPCD transfers with a stale aux->drm_dev.
> + dp->state &= ~(DPTX_STATE_CONFIGURED);
> + consumer = dp->link_consumer;
> + dp->link_consumer = NULL;
> + }
> +
> + if (consumer)
> + device_link_remove(consumer, dp->dev);
> +}
[Severity: Medium]
Can calling device_link_remove() outside dp->lock race with platform device
removal and cause a use-after-free on dp->dev?
Both dptx_deinit() and dptx_bridge_detach() clear dp->link_consumer under
dp->lock and drop the lock before calling device_link_remove(). Because
the link is DL_FLAG_STATELESS, supplier removal does not unbind the
consumer first:
CPU0 CPU1
dptx_bridge_detach()
mutex_lock(&dp->lock)
consumer = dp->link_consumer
dp->link_consumer = NULL
mutex_unlock(&dp->lock)
trilinear_dptx_remove()
dptx_deinit()
/* sees link_consumer == NULL */
device_del(dp->dev)
put_device(dp->dev) (freed)
device_link_remove(consumer, dp->dev)
list_for_each_entry(..., &dp->dev->links.consumers, ...)
<-- use-after-free
Calling device_link_remove() while holding dp->lock in both
dptx_bridge_detach() and dptx_deinit() (matching device_link_add() in
dptx_bridge_attach()) serializes link removal against supplier teardown.
[ ... ]
> +struct dptx_dev *trilinear_dptx_probe(struct device *dev,
> + const struct dptx_plat_data *soc_data,
> + void *priv)
> +{
> + struct device_node *remote __free(device_node) = NULL;
[Severity: Low]
This isn't a bug, but remote is declared with __free(device_node) = NULL at
the top of the function and assigned much later, whereas the cleanup API
convention is to initialize __free() variables at acquisition.
In addition, of_drm_get_bridge_by_endpoint() already calls
of_graph_get_remote_node() internally and returns ERR_PTR(-ENODEV) when no
remote endpoint is present, so calling of_drm_get_bridge_by_endpoint()
directly and ignoring -ENODEV drops both the redundant OF lookup and the
remote variable.
[ ... ]
> + remote = of_graph_get_remote_node(dev->of_node, 1, 0);
> + if (remote) {
> + dp->next_bridge = of_drm_get_bridge_by_endpoint(dev->of_node,
> + 1, 0);
> + if (IS_ERR(dp->next_bridge)) {
> + ret = PTR_ERR(dp->next_bridge);
> + dp->next_bridge = NULL;
> + dptx_deinit(dp);
> + return ERR_PTR(ret);
> + }
> + }
[Severity: Medium]
Does chaining a downstream bridge on port@1 break out-of-band HPD replay
and notifications on USB-C DisplayPort?
In upstream USB-C DP Alt Mode topologies, the chain ends at a
drm_aux_hpd_bridge (which sets DRM_BRIDGE_OP_HPD), and a dp-connector with
hpd-gpios also sets DRM_BRIDGE_OP_HPD. drm_bridge_connector_init() picks
the last bridge with DRM_BRIDGE_OP_HPD as bridge_connector->bridge_hpd, so
drm_bridge_connector_enable_hpd() never calls dptx_bridge_hpd_enable() on
&dp->bridge and dp->bridge.hpd_cb stays NULL.
As a result, boot-time dptx_replay_deferred_hotplug() never runs for an
already-plugged USB-C sink, and dptx_notify_hpd() becomes a silent no-op,
dropping notifications from delayed PHY DP-mode polling and system resume
in dptx_pm_complete(). Conversely, wiring port@1 directly to a USB-C combo
PHY that does not register a struct drm_bridge (as documented in
cix,sky1-dp.yaml) makes of_drm_get_bridge_by_endpoint() return
-EPROBE_DEFER indefinitely.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204114332.280808-1-Luo.Liu@cixtech.com?part=4
next prev parent reply other threads:[~2026-12-04 12:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 11:43 [PATCH v10 0/5] drm/bridge: trilinear: add the Sky1 DisplayPort transmitter Luo Liu
2026-12-04 11:43 ` [PATCH v10 1/5] dt-bindings: display: add CIX " Luo Liu
2026-12-04 11:43 ` [PATCH v10 2/5] drm/bridge: trilinear: add the DPTX hardware layer Luo Liu
2026-12-04 12:06 ` sashiko-bot
2026-12-04 11:43 ` [PATCH v10 3/5] drm/bridge: trilinear: add the DPTX DRM bridge Luo Liu
2026-12-04 12:16 ` sashiko-bot
2026-12-04 11:43 ` [PATCH v10 4/5] drm/bridge: trilinear: add the DPTX core and build glue Luo Liu
2026-12-04 12:15 ` sashiko-bot [this message]
2026-12-04 11:43 ` [PATCH v10 5/5] drm/cix: add the Sky1 DisplayPort platform glue Luo Liu
2026-12-04 12:01 ` sashiko-bot
2026-12-04 12:11 ` 回复: " Luo Liu
2026-12-04 12:11 ` 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-249774@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.