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 v3 4/4] drm/bridge: tda998x: fix DRM_BRIDGE_ATTACH_NO_CONNECTOR support
Date: Tue, 24 Nov 2026 10:02:55 +0000	[thread overview]
Message-ID: <sashiko-outbox-230903@kernel.org> (raw)
In-Reply-To: <20261124093928.3220071-5-Luo.Liu@cixtech.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] drm/bridge: tda998x: tda998x_detect_work() drops HPD before
  detect()
- [Medium] drm/bridge: tda998x: unreferenced bridge_connector UAF in
  tda998x_audio_get_eld()
- [Medium] drm/bridge: tda998x: tda998x_remove() destroys hpd_mutex
  before detect_work
--

commit 5c61daf84ccbb8e21901c3e3a497e52ae6903d78
Author: Luo Liu <Luo.Liu@cixtech.com>

drm/bridge: tda998x: fix DRM_BRIDGE_ATTACH_NO_CONNECTOR support

This commit caches the connector passed to the bridge detect and EDID read
callbacks so mode setting, ELD retrieval, and hotplug work use the external
bridge connector when attached with DRM_BRIDGE_ATTACH_NO_CONNECTOR, and
sets bridge.interlace_allowed.

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

[ ... ]

> @@ -778,10 +800,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->bridge_connector)
> +		drm_bridge_hpd_notify(&priv->bridge, tda998x_conn_detect(priv));

[Severity: Medium]
Can tda998x_detect_work() lock priv->bridge.hpd_mutex after
tda998x_remove() has destroyed it?

tda998x_remove() calls drm_bridge_remove(), which runs
mutex_destroy(&bridge->hpd_mutex), before disabling the HPD interrupt and
canceling edid_delay_timer and detect_work:

CPU0                                  CPU1 (kworker)
tda998x_remove()
  drm_bridge_remove(&priv->bridge)
    mutex_destroy(&bridge->hpd_mutex)
                                      tda998x_detect_work()
                                        drm_bridge_hpd_notify()
                                          mutex_lock(&bridge->hpd_mutex)
                                            <-- use-after-destroy
  ...
  cancel_work_sync(&priv->detect_work)

> +	else if (priv->connector.dev)
> +		drm_kms_helper_hotplug_event(priv->connector.dev);
>  }

[Severity: Medium]
Does gating drm_bridge_hpd_notify() on priv->bridge_connector drop hotplug
events before tda998x_bridge_detect() or tda998x_bridge_edid_read() has been
called?

When attached with DRM_BRIDGE_ATTACH_NO_CONNECTOR, priv->connector.dev is
NULL and priv->bridge_connector stays NULL until .detect() or .edid_read()
runs.  With client->irq present, drm_bridge_connector_init() sets
DRM_CONNECTOR_POLL_HPD and registers the HPD callback without calling
.detect() or .edid_read(), so an HPD interrupt arriving before the first
connector probe takes neither branch and is lost.

Since drm_bridge_hpd_notify() does not use priv->bridge_connector, checking
priv->connector.dev first and calling drm_bridge_hpd_notify() in the else
branch would avoid dropping early HPD events.

[ ... ]

> @@ -1152,10 +1176,10 @@ static int tda998x_audio_get_eld(struct device *dev, void *data,
>  				 uint8_t *buf, size_t len)
>  {
>  	struct tda998x_priv *priv = dev_get_drvdata(dev);
> +	struct drm_connector *connector = tda998x_get_connector(priv);
>  
>  	mutex_lock(&priv->audio_mutex);
> -	memcpy(buf, priv->connector.eld,
> -	       min(sizeof(priv->connector.eld), len));
> +	memcpy(buf, connector->eld, min(sizeof(connector->eld), len));
>  	mutex_unlock(&priv->audio_mutex);
>  
>  	return 0;
>  }

[ ... ]

> @@ -1390,6 +1406,8 @@ static void tda998x_bridge_detach(struct drm_bridge *bridge)
>  {
>  	struct tda998x_priv *priv = bridge_to_tda998x_priv(bridge);
>  
> +	priv->bridge_connector = NULL;
> +
>  	if (priv->connector.dev)
>  		drm_connector_cleanup(&priv->connector);
>  }

[Severity: Medium]
Can tda998x_audio_get_eld() read from a freed priv->bridge_connector when
the display driver unbinds?

priv->audio_pdev lives until tda998x_remove(), while the external connector
created by drm_bridge_connector_init() is allocated with drmm_kzalloc()
after the mode_config and encoder cleanup actions are registered.  During
DRM teardown, drm_managed_release() runs in reverse order and frees the
drm_bridge_connector before drm_encoder_cleanup() calls
tda998x_bridge_detach().  In addition, tda998x_get_connector() and
tda998x_bridge_detach() access priv->bridge_connector without holding
priv->audio_mutex or taking a connector reference:

CPU0                                  CPU1
                                      tda998x_audio_get_eld()
                                        connector = tda998x_get_connector()
drm_managed_release()
  free_dr() /* frees bridge_connector */
  ...
  drm_encoder_cleanup()
    tda998x_bridge_detach()
      priv->bridge_connector = NULL
                                        mutex_lock(&priv->audio_mutex)
                                        memcpy(buf, connector->eld, ...)
                                          <-- use-after-free

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

  reply	other threads:[~2026-11-24 10:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24  9:39 [PATCH v3 0/4] drm/komeda: Use the bridge connector Luo Liu
2026-11-24  9:39 ` [PATCH v3 1/4] " Luo Liu
2026-11-24  9:39 ` [PATCH v3 2/4] drm/komeda: Use drmm_mode_config_init() Luo Liu
2026-11-24  9:39 ` [PATCH v3 3/4] drm/komeda: Free the IRQ before clearing dev_private Luo Liu
2026-11-24  9:39 ` [PATCH v3 4/4] drm/bridge: tda998x: fix DRM_BRIDGE_ATTACH_NO_CONNECTOR support Luo Liu
2026-11-24 10:02   ` sashiko-bot [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-11-24  9:41 [PATCH v3 0/4] drm/komeda: Use the bridge connector Luo Liu
2026-11-24  9:41 ` [PATCH v3 4/4] drm/bridge: tda998x: fix DRM_BRIDGE_ATTACH_NO_CONNECTOR support Luo Liu
2026-11-24 10:03   ` sashiko-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=sashiko-outbox-230903@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.