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 <[email protected]> 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 <[email protected]> > +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 <[email protected]> > L: [email protected] [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 <[email protected]> > + */ > + > +#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/[email protected]?part=31
