Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Luca Ceresoli" <luca.ceresoli@bootlin.com>
Cc: Frank.Li@kernel.org, imx@lists.linux.dev
Subject: Re: [PATCH 17/37] drm/display: bridge-connector: protect dynconn creation and destruction with a mutex
Date: Tue, 19 May 2026 11:18:14 +0000	[thread overview]
Message-ID: <20260519111814.BC9C6C2BCB3@smtp.kernel.org> (raw)
In-Reply-To: <20260519-drm-bridge-hotplug-v1-17-45e2bdb3dfb4@bootlin.com>

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] Missing state check inside the locked section of drm_bridge_connector_add_connector() allows overwriting an existing connector
- [High] Unprotected access to `dynconn` in drm_bridge_connector_handle_hpd() leads to NULL pointer dereference
- [High] Use-After-Free caused by mixing `drmm` cleanup actions with dynamically freed connectors
- [Medium] Mixing goto-based error handling with scope-based guard() cleanup in drm_bridge_connector_add_connector()
- [Medium] Missing mutex_destroy() or drmm_mutex_init() for `dynconn_mutex`
--

commit 83c9dccacbc0bf010c7c667632a3090398d3e6ed
Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
drm/display: bridge-connector: protect dynconn creation and destruction with a mutex

This commit introduces a mutex to mutually exclude connector creation and
destruction based on bridge hotplug events. It adds dynconn_mutex to
the drm_bridge_connector structure and uses guard() to protect the
relevant sections.

> diff --git a/drivers/gpu/drm/display/drm_bridge_connector.c b/drivers/gpu/drm/display/drm_bridge_connector.c
> index bd421b6beb7c4..b83da529cc7af 100644
> --- a/drivers/gpu/drm/display/drm_bridge_connector.c
> +++ b/drivers/gpu/drm/display/drm_bridge_connector.c
> @@ -152,6 +153,11 @@ struct drm_bridge_connector {
>  	 * @dynconn: The DRM connector added by the drm_bridge_connector
>  	 */
>  	struct drm_bridge_connector_dynconn *dynconn;
> +	/**
> +	 * @dynconn_mutex: Protect @dynconn from concurrent creation and
> +	 * destruction
> +	 */
> +	struct mutex dynconn_mutex;
>  };

Does drm_bridge_connector_handle_hpd() need to use this new mutex?

Since the connector lifecycle is now dynamic, if an asynchronous HPD event
fires concurrently with a bridge detachment (which calls
drm_bridge_connector_dynconn_release() and sets dynconn to NULL under the
mutex), could drm_bridge_connector_handle_hpd() fetch the connector without
the lock and trigger a NULL pointer dereference or use-after-free?

Could the dynamic lifecycle of the connector also cause a use-after-free
with drmm cleanup actions?

drm_bridge_connector_add_connector() calls
drm_bridge_connector_init_hdmi_audio_cec(), which uses
drmm_connector_hdmi_cec_register() to register a cleanup action tied to the
drm_device's lifetime.

Because the connector is now dynamically managed and freed via kfree when a
bridge is detached, won't the drmm cleanup action hold a stale pointer and
execute on an already-freed connector when the DRM device is unregistered?

[ ... ]
> @@ -1050,6 +1058,8 @@ static int drm_bridge_connector_add_connector(struct drm_bridge_connector *bridg
>  	int connector_type;
>  	int ret;
>  
> +	guard(mutex)(&bridge_connector->dynconn_mutex);
> +

Does introducing guard() here violate the cleanup subsystem guidelines?

The kernel cleanup subsystem guidelines forbid mixing goto-based error
handling with scope-based cleanups like guard() in the same function because
it creates confusing ownership semantics.

Later in this function we see:

	if (ret)
		goto err_put;

	return 0;

err_put:
	drm_connector_put(connector);
	bridge_connector->dynconn = NULL;
	return ret;

Could this mix of guard() and goto cause issues?

>  	struct drm_bridge_connector_dynconn *dynconn = kzalloc_obj(*dynconn);

Could concurrent hotplug events overwrite an existing connector here?

While later patches in the series introduce
drm_bridge_connector_try_complete() which checks
if (bridge_connector->dynconn), that lockless check happens outside of
dynconn_mutex.

If two threads pass that check simultaneously, they will sequentially
acquire dynconn_mutex here. Would the second thread then unconditionally
overwrite bridge_connector->dynconn with a new allocation, leaking the
first connector's memory and leaving a dangling registered connector?

[ ... ]
> @@ -1177,6 +1187,7 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
>  	if (!bridge_connector)
>  		return ERR_PTR(-ENOMEM);
>  
> +	mutex_init(&bridge_connector->dynconn_mutex);

Should this be drmm_mutex_init() instead?

bridge_connector is allocated with drmm_kzalloc(), meaning its memory is
tied to the DRM device's lifecycle. Since the registered cleanup action
drm_bridge_connector_fini() does not call mutex_destroy(), could freeing
the structure leave an active mutex and trigger kernel debug warnings when
CONFIG_DEBUG_MUTEXES is enabled?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260519-drm-bridge-hotplug-v1-0-45e2bdb3dfb4@bootlin.com?part=17

  reply	other threads:[~2026-05-19 11:18 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-19 10:37 [PATCH 00/37] drm bridge hotplug Luca Ceresoli
2026-05-19 10:37 ` [PATCH 01/37] drm/connector: split drmm_connector_hdmi_init() in 3 parts Luca Ceresoli
2026-05-19 10:37 ` [PATCH 02/37] drm/connector: add drm_connector_hdmi_dynamic_init() Luca Ceresoli
2026-05-19 11:04   ` sashiko-bot
2026-05-19 10:37 ` [PATCH 03/37] drm/display: bridge-connector: rename variable for consistency Luca Ceresoli
2026-05-19 10:37 ` [PATCH 04/37] drm/display: bridge-connector: store the drm_device pointer Luca Ceresoli
2026-05-19 10:37 ` [PATCH 05/37] drm/display: bridge-connector: split code creating the connector to a subfunction Luca Ceresoli
2026-05-19 10:37 ` [PATCH 06/37] drm/display: bridge-connector: use a drm_bridge_connector internally, not a drm_connector Luca Ceresoli
2026-05-19 10:37 ` [PATCH 07/37] drm/display: bridge-connector: extract drm_bridge_connector_get_bridges() Luca Ceresoli
2026-05-19 11:01   ` sashiko-bot
2026-05-19 10:37 ` [PATCH 08/37] drm/display: bridge-connector: return int from drm_bridge_connector_get_bridges() Luca Ceresoli
2026-05-19 10:58   ` sashiko-bot
2026-05-19 10:37 ` [PATCH 09/37] drm/display: bridge-connector: extract drm_bridge_connector_init_hdmi_audio_cec() Luca Ceresoli
2026-05-19 10:37 ` [PATCH 10/37] drm/display: bridge-connector: return int from drm_bridge_connector_init_hdmi_audio_cec() Luca Ceresoli
2026-05-19 10:37 ` [PATCH 11/37] drm/display: bridge-connector: return int from drm_bridge_connector_add_connector() Luca Ceresoli
2026-05-19 10:37 ` [PATCH 12/37] drm/display: bridge-connector: hoist error management to common code Luca Ceresoli
2026-05-19 10:37 ` [PATCH 13/37] drm/display: bridge-connector: move drm_bridge_connector_put_bridges() definition eariler Luca Ceresoli
2026-05-19 10:37 ` [PATCH 14/37] drm/display: bridge-connector: add non-drmm variant of drm_bridge_connector_put_bridges() Luca Ceresoli
2026-05-19 10:37 ` [PATCH 15/37] drm/display: bridge-connector: allocate the connector dynamically Luca Ceresoli
2026-05-19 11:15   ` sashiko-bot
2026-05-19 10:37 ` [PATCH 16/37] drm/display: bridge-connector: move per-connector fields to the dynamic connector Luca Ceresoli
2026-05-19 11:17   ` sashiko-bot
2026-05-19 10:37 ` [PATCH 17/37] drm/display: bridge-connector: protect dynconn creation and destruction with a mutex Luca Ceresoli
2026-05-19 11:18   ` sashiko-bot [this message]
2026-05-19 10:37 ` [PATCH 18/37] drm/bridge: samsung-dsim: remove the panel_bridge on host_detach Luca Ceresoli
2026-05-19 10:37 ` [PATCH 19/37] drm/bridge: samsung-dsim: move drm_bridge_add() call to probe Luca Ceresoli
2026-05-19 11:16   ` sashiko-bot
2026-05-19 10:37 ` [PATCH 20/37] drm/bridge: samsung-dsim: attach: return -EPROBE_DEFER is next bridge not yet available Luca Ceresoli
2026-05-19 11:13   ` sashiko-bot
2026-05-19 10:37 ` [PATCH 21/37] drm/bridge: initialize chain_node list head on allocation Luca Ceresoli
2026-05-19 10:37 ` [PATCH 22/37] drm/bridge: initialize chain_node list head on detach and attach errors Luca Ceresoli
2026-05-19 11:17   ` sashiko-bot
2026-05-19 10:37 ` [PATCH 23/37] drm/encoder: add drm_encoder_cleanup_from() Luca Ceresoli
2026-05-19 11:14   ` sashiko-bot
2026-05-19 10:37 ` [PATCH 24/37] drm/atomic: move drm_atomic_helper_disable_all() and drm_atomic_helper_shutdown() from drm_atomic_helper to drm_atomic Luca Ceresoli
2026-05-19 10:57   ` sashiko-bot
2026-05-19 10:37 ` [PATCH 25/37] drm/bridge: shutdown and cleanup on bridge unplug Luca Ceresoli
2026-05-19 11:09   ` sashiko-bot
2026-05-19 10:37 ` [PATCH 26/37] drm: event-notifier: add mechanism to notify about hotplug events Luca Ceresoli
2026-05-19 11:06   ` sashiko-bot
2026-05-19 10:37 ` [PATCH 27/37] drm/bridge: notify about detached bridges Luca Ceresoli
2026-05-19 11:32   ` sashiko-bot
2026-05-19 10:37 ` [PATCH 28/37] drm/mipi-dsi: turn DRM_MIPI_DSI into a tristate Luca Ceresoli
2026-05-19 11:07   ` sashiko-bot
2026-05-19 10:37 ` [PATCH 29/37] drm/mipi-dsi: notify about DSI attach Luca Ceresoli
2026-05-19 11:13   ` sashiko-bot
2026-05-19 10:37 ` [PATCH 30/37] drm/bridge: add drm_bridge_is_tail() to know whether a bridge completes the pipeline Luca Ceresoli
2026-05-19 10:59   ` sashiko-bot
2026-05-19 10:37 ` [PATCH 31/37] drm/bridge: panel: implement .is_tail Luca Ceresoli
2026-05-19 15:12   ` Neil Armstrong
2026-05-19 10:37 ` [PATCH 32/37] drm/bridge: display-connector: " Luca Ceresoli
2026-05-19 10:37 ` [PATCH 33/37] drm/bridge: samsung-dsim: " Luca Ceresoli
2026-05-19 10:37 ` [PATCH 34/37] drm/bridge: ti-sn65dsi83: " Luca Ceresoli
2026-05-19 10:37 ` [PATCH 35/37] drm/bridge: drm_bridge_attach(): don't fail on -EPROBE_DEFER Luca Ceresoli
2026-05-19 11:21   ` sashiko-bot
2026-05-19 10:37 ` [PATCH 36/37] drm/display: bridge-connector: handle bridge hotplug Luca Ceresoli
2026-05-19 11:15   ` sashiko-bot
2026-05-19 10:37 ` [PATCH 37/37] drm/mxsfb/lcdif: enable " Luca Ceresoli
2026-05-19 11:33   ` 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=20260519111814.BC9C6C2BCB3@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=luca.ceresoli@bootlin.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox