All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Luo Liu" <Luo.Liu@cixtech.com>, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v4 4/4] drm/bridge: tda998x: fix DRM_BRIDGE_ATTACH_NO_CONNECTOR support
Date: Mon, 30 Nov 2026 03:14:08 +0000	[thread overview]
Message-ID: <sashiko-outbox-240296@kernel.org> (raw)
In-Reply-To: <20261130025520.766762-4-Luo.Liu@cixtech.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] drm/bridge: tda998x: uninitialized hpd_mutex lock in
  tda998x_detect_work()
- [Medium] drm/bridge: tda998x: stale ELD and live state mutation in
  atomic_check()
- [Medium] drm/bridge: tda998x: audio race and DPMS stall in
  tda998x_bridge_enable()
--

commit 759cd5e7edd1580ad6795fbc82cc8be14e7f0776
Author: Luo Liu <Luo.Liu@cixtech.com>

drm/bridge: tda998x: fix DRM_BRIDGE_ATTACH_NO_CONNECTOR support

This commit fixes DRM_BRIDGE_ATTACH_NO_CONNECTOR support in the tda998x
bridge driver by retrieving connector display information and ELD from
atomic state and reporting hotplug events via drm_bridge_hpd_notify().

> diff --git a/drivers/gpu/drm/bridge/tda998x_drv.c b/drivers/gpu/drm/bridge/tda998x_drv.c
> index 0b966c9844e70..5a59302e09ec3 100644
> --- a/drivers/gpu/drm/bridge/tda998x_drv.c
> +++ b/drivers/gpu/drm/bridge/tda998x_drv.c

[ ... ]

> @@ -778,10 +788,11 @@ static void tda998x_detect_work(struct work_struct *work)
>  {
>  	struct tda998x_priv *priv =
>  		container_of(work, struct tda998x_priv, detect_work);
> -	struct drm_device *dev = priv->connector.dev;
>  
> -	if (dev)
> -		drm_kms_helper_hotplug_event(dev);
> +	if (priv->connector.dev)
> +		drm_kms_helper_hotplug_event(priv->connector.dev);
> +	else
> +		drm_bridge_hpd_notify(&priv->bridge, tda998x_conn_detect(priv));
>  }

[Severity: Medium]
Can tda998x_detect_work() call drm_bridge_hpd_notify() before
priv->bridge.hpd_mutex is initialized?

tda998x_probe() registers tda998x_irq_thread() and enables HPD interrupts
in REG_CEC_RXSHPDINTENA before calling drm_bridge_add(&priv->bridge),
which is where mutex_init(&bridge->hpd_mutex) runs.  During probe,
priv->connector.dev is NULL, so an HPD interrupt that schedules
priv->detect_work before drm_bridge_add() finishes (or before a later
probe error flushes detect_work at cancel_work) will lock an
uninitialized hpd_mutex:

CPU0                              CPU1 (kworker)
tda998x_probe()
  request_threaded_irq()
  cec_write(..., CEC_RXSHPDLEV_HPD)
  <HPD IRQ>
    tda998x_irq_thread()
      schedule_work(&priv->detect_work)
                                  tda998x_detect_work()
                                    drm_bridge_hpd_notify()
                                      mutex_lock(&bridge->hpd_mutex)
                                        <-- uninitialized mutex
  ...
  drm_bridge_add(&priv->bridge)
    mutex_init(&bridge->hpd_mutex)

[ ... ]

> @@ -1394,6 +1397,26 @@ static void tda998x_bridge_detach(struct drm_bridge *bridge)
>  		drm_connector_cleanup(&priv->connector);
>  }
>  
> +static int tda998x_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 tda998x_priv *priv = bridge_to_tda998x_priv(bridge);
> +	struct drm_connector *connector = conn_state->connector;
> +
> +	priv->rgb_quant_range_selectable =
> +		connector->display_info.rgb_quant_range_selectable;
> +
> +	mutex_lock(&connector->eld_mutex);
> +	mutex_lock(&priv->audio_mutex);
> +	memcpy(priv->eld, connector->eld, sizeof(priv->eld));
> +	mutex_unlock(&priv->audio_mutex);
> +	mutex_unlock(&connector->eld_mutex);
> +
> +	return 0;
> +}

[Severity: Medium]
Does populating priv->eld only in tda998x_bridge_atomic_check() leave
stale ELD data after the display is unplugged and disabled?

When an output is disabled (new_conn_state->crtc == NULL), mode_fixup()
in drm_atomic_helper.c skips drm_atomic_bridge_chain_check(), and neither
tda998x_bridge_disable() nor the HPD disconnect path clears priv->eld.
tda998x_audio_get_eld() will continue returning the previous sink's ELD
to hdmi_codec_startup(), which checks hcp->eld[0] to decide whether a
sink is present, while also returning an empty or outdated ELD after hotplug
EDID probing until a modeset runs.

In addition, writing priv->rgb_quant_range_selectable and priv->eld here
mutates live driver state during DRM_MODE_ATOMIC_TEST_ONLY or failing
checks, and taking priv->audio_mutex stalls atomic_check behind the 20 ms
msleep() in tda998x_configure_audio().

> @@ -1411,9 +1434,59 @@ static enum drm_mode_status tda998x_bridge_mode_valid(struct drm_bridge *bridge,
>  }
>  
>  static void tda998x_bridge_enable(struct drm_bridge *bridge,
> -				  struct drm_atomic_commit *commit)
> +				  struct drm_atomic_commit *state)
>  {
>  	struct tda998x_priv *priv = bridge_to_tda998x_priv(bridge);
> +	struct drm_connector *connector;
> +	struct drm_connector_state *conn_state;
> +	struct drm_crtc_state *crtc_state;
> +	const struct drm_display_mode *adjusted_mode;
> +	u8 reg;
> +
> +	connector = drm_atomic_get_new_connector_for_encoder(state,
> +							     bridge->encoder);
> +	conn_state = drm_atomic_get_new_connector_state(state, connector);
> +
> +	mutex_lock(&priv->audio_mutex);
> +
> +	if (conn_state && conn_state->crtc) {
> +		crtc_state = drm_atomic_get_new_crtc_state(state, conn_state->crtc);
> +		adjusted_mode = &crtc_state->adjusted_mode;
> +
> +		/*
> +		 * CEA-861B section 6 says that:
> +		 * CEA version 1 (CEA-861) has no support for infoframes.
> +		 * CEA version 2 (CEA-861A) supports version 1 AVI infoframes,
> +		 * and optional basic audio.
> +		 * CEA version 3 (CEA-861B) supports version 1 and 2 AVI infoframes,
> +		 * and optional digital audio, with audio infoframes.
> +		 *
> +		 * Since we only support generation of version 2 AVI infoframes,
> +		 * ignore CEA version 2 and below (iow, behave as if we're a
> +		 * CEA-861 source.)
> +		 */
> +		priv->supports_infoframes = connector->display_info.cea_rev >= 3;
> +
> +		if (priv->supports_infoframes) {
> +			/* We need to turn HDMI HDCP stuff on to get audio through */
> +			reg = TBG_CNTRL_1_TGL_EN;
> +			if (crtc_state->mode.flags & DRM_MODE_FLAG_NHSYNC)
> +				reg |= TBG_CNTRL_1_H_TGL;
> +			if (crtc_state->mode.flags & DRM_MODE_FLAG_NVSYNC)
> +				reg |= TBG_CNTRL_1_V_TGL;
> +			reg_write(priv, REG_TBG_CNTRL_1, reg);
> +			reg_write(priv, REG_ENC_CNTRL, ENC_CNTRL_CTL_CODE(1));
> +			reg_set(priv, REG_TX33, TX33_HDMI);
> +
> +			tda998x_write_avi(priv, connector, adjusted_mode);
> +			tda998x_write_vsi(priv, connector, adjusted_mode);
> +
> +			if (priv->sink_has_audio)
> +				tda998x_configure_audio(priv);
> +		}
> +	}
> +
> +	mutex_unlock(&priv->audio_mutex);

[Severity: Medium]
Does moving the HDMI and audio setup from tda998x_bridge_mode_set() to
tda998x_bridge_enable() reintroduce the audio vs. modeset race that commit
2cae8e028ecb ("drm/i2c: tda998x: avoid race when programming audio")
fixed?

tda998x_bridge_mode_set() mutes the audio FIFO, disables HDMI mode, and
releases priv->audio_mutex while priv->supports_infoframes is still true
from the previous mode.  Before tda998x_bridge_enable() runs, a
concurrent tda998x_audio_hw_params() or tda998x_audio_mute_stream() can
acquire priv->audio_mutex, observe priv->supports_infoframes == true, and
unmute the audio FIFO or write audio infoframes while HDMI mode is still
off:

CPU0 (modeset)                    CPU1 (ALSA audio)
tda998x_bridge_mode_set()
  mutex_lock(&priv->audio_mutex)
  reg_set(..., AIP_CNTRL_0_RST_FIFO)
  reg_clear(..., TX33_HDMI)
  mutex_unlock(&priv->audio_mutex)
                                  tda998x_audio_mute_stream()
                                    mutex_lock(&priv->audio_mutex)
                                    if (priv->supports_infoframes)
                                      tda998x_audio_mute(priv, false)
                                        <-- unmutes FIFO before HDMI on
                                    mutex_unlock(&priv->audio_mutex)
tda998x_bridge_enable()
  mutex_lock(&priv->audio_mutex)
  reg_set(..., TX33_HDMI)

Also, because tda998x_bridge_enable() runs on every DPMS ON transition
even when tda998x_bridge_disable() only disabled the video ports, every
DPMS ON with active audio will now re-run tda998x_configure_audio(),
soft-resetting the audio block and sleeping for 20 ms.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130025520.766762-1-Luo.Liu@cixtech.com?part=4

  reply	other threads:[~2026-11-30  3:14 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  2:55 [PATCH v4 1/4] drm/komeda: Use the bridge connector Luo Liu
2026-11-30  2:55 ` [PATCH v4 2/4] drm/komeda: Use drmm_mode_config_init() Luo Liu
2026-11-30 13:25   ` Liviu Dudau
2026-11-30  2:55 ` [PATCH v4 3/4] drm/komeda: Free the IRQ before clearing dev_private Luo Liu
2026-11-30 13:27   ` Liviu Dudau
2026-11-30 17:38   ` Luca Ceresoli
2026-12-01  2:47     ` 回复: " Luo Liu
2026-12-01  2:47       ` Luo Liu
2026-11-30  2:55 ` [PATCH v4 4/4] drm/bridge: tda998x: fix DRM_BRIDGE_ATTACH_NO_CONNECTOR support Luo Liu
2026-11-30  3:14   ` sashiko-bot [this message]
2026-11-30 14:32   ` Liviu Dudau
2026-11-30  9:53 ` [PATCH v4 1/4] drm/komeda: Use the bridge connector Kory Maincent
2026-11-30 11:45   ` 回复: " Luo Liu
2026-11-30 11:45     ` Luo Liu
2026-11-30 13:23 ` Liviu Dudau

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-240296@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Luo.Liu@cixtech.com \
    --cc=dri-devel@lists.freedesktop.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.