public inbox for drm-ai-reviews@public-inbox.freedesktop.org
 help / color / mirror / Atom feed
From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: drm/bridge: dw-hdmi-qp: Add high TMDS clock ratio and scrambling support
Date: Tue, 03 Mar 2026 12:42:55 +1000	[thread overview]
Message-ID: <review-patch3-20260303-dw-hdmi-qp-scramb-v4-3-317d3b8bd219@collabora.com> (raw)
In-Reply-To: <20260303-dw-hdmi-qp-scramb-v4-3-317d3b8bd219@collabora.com>

Patch Review

This is the core patch. It has important functionality but also a significant locking concern.

**Locking issue in `dw_hdmi_qp_reset_crtc`:** This function is called from `dw_hdmi_qp_bridge_detect` (the `detect_ctx` callback), which is invoked with `connection_mutex` already held via `ctx`. Inside, it calls:

```c
retry:
    ret = drm_bridge_helper_reset_crtc(&hdmi->bridge, ctx);
    if (ret == -EDEADLK) {
        drm_modeset_backoff(ctx);
        goto retry;
    }
```

`drm_bridge_helper_reset_crtc` acquires `connection_mutex` with `ctx` (returns 0 due to `-EALREADY` handling in `modeset_lock()` at `drm_modeset_lock.c:321`), but then **unconditionally releases** it at the end:

```c
out:
    drm_modeset_unlock(&dev->mode_config.connection_mutex);
```

`drm_modeset_unlock` does `list_del_init(&lock->head)` + `ww_mutex_unlock(&lock->mutex)`, which fully releases the lock — even though the caller's framework (`drm_helper_probe_detect_ctx`) still expects it to be held. This is a locking protocol violation. After `drm_bridge_helper_reset_crtc` returns, `connection_mutex` is no longer held, creating a window where concurrent threads can modify connector state.

Additionally, calling `drm_modeset_backoff(ctx)` on a context that the function does not own is incorrect. `drm_modeset_backoff` drops **all** locks held by `ctx`, not just the contended one. The EDEADLK should be propagated back to the framework's retry loop rather than handled internally. The correct approach would be:

```c
ret = drm_bridge_helper_reset_crtc(&hdmi->bridge, ctx);
if (ret)
    return ret;  /* Let caller handle EDEADLK and other errors */
```

This would also require `dw_hdmi_qp_bridge_detect` to propagate the error:
```c
if (status == connector_status_connected && hdmi->scramb_enabled) {
    ret = dw_hdmi_qp_reset_crtc(hdmi, connector, ctx);
    if (ret)
        return ret;
}
```

However, even with this fix, `drm_bridge_helper_reset_crtc` still unlocks `connection_mutex` at line 57 after the EALREADY re-lock. This seems like `drm_bridge_helper_reset_crtc` is designed to be called **without** `connection_mutex` already held. The detect_ctx callback may need to be restructured to release `connection_mutex` before calling reset, or `drm_bridge_helper_reset_crtc` needs a variant that doesn't manage `connection_mutex` itself.

**Scrambling work queue safety:** The `scramb_work` delayed work accesses `hdmi->curr_conn`:

```c
static void dw_hdmi_qp_scramb_work(struct work_struct *work)
{
    ...
    if (!drm_scdc_get_scrambling_status(hdmi->curr_conn))
        dw_hdmi_qp_set_scramb(hdmi);
}
```

The lifecycle looks correct — `cancel_delayed_work_sync` in `dw_hdmi_qp_disable_scramb` runs before `curr_conn` is set to NULL in `atomic_disable`. However, consider: if the sink disconnects and HPD triggers detect_ctx (which resets the CRTC, triggering atomic_disable), the `cancel_delayed_work_sync` could block on a work item that is in the middle of writing SCDC. This should be fine functionally but might cause a delay.

**`SCDC_MIN_SOURCE_VERSION` naming:** The constant is used as:
```c
drm_scdc_writeb(hdmi->bridge.ddc, SCDC_SOURCE_VERSION,
                min_t(u8, ver, SCDC_MIN_SOURCE_VERSION));
```
The name `MIN` is misleading — this is the **maximum** source version the driver supports. `SCDC_SOURCE_VERSION` or `SCDC_MAX_SOURCE_VERSION` would be clearer.

**`SCRAMB_POLL_DELAY_MS` change from 3000 to 5000:** Not explained in the commit message. What motivated this change? It increases the window during which scrambling could be desynchronized from the sink.

**Pre-existing `drm_edid` leak in `no_hpd` path** (not introduced by this patch but worth noting):
```c
if (hdmi->no_hpd) {
    drm_edid = drm_edid_read_ddc(connector, bridge->ddc);
    if (drm_edid)
        return connector_status_connected;  /* drm_edid leaked */
```

**Ignored return value:** `dw_hdmi_qp_bridge_detect` ignores the return value of `dw_hdmi_qp_reset_crtc`:
```c
if (status == connector_status_connected && hdmi->scramb_enabled)
    dw_hdmi_qp_reset_crtc(hdmi, connector, ctx);

return status;
```
If the reset fails, the function still reports connected status. Errors should either be propagated or explicitly documented as intentionally ignored.

---
Generated by Claude Code Patch Reviewer

  reply	other threads:[~2026-03-03  2:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-03  1:38 [PATCH v4 0/4] Add HDMI 2.0 support to DW HDMI QP TX Cristian Ciocaltea
2026-03-03  1:38 ` [PATCH v4 1/4] drm/bridge: Add ->detect_ctx hook and drm_bridge_detect_ctx() Cristian Ciocaltea
2026-03-03  2:42   ` Claude review: " Claude Code Review Bot
2026-03-03  1:38 ` [PATCH v4 2/4] drm/bridge-connector: Switch to using ->detect_ctx hook Cristian Ciocaltea
2026-03-03  2:42   ` Claude review: " Claude Code Review Bot
2026-03-03  1:38 ` [PATCH v4 3/4] drm/bridge: dw-hdmi-qp: Add high TMDS clock ratio and scrambling support Cristian Ciocaltea
2026-03-03  2:42   ` Claude Code Review Bot [this message]
2026-03-03  1:38 ` [PATCH v4 4/4] drm/rockchip: dw_hdmi_qp: Do not send HPD events for all connectors Cristian Ciocaltea
2026-03-03  2:42   ` Claude review: " Claude Code Review Bot
2026-03-03  2:42 ` Claude review: Add HDMI 2.0 support to DW HDMI QP TX Claude Code Review Bot
  -- strict thread matches above, loose matches on Subject: below --
2026-03-23 17:45 [PATCH RESEND v4 0/4] " Cristian Ciocaltea
2026-03-23 17:45 ` [PATCH RESEND v4 3/4] drm/bridge: dw-hdmi-qp: Add high TMDS clock ratio and scrambling support Cristian Ciocaltea
2026-03-24 21:36   ` Claude review: " Claude Code Review Bot

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=review-patch3-20260303-dw-hdmi-qp-scramb-v4-3-317d3b8bd219@collabora.com \
    --to=claude-review@example.com \
    --cc=dri-devel-reviews@example.com \
    /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