Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/bridge: trilinear: htotal and clock overflow in
  dptx_adjust_mode()
--

commit 121beb945da3bca1311595f6221c3e03dd980739
Author: Luo Liu <[email protected]>

drm/bridge: trilinear: add the DPTX DRM bridge

This commit adds the DRM bridge implementation for the Trilinear DisplayPort
transmitter, handling connector detection, EDID and downstream mode
enumeration, mode validation, and atomic modesetting callbacks.

> 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..7a081873560bf
> --- /dev/null
> +++ b/drivers/gpu/drm/bridge/trilinear/dptx_drm.c

[ ... ]

> +static void dptx_adjust_mode(const struct drm_display_mode *mode,
> +                          struct drm_display_mode *adjusted_mode)
> +{
> +     int diff = mode->htotal - mode->hsync_end;
> +
> +     if (diff < DPTX_MIN_H_BACKPORCH) {
> +             adjusted_mode->htotal = mode->htotal +
> +                                     DPTX_MIN_H_BACKPORCH - diff;
> +             adjusted_mode->clock =
> +                     div_u64(mul_u32_u32(mode->clock, adjusted_mode->htotal),
> +                             mode->htotal);
> +     }

[Severity: Medium]
Can adjusted_mode->htotal and adjusted_mode->clock overflow here when a
userspace mode has a horizontal backporch smaller than DPTX_MIN_H_BACKPORCH?

Because adjusted_mode->htotal is a u16 and adjusted_mode->clock is a signed
int, a custom mode with mode->hsync_end >= 65524 wraps adjusted_mode->htotal
to 0..11 and truncates adjusted_mode->clock to 0 (or overflows
adjusted_mode->clock past INT_MAX when mode->clock is near INT_MAX).

dptx_bridge_mode_valid() and dptx_bridge_atomic_check() only check the upper
bound of adjusted_mode->clock, so the wrapped value passes validation and
reaches dptx_bridge_atomic_enable(), where dptx_hw_stream_timing_set()
underflows mode->htotal - mode->hdisplay and divides by zero on mode->clock:

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);
    ...
}

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=3

Reply via email to