All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Luca Ceresoli" <luca.ceresoli@bootlin.com>
Cc: dri-devel@lists.freedesktop.org, imx@lists.linux.dev,
	Frank.Li@kernel.org
Subject: Re: [PATCH v4 31/32] drm: drm_hotplug_helper: new helper to implement bridge hotplug
Date: Wed, 25 Nov 2026 18:30:28 +0000	[thread overview]
Message-ID: <sashiko-outbox-233995@kernel.org> (raw)
In-Reply-To: <20261125-drm-bridge-hotplug-v4-31-822722850492@bootlin.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] drm: invalid direct attach() call in
  drm_hotplug_helper_try_complete()
- [Medium] drm: drmm_hotplug_helper_init() returns NULL on success
- [Medium] drm: race with bridge detach in
  drm_hotplug_helper_try_complete()
- [Low] drm: missing forward declarations and broken kdoc in
  drm_hotplug_helper.h
- [Low] drm: MAINTAINERS hotplug helper entry claims all bridge DT
  bindings
--

commit 965c3e7b932068825241acd70d8d77673075709c
Author: Luca Ceresoli <luca.ceresoli@bootlin.com>

drm: drm_hotplug_helper: new helper to implement bridge hotplug

This commit adds drmm_hotplug_helper_init() to listen for DRM bridge hotplug
events, attach the encoder's bridge chain, and dynamically add or remove a
drm_bridge_connector as the pipeline completes or breaks.

> diff --git a/MAINTAINERS b/MAINTAINERS
> index a5e2bf15e59f2..18ecb7bb39f40 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -8219,6 +8219,14 @@ F:	Documentation/devicetree/bindings/npu/rockchip,rk3588-rknn-core.yaml
>  F:	drivers/accel/rocket/
>  F:	include/uapi/drm/rocket_accel.h
>  
> +DRM BRIDGE HOTPLUG HELPER
> +M:	Luca Ceresoli <luca.ceresoli@bootlin.com>
> +S:	Maintained
> +T:	git https://gitlab.freedesktop.org/drm/misc/kernel.git
> +F:	Documentation/devicetree/bindings/display/bridge/
> +F:	drivers/gpu/drm/display/drm_hotplug_helper.c
> +F:	include/drm/drm_hotplug_helper.h
> +
>  DRM COMPUTE ACCELERATORS DRIVERS AND FRAMEWORK
>  M:	Oded Gabbay <ogabbay@kernel.org>
>  L:	dri-devel@lists.freedesktop.org

[Severity: Low]
Should the Documentation/devicetree/bindings/display/bridge/ line be dropped
here?  That path covers all bridge chip bindings (already listed under DRM
DRIVERS FOR BRIDGE CHIPS), whereas drm_hotplug_helper is an in-kernel helper
with no devicetree bindings of its own.

> diff --git a/drivers/gpu/drm/display/drm_hotplug_helper.c b/drivers/gpu/drm/display/drm_hotplug_helper.c
> new file mode 100644
> index 0000000000000..ea32bdb0af8f3
> --- /dev/null
> +++ b/drivers/gpu/drm/display/drm_hotplug_helper.c

[ ... ]

> +static void drm_hotplug_helper_try_complete(struct drm_hotplug_helper *hotplug_helper)
> +{
> +	struct device *dev = hotplug_helper->encoder->dev->dev;
> +	int err;
> +
> +	WARN_ON(!mutex_is_locked(&hotplug_helper->event_mutex));
> +
> +	/*
> +	 * drm_connector already present, the new bridge must be for
> +	 * another card
> +	 *
> +	 */
> +	if (hotplug_helper->connector)
> +		return;
> +
> +	struct drm_bridge *last_bridge __free(drm_bridge_put) =
> +		drm_bridge_chain_get_last_bridge(hotplug_helper->encoder);

[Severity: Medium]
Can drm_bridge_chain_get_last_bridge() race with concurrent bridge removal in
drm_bridge_detach_from()?

drm_hotplug_helper_try_complete() (and
drm_hotplug_helper_bridge_chain_is_complete()) reads encoder->bridge_chain
under hotplug_helper->event_mutex without holding
encoder->bridge_chain_mutex.  Meanwhile, drm_bridge_remove() detaches
bridges before notifying DRM_BRIDGE_DETACHED:

CPU0                                  CPU1
drm_bridge_remove(last_bridge)
  drm_bridge_detach_from()
    lock(&encoder->bridge_chain_mutex)
                                      drm_hotplug_helper_try_complete()
                                        drm_bridge_chain_get_last_bridge()
                                          list_last_entry_or_null(...)
    list_move_tail(..., &tmplist)
    unlock(&encoder->bridge_chain_mutex)
    drm_bridge_detach(last_bridge)
      list_del_init(&chain_node)
                                        last_bridge->funcs->attach(...)
                                          drm_bridge_attach(..., last_bridge)
                                            list_add(&new->chain_node,
                                                     &last_bridge->chain_node)
                                                     <-- attaches to detached
                                                         bridge / corrupts
                                                         tmplist
      drm_hotplug_event_notifier_notify()
      last_bridge->dev = NULL
      last_bridge->encoder = NULL

Because drm_bridge_detach() only clears bridge->dev and bridge->encoder after
the DRM_BRIDGE_DETACHED notification returns, drm_bridge_attach() with
previous = last_bridge passes its validation checks and links the new bridge
onto last_bridge->chain_node while last_bridge is on tmplist or already
detached from encoder->bridge_chain.

> +
> +	if (last_bridge) {
> +		/*
> +		 * Some bridge(s) already in the chain, propagate the
> +		 * attach call chain from the current chain tail to newly
> +		 * hotplugged bridge(s)
> +		 */
> +		dev_dbg(dev, "propagate attach after %ps\n", last_bridge->funcs);
> +
> +		err = last_bridge->funcs->attach(last_bridge, hotplug_helper->encoder,
> +						 DRM_BRIDGE_ATTACH_NO_CONNECTOR);
> +		if (err)
> +			return;

[Severity: High]
Is it valid to call last_bridge->funcs->attach() directly on a bridge that is
already attached?

First, drm_bridge_funcs.attach is optional (drm_bridge_attach() checks
if (bridge->funcs->attach)), so dereferencing last_bridge->funcs->attach
unconditionally will cause a NULL pointer dereference if the tail bridge
does not implement .attach.

Second, last_bridge is already attached to encoder->bridge_chain and has not
been detached.  Re-invoking its .attach callback on subsequent
DRM_BRIDGE_ADDED or DRM_MIPI_DSI_ATTACHED notifications violates the 1:1
attach/detach lifecycle and re-runs per-bridge attach initialization on an
already-initialized bridge.  For example, ti_sn_bridge_attach() in
drivers/gpu/drm/bridge/ti-sn65dsi86.c calls drm_dp_aux_register(&pdata->aux)
before attaching pdata->next_bridge and unwinds with
drm_dp_aux_unregister(&pdata->aux) if attaching next_bridge fails, so
calling .attach() again attempts to re-register an already-registered DP AUX
device and unregisters it on failure while the bridge remains attached.

[ ... ]

> +struct drm_hotplug_helper *drmm_hotplug_helper_init(struct drm_encoder *encoder,
> +						    drm_hotplug_helper_event_cb event_cb,
> +						    struct device_node *first_bridge_ep)
> +{

[ ... ]

> +	guard(mutex)(&hotplug_helper->event_mutex);
> +	drm_hotplug_helper_try_complete(hotplug_helper);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(drmm_hotplug_helper_init);

[Severity: Medium]
Should drmm_hotplug_helper_init() return hotplug_helper instead of 0?
Returning NULL on success contradicts the documented ERR_PTR() contract and
causes callers checking !ret or IS_ERR_OR_NULL() to treat every successful
initialization as a failure.

> diff --git a/include/drm/drm_hotplug_helper.h b/include/drm/drm_hotplug_helper.h
> new file mode 100644
> index 0000000000000..ba14d547f8ff8
> --- /dev/null
> +++ b/include/drm/drm_hotplug_helper.h
> @@ -0,0 +1,30 @@
> +/* SPDX-License-Identifier: GPL-2.0+ */
> +/*
> + * Copyright (C) 2026 GE HealthCare
> + * Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
> + */
> +
> +#ifndef __DRM_HOTPLUG_HELPER_H__
> +#define __DRM_HOTPLUG_HELPER_H__
> +
> +/**
> + * enum drm_hotplug_helper_event - DRM hotplug helper connector events
> + */
> +enum drm_hotplug_helper_event {
> +	/** @DRM_HOTPLUG_HELPER_CONNECTOR_ADDED: A drm_connector has just been added */
> +	DRM_HOTPLUG_HELPER_CONNECTOR_ADDED,
> +	/** @DRM_HOTPLUG_HELPER_CONNECTOR_REMOVING: A drm_connector is about to be removed */
> +	DRM_HOTPLUG_HELPER_CONNECTOR_REMOVING,
> +};
> +
> +/**
> + * drm_hotplug_helper_event_cb - Callback to report connector addition and removal.
> + */
> +typedef void (*drm_hotplug_helper_event_cb)(enum drm_hotplug_helper_event event,
> +					    struct drm_connector *connector);
> +
> +struct drm_hotplug_helper *drmm_hotplug_helper_init(struct drm_encoder *encoder,
> +						    drm_hotplug_helper_event_cb event_cb,
> +						    struct device_node *next_bridge_ep);
> +
> +#endif /* __DRM_HOTPLUG_HELPER_H__ */

[Severity: Low]
Does include/drm/drm_hotplug_helper.h build cleanly under
CONFIG_DRM_HEADER_TEST=y?

struct drm_connector, struct drm_encoder, and struct device_node are used in
the parameter lists without forward declarations, causing -Wvisibility
warnings when the header is compiled standalone.  In addition, the kernel-doc
comment for drm_hotplug_helper_event_cb is missing the typedef prefix
("typedef drm_hotplug_helper_event_cb - ...") and @event / @connector
descriptions required by scripts/kernel-doc, and the third parameter of
drmm_hotplug_helper_init() is named next_bridge_ep here instead of
first_bridge_ep as in the definition.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-drm-bridge-hotplug-v4-0-822722850492@bootlin.com?part=31

  reply	other threads:[~2026-11-25 18:30 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 01/32] drm/display: hdmi-cec-helper: use drmm_ prefix for drmm action Luca Ceresoli
2026-12-01 10:20   ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 02/32] drm/display: hdmi-cec-helper: add non-drmm API variant Luca Ceresoli
2026-11-25 18:08   ` sashiko-bot
2026-12-01 10:21   ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 03/32] drm/display: hdmi-cec-notifier-helper: use drmm_ prefix for drmm action Luca Ceresoli
2026-12-01 10:21   ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 04/32] drm/display: hdmi-cec-notifier-helper: add non-drmm API variant Luca Ceresoli
2026-11-25 18:07   ` sashiko-bot
2026-12-01 10:22   ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 05/32] drm/connector: split drmm_connector_hdmi_init() in 3 parts Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 06/32] drm/connector: add drm_connector_hdmi_dynamic_init() Luca Ceresoli
2026-11-25 18:10   ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 07/32] drm/display: bridge-connector: split allocation code from initialization code Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 08/32] drm/display: bridge-connector: hoist error management to common code Luca Ceresoli
2026-11-25 18:03   ` sashiko-bot
2026-12-01 10:30   ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 09/32] drm/display: bridge-connector: use a dynamic connector Luca Ceresoli
2026-11-25 18:21   ` sashiko-bot
2026-11-26  1:15   ` kernel test robot
2026-11-25 17:50 ` [PATCH v4 10/32] drm/display: bridge-connector: add APIs to add/remove the connector dynamically Luca Ceresoli
2026-11-25 18:14   ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 11/32] drm/bridge: constify of_drm_find_and_get_bridge() device_node parameter Luca Ceresoli
2026-11-25 17:59   ` sashiko-bot
2026-12-01 10:30   ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 12/32] drm/bridge: initialize chain_node list head on allocation Luca Ceresoli
2026-12-01 10:31   ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 13/32] drm/bridge: initialize chain_node list head on detach and attach errors Luca Ceresoli
2026-12-01 10:31   ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 14/32] drm/bridge: ti-sn65dsi86: protect device resources on unplug Luca Ceresoli
2026-11-25 18:16   ` sashiko-bot
2026-12-01 10:23   ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 15/32] drm/atomic: drm_atomic_private_obj_fini: protect private_obj removal from list Luca Ceresoli
2026-11-25 18:12   ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 16/32] drm/probe-helper: add per-connector polling enable/disable Luca Ceresoli
2026-11-25 18:10   ` sashiko-bot
2026-12-01 10:32   ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 17/32] drm: event-notifier: add mechanism to notify about hotplug events Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 18/32] drm/bridge: notify about added and detached bridges Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 19/32] drm/mipi-dsi: notify about DSI attach Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 20/32] drm/bridge: add drm_bridge_get_next() and supporting func Luca Ceresoli
2026-12-01 10:40   ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 21/32] drm/panel: implement .get_next_bridge Luca Ceresoli
2026-12-01 10:36   ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 22/32] drm/bridge: display-connector: " Luca Ceresoli
2026-12-01 10:41   ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 23/32] drm/bridge: ti-sn65dsi83: " Luca Ceresoli
2026-11-25 18:14   ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 24/32] drm/bridge: ti-sn65dsi86: " Luca Ceresoli
2026-11-25 18:18   ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 25/32] drm/bridge: samsung-dsim: " Luca Ceresoli
2026-11-25 18:15   ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 26/32] drm/bridge: add drm_bridge_detach_from() Luca Ceresoli
2026-11-25 18:15   ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 27/32] drm/atomic: add drm_atomic_shutdown_encoder() Luca Ceresoli
2026-12-01 15:19   ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 28/32] drm/tests: atomic: add tests for drm_atomic_shutdown_encoder() Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 29/32] drm/bridge: clear bridge->encoder on detach Luca Ceresoli
2026-12-01 15:24   ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 30/32] drm/bridge: shutdown encoder and detach downstream bridges on bridge unplug Luca Ceresoli
2026-11-25 18:28   ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 31/32] drm: drm_hotplug_helper: new helper to implement bridge hotplug Luca Ceresoli
2026-11-25 18:30   ` sashiko-bot [this message]
2026-12-01 16:06   ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 32/32] drm/mxsfb/lcdif: enable " Luca Ceresoli
2026-11-25 18:31   ` sashiko-bot
2026-11-26  3:23   ` kernel test robot
2026-11-26  5:12   ` kernel test robot

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-233995@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=dri-devel@lists.freedesktop.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 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.