Thank you for your contribution! Sashiko AI review found 7 potential issues to consider: - [High] drm/bridge: trilinear: dptx_bridge_attach() omits downstream bridge chaining - [Medium] drm/bridge: unquantized bpc and missing zero info->bpc cap in dptx_cal_bpc() - [Medium] drm/bridge: UAF of dp->dev in dptx_bridge_atomic_enable() error paths - [Medium] drm/bridge: trilinear: UAF calling device_link_del() after consumer removal - [Medium] drm/bridge: trilinear: dptx_bridge_atomic_check() validates link on DPMS off - [Low] drm/bridge: unreachable RGB bpc fallback in dptx_pick_format_bpc() - [Low] drm/bridge: 32-bit overflow in dptx_hw_stream_timing_set() from valid modes --
commit a2fe608ed44e66c7e1c705abc9a47feab7f0a6e0 Author: Luo Liu <[email protected]> drm/bridge: trilinear: add the DPTX DRM bridge This commit adds the DRM bridge layer for the Trilinear DisplayPort transmitter, covering detection, EDID and downstream mode enumeration, mode validation, format and bpc selection, atomic enable and disable, and device-link management on attach and detach. > diff --git a/drivers/gpu/drm/bridge/trilinear/dptx_drm.c > b/drivers/gpu/drm/bridge/trilinear/dptx_drm.c > new file mode 100644 > index 0000000000000..55e8caef39a2d > --- /dev/null > +++ b/drivers/gpu/drm/bridge/trilinear/dptx_drm.c [ ... ] > +static int dptx_cal_bpc(struct drm_connector_state *connector_state, > + int format, int bpc) > +{ > + struct drm_display_info *info = > + &connector_state->connector->display_info; > + > + if (dptx_bt2020_colorspace(connector_state)) > + bpc = min(bpc, 10); > + > + if (info->bpc) > + bpc = min_t(int, bpc, info->bpc); > + > + if (connector_state->max_requested_bpc) > + bpc = min(bpc, connector_state->max_requested_bpc); > + > + if (bpc < 6) > + return -EINVAL; > + > + if (bpc < 8 && format != DRM_OUTPUT_COLOR_FORMAT_RGB444) > + return -EINVAL; > + > + return bpc; > +} [Severity: Medium] Can dptx_cal_bpc() return an odd bpc value that the hardware register programming silently maps to 8 bpc? max_requested_bpc comes from a continuous range property, so userspace can request values such as 7 or 9. dptx_cal_bpp() computes the transfer unit and user data count from that unquantized bpp, while dptx_hw_stream_misc() and dptx_hw_stream_format_set() in dptx_hw.c only encode discrete DP depths (6, 8, 10, 12, 16) and fall through to 8 bpc for anything else, corrupting stream framing and exceeding a 7-bpc cap. Separately, when a sink leaves info->bpc as 0 (treated as 8 bpc elsewhere in the driver), skipping the info->bpc cap lets 10-bpc YCbCr 4:2:2 or BT.2020 RGB exceed the sink's default 8-bpc depth. Clamping against info->bpc ? info->bpc : 8 and rounding bpc down to the nearest discrete DP depth would prevent both mismatches. [ ... ] > + if (suggest_bpc > 10 && > + !compute_available_clock_rate(dp, conn_state, 10, > + adjusted_mode->clock, > + format, bpc, bpp)) { > + if (color_format) > + *color_format = format; > + return 0; > + } > + > + if (!compute_available_clock_rate(dp, conn_state, > + suggest_bpc, > + adjusted_mode->clock, > + format, bpc, bpp)) { [Severity: Low] Does trying 10 bpc before suggest_bpc make 12-bpc RGB unreachable? When a sink advertises more than 10 bpc, the first check succeeds and returns early at 10 bpc if link bandwidth allows; if 10 bpc does not fit, the higher suggest_bpc requires more bandwidth and can never succeed either. [ ... ] > +static int dptx_bridge_atomic_check(struct drm_bridge *bridge, > + struct drm_bridge_state *bridge_state, > + struct drm_crtc_state *crtc_state, > + struct drm_connector_state *conn_state) > +{ > + struct dptx_dev *dp = bridge_to_dp(bridge); > + int bpc; > + int bpp; > + int ret; > + bool vsc_supported; > + > + if (!conn_state->crtc) > + return 0; > + > + if (!dptx_adjust_mode(&crtc_state->mode, &crtc_state->adjusted_mode)) > + return -EINVAL; [Severity: Low] Can a custom userspace mode accepted here overflow 32-bit arithmetic when programming the secondary data window? Neither dptx_bridge_mode_valid() nor dptx_bridge_atomic_check() caps htotal - hdisplay below U16_MAX, so a custom mode with large horizontal blanking (over 35349 pixels at HBR2 or 23566 at HBR3) wraps modulo 2^32 in dptx_hw_stream_timing_set(): drivers/gpu/drm/bridge/trilinear/dptx_hw.c:dptx_hw_stream_timing_set() { ... dptx_hw_write(hw, DPTX_SECONDARY_DATA_WINDOW(stream_id), (mode->htotal - mode->hdisplay) * (link_rate / 40) * 9 / mode->clock); ... } Because link_rate is u32, the numerator overflows before division by mode->clock and writes a corrupted secondary data window. Using 64-bit arithmetic with mul_u32_u32() and div_u64() would avoid the wraparound. > + scoped_guard(mutex, &dp->lock) { > + ret = dptx_pick_config(dp, conn_state, &crtc_state->mode, > + &crtc_state->adjusted_mode, > + NULL, &bpc, &bpp); > + vsc_supported = dp->hw->ops->vsc_supported(dp->hw); > + } > + if (ret) > + return ret; [Severity: Medium] Can dptx_bridge_atomic_check() reject a DPMS off commit after hot-swapping to a lower-bandwidth sink? When an active high-bandwidth sink (such as 4-lane HBR2 at 4K@60Hz) is swapped for a lower-bandwidth sink, the HPD worker updates dp->link_max_lanes and dp->link_max_rate immediately. A subsequent DPMS off commit sets crtc_state->active to false while leaving conn_state->crtc non-NULL and mode_changed and connectors_changed false. In drm_atomic_helper_check_modeset(), mode_valid() skips the connector in that case, but mode_fixup() still calls drm_atomic_bridge_chain_check(). Unconditionally running dptx_pick_config() against the new sink's lower limits then returns -EINVAL and prevents userspace from turning the output off. Skipping link validation when !crtc_state->active (or when !crtc_state->mode_changed && !crtc_state->connectors_changed) would avoid this. [ ... ] > + ret = dp->ops->prepare(dp); > + if (ret) { > + if (ret != -ENODEV) > + dev_err(dp->dev, "failed to prepare DP output: %d\n", > + ret); > + return; > + } > + > + ret = dptx_bridge_mode_set(dp, crtc_state, conn_state); > + if (ret) { > + dev_err(dp->dev, "failed to set DP mode: %d\n", ret); > + goto err_unprepare; > + } > + > + ret = dp->ops->encoder_enable(dp, 0, true); > + if (ret) { > + dev_err(dp->dev, "failed to enable DP output: %d\n", ret); > + goto err_unprepare; > + } [Severity: Medium] Can these dev_err(dp->dev, ...) calls hit a use-after-free if the transmitter platform device is removed concurrently? struct dptx_dev can outlive its backing platform device while the refcounted drm_bridge remains attached, and neither __devm_drm_bridge_alloc() nor probe takes a get_device(dp->dev) reference. Because dp->lock is not held across prepare(), dptx_bridge_mode_set(), and encoder_enable(), platform device removal can finish in between: CPU0 CPU1 dptx_bridge_atomic_enable() dp->ops->prepare(dp) -> 0 device_del(dp->dev) ... -> dptx_deinit() dp->released = true put_device(dp->dev) (freed) dptx_bridge_mode_set() -> -ENODEV dev_err(dp->dev, ...) <-- use-after-free The same race applies to the encoder_enable() error path and to the prepare() error path after a non--ENODEV failure. Logging with drm_err(bridge->dev, ...) or holding a get_device(dp->dev) reference until dptx_bridge_destroy() would prevent this. [ ... ] > +static int dptx_bridge_attach(struct drm_bridge *bridge, > + struct drm_encoder *encoder, > + enum drm_bridge_attach_flags flags) > +{ > + struct dptx_dev *dp = bridge_to_dp(bridge); > + int ret; > + > + if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)) > + return -EINVAL; > + > + scoped_guard(mutex, &dp->lock) { > + if (dp->released) { > + ret = -ENODEV; > + } else { > + ret = dp->hw->ops->aux_register(dp->hw, bridge->dev); > + if (!ret) { > + dp->link = device_link_add(bridge->dev->dev, > + dp->dev, > + DL_FLAG_STATELESS); > + if (dp->link) { > + WRITE_ONCE(dp->hpd_stopped, false); > + dp->attached = true; > + } else { > + dp->hw->ops->aux_unregister(dp->hw); > + ret = -EINVAL; > + } > + } > + } > + } > + if (ret) > + return ret; > + > + /* The bridge may have been attached long after the sink was plugged. */ > + dp->ops->replay_deferred_hotplug(dp); > + > + return 0; > +} [Severity: High] Does omitting downstream bridge chaining in dptx_bridge_attach() break out-of-band USB-C HPD delivery? dptx_hpd_notify() relies on external drm_bridge_connector_hpd_notify() calls when dp->oob_hpd is set. Because neither probe nor dptx_bridge_attach() acquires and chains a downstream bridge from port@1, dp->bridge stays the last bridge in encoder->bridge_chain. drm_bridge_connector_init() then sets connector->fwnode to the DP controller's of_node rather than the usb-c-connector node, so drm_connector_oob_hotplug_event() from typec_displayport fails to match in drm_connector_find_by_fwnode() and silently drops every USB-C hotplug event. Any downstream bridge or panel wired to port@1 as described in the DT binding also cannot be attached. > +static void dptx_bridge_detach(struct drm_bridge *bridge) > +{ > + struct dptx_dev *dp = bridge_to_dp(bridge); > + struct device_link *link; > + > + /* Stop workers before the connector goes away. */ > + dp->ops->quiesce_hpd(dp); > + > + scoped_guard(mutex, &dp->lock) { > + dp->attached = false; > + > + if (!dp->released) > + dp->hw->ops->aux_unregister(dp->hw); > + > + link = dp->link; > + dp->link = NULL; > + } > + > + if (link) > + device_link_del(link); > +} [Severity: Medium] Can calling device_link_del() on the cached dp->link pointer hit a use-after-free if the consumer display controller is removed while userspace holds the DRM device open? When a display controller defers drm_mode_config_cleanup() via drmm_mode_config_init() and userspace keeps /dev/dri/cardN open, device_del(bridge->dev->dev) runs device_links_purge() and frees all supplier links, including DL_FLAG_STATELESS ones, before the final drm_dev_put() invokes drm_encoder_cleanup() -> dptx_bridge_detach(). Passing the cached pointer to device_link_del() then dereferences freed memory and violates the drivers/base/core.c contract against calling device_link_del() after links are purged. Removing the link with device_link_remove(consumer, dp->dev) instead of caching a raw struct device_link pointer avoids dereferencing a purged link. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=3
