drm/komeda: Use the bridge connector
Subsystems (6)
v3 cover drm/komeda: Use the bridge connector
The first patch converts komeda to the new DRM bridge model. Bridges following that model no longer create a connector themselves, so the display driver attaches them with DRM_BRIDGE_ATTACH_NO_CONNECTOR and creates one connector for the whole chain with drm_bridge_connector_init().
The second patch fixes the teardown path that the conversion exposes. drm_bridge_connector_init() creates the connector with drmm_connector_init(), which provides no ->destroy hook and leaves the cleanup to a managed action. The drm_mode_config_cleanup() call in komeda_kms_detach(), and in the komeda_kms_attach() error paths, drops the connector references directly, so drm_connector_free() ends up calling the NULL ->destroy pointer.
Switching to drmm_mode_config_init() lets the core release the mode configuration after the connector cleanup actions have run. The komeda private objects are then finalized by walking the pipelines instead of mode_config.privobj_list, which also holds the bridges that the encoder cleanup releases.
The third patch fixes a latent interrupt race found in review. The IRQ is still registered after komeda_kms_detach(), and the komeda_kms_attach() error path, clear drm->dev_private, so a shared interrupt can reach komeda_kms_irq_handler() and dereference a NULL mdev. It is independent of the conversion.
The fourth patch fixes the tda998x bridge, which accepts the connector-less attach flag but keeps using its own connector. In that mode the connector is never initialised, so the bridge reads an empty display_info and ELD and stays in DVI mode without sending hotplug events. Use the connector provided to the detect and EDID read operations, report hotplug through drm_bridge_hpd_notify() and advertise interlaced mode support through the bridge.
Changes in v3:
- Add a fix for the tda998x bridge, which accepts DRM_BRIDGE_ATTACH_NO_CONNECTOR but keeps using its own connector.
Luo Liu (4):
drm/komeda: Use the bridge connector
drm/komeda: Use drmm_mode_config_init()
drm/komeda: Free the IRQ before clearing dev_private drm/bridge: tda998x: fix DRM_BRIDGE_ATTACH_NO_CONNECTOR support
drivers/gpu/drm/arm/display/Kconfig | 2 + .../gpu/drm/arm/display/komeda/komeda_crtc.c | 18 +++++- .../gpu/drm/arm/display/komeda/komeda_kms.c | 39 ++++++----- .../gpu/drm/arm/display/komeda/komeda_kms.h | 2 +- .../arm/display/komeda/komeda_private_obj.c | 23 +++++-- drivers/gpu/drm/bridge/tda998x_drv.c | 64 +++++++++++++------ 6 files changed, 105 insertions(+), 43 deletions(-)
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4 --
2.25.1
PATCH v3 1/4 drm/komeda: Use the bridge connector
Bridges following the new DRM bridge model no longer create a connector
themselves: the display driver has to attach them with DRM_BRIDGE_ATTACH_NO_CONNECTOR and create one connector for the whole chain with drm_bridge_connector_init().
Convert komeda to that model, so it keeps working with bridges that have moved to the new one. The bridges komeda binds to in mainline support connector-less attach, so boards using them are unaffected.
Select DRM_BRIDGE_CONNECTOR for drm_bridge_connector_init() and DRM_DISPLAY_HELPER, as the bridge connector is only visible when the display helper is enabled.
--- drivers/gpu/drm/arm/display/Kconfig | 2 ++ .../gpu/drm/arm/display/komeda/komeda_crtc.c | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-)
drivers/gpu/drm/arm/display/Kconfig +2 -0
@@ -6,6 +6,8 @@ config DRM_KOMEDA select DRM_CLIENT_SELECTION select DRM_KMS_HELPER select DRM_GEM_DMA_HELPER + select DRM_DISPLAY_HELPER + select DRM_BRIDGE_CONNECTOR select VIDEOMODE_HELPERS help Choose this option if you want to compile the ARM Komeda display
drivers/gpu/drm/arm/display/komeda/komeda_crtc.c +15 -3
@@ -15,6 +15,7 @@#include <drm/drm_print.h> #include <drm/drm_vblank.h> #include <drm/drm_bridge.h> +#include <drm/drm_bridge_connector.h> #include <drm/drm_panel.h> #include "komeda_dev.h"
@@ -617,6 +618,7 @@ static int komeda_attach_bridge(struct device *dev, struct drm_encoder *encoder) {struct drm_device *drm = encoder->dev; +struct drm_connector *connector;struct drm_bridge *bridge;int err;
@@ -626,12 +628,22 @@ static int komeda_attach_bridge(struct device *dev,return dev_err_probe (dev,PTR_ERR (bridge),"remote bridge not found for pipe: %s\n" ,of_node_full_name (pipe->of_node)); - err =drm_bridge_attach (encoder, bridge,NULL ,0 ); -if (err) + err =drm_bridge_attach (encoder, bridge,NULL , +DRM_BRIDGE_ATTACH_NO_CONNECTOR ); +if (err) {drm_err (drm,"bridge_attach() failed for pipe: %s\n" ,of_node_full_name (pipe->of_node)); +return err; + } -return err; + connector =drm_bridge_connector_init (drm, encoder); +if (IS_ERR (connector)) { +drm_err (drm,"bridge connector init failed for pipe: %s\n" , +of_node_full_name (pipe->of_node)); +return PTR_ERR (connector); + } + +return 0 ; }static const struct drm_encoder_funcs komeda_encoder_funcs = {
Signature · 1 line
2.25.1
PATCH v3 2/4 drm/komeda: Use drmm_mode_config_init()
In reply to Luo Liudrm_bridge_connector_init() creates the connector with drmm_connector_init(), which does not allow a ->destroy hook and registers its own cleanup action instead. Calling drm_mode_config_cleanup() explicitly drops the connector's last reference, so drm_connector_free() ends up calling a NULL ->destroy pointer. That happens on the komeda_kms_attach() error paths, and on unbind as soon as no other component holds a connector reference.
Let DRM release the mode configuration: switch to drmm_mode_config_init() and drop the explicit drm_mode_config_cleanup() calls. The managed cleanup is registered before the connectors are created, so it runs after the connector cleanup actions and finds an empty connector list.
The mode configuration teardown now happens after komeda_kms_detach() has returned, so komeda can no longer rely on drm_mode_config_cleanup() detaching the encoders' bridges before komeda_kms_cleanup_private_objs() walks mode_config.privobj_list - the bridges are private objects there as well, and finalizing them a second time when the encoders are cleaned up would corrupt the list and free their state twice. Since the komeda private objects belong to the pipeline components, finalize them by walking the pipelines instead of the shared list.
--- .../gpu/drm/arm/display/komeda/komeda_kms.c | 36 +++++++++++-------- .../gpu/drm/arm/display/komeda/komeda_kms.h | 2 +- .../arm/display/komeda/komeda_private_obj.c | 23 +++++++++--- 3 files changed, 40 insertions(+), 21 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_kms.c +21 -15
@@ -253,12 +253,15 @@ static const struct drm_mode_config_funcs komeda_mode_config_funcs = { .atomic_commit = drm_atomic_helper_commit, }; -static void komeda_kms_mode_config_init (struct komeda_kms_dev *kms, -struct komeda_dev *mdev) +static int komeda_kms_mode_config_init (struct komeda_kms_dev *kms, +struct komeda_dev *mdev) {struct drm_mode_config *config = &kms->base.mode_config; +int err; -drm_mode_config_init (&kms->base); + err =drmm_mode_config_init (&kms->base); +if (err) +return err;komeda_kms_setup_crtcs (kms, mdev);
@@ -270,6 +273,8 @@ static void komeda_kms_mode_config_init(struct komeda_kms_dev *kms, config->funcs = &komeda_mode_config_funcs; config->helper_private = &komeda_mode_config_helpers; + +return 0 ; }struct komeda_kms_dev *komeda_kms_attach (struct komeda_dev *mdev)
@@ -287,27 +292,29 @@ struct komeda_kms_dev *komeda_kms_attach(struct komeda_dev *mdev) drm->dev_private = mdev; -komeda_kms_mode_config_init (kms, mdev); + err =komeda_kms_mode_config_init (kms, mdev); +if (err) +return ERR_PTR (err); err =komeda_kms_add_private_objs (kms, mdev);if (err) - goto cleanup_mode_config; + goto cleanup_private_objs; err =komeda_kms_add_planes (kms, mdev);if (err) - goto cleanup_mode_config; + goto cleanup_private_objs; err =drm_vblank_init (drm, kms->n_crtcs);if (err) - goto cleanup_mode_config; + goto cleanup_private_objs; err =komeda_kms_add_crtcs (kms, mdev);if (err) - goto cleanup_mode_config; + goto cleanup_private_objs; err =komeda_kms_add_wb_connectors (kms, mdev);if (err) - goto cleanup_mode_config; + goto cleanup_private_objs;drm_mode_config_reset (drm);
@@ -315,7 +322,7 @@ struct komeda_kms_dev *komeda_kms_attach(struct komeda_dev *mdev) komeda_kms_irq_handler,IRQF_SHARED , drm->driver->name, drm);if (err) - goto cleanup_mode_config; + goto cleanup_private_objs;drm_kms_helper_poll_init (drm);
@@ -327,9 +334,8 @@ struct komeda_kms_dev *komeda_kms_attach(struct komeda_dev *mdev) free_interrupts:drm_kms_helper_poll_fini (drm); -cleanup_mode_config: -drm_mode_config_cleanup (drm); -komeda_kms_cleanup_private_objs (kms); +cleanup_private_objs: +komeda_kms_cleanup_private_objs (mdev); drm->dev_private =NULL ;return ERR_PTR (err); }
@@ -337,12 +343,12 @@ struct komeda_kms_dev *komeda_kms_attach(struct komeda_dev *mdev)void komeda_kms_detach (struct komeda_kms_dev *kms) {struct drm_device *drm = &kms->base; +struct komeda_dev *mdev = drm->dev_private;drm_dev_unregister (drm);drm_kms_helper_poll_fini (drm);drm_atomic_helper_shutdown (drm); -drm_mode_config_cleanup (drm); -komeda_kms_cleanup_private_objs (kms); +komeda_kms_cleanup_private_objs (mdev); drm->dev_private =NULL ; }
drivers/gpu/drm/arm/display/komeda/komeda_kms.h +1 -1
@@ -181,7 +181,7 @@ int komeda_kms_add_private_objs(struct komeda_kms_dev *kms, struct komeda_dev *mdev);int komeda_kms_add_wb_connectors (struct komeda_kms_dev *kms,struct komeda_dev *mdev); -void komeda_kms_cleanup_private_objs (struct komeda_kms_dev *kms); +void komeda_kms_cleanup_private_objs (struct komeda_dev *mdev);void komeda_crtc_handle_event (struct komeda_crtc *kcrtc,struct komeda_events *evts);
drivers/gpu/drm/arm/display/komeda/komeda_private_obj.c +18 -5
@@ -502,11 +502,24 @@ int komeda_kms_add_private_objs(struct komeda_kms_dev *kms,return 0 ; } -void komeda_kms_cleanup_private_objs (struct komeda_kms_dev *kms) +void komeda_kms_cleanup_private_objs (struct komeda_dev *mdev) { -struct drm_mode_config *config = &kms->base.mode_config; -struct drm_private_obj *obj, *next; +struct komeda_component *c; +struct komeda_pipeline *pipe; +unsigned long avail_comps; +int i, id; + +for (i =0 ; i < mdev->n_pipelines; i++) { + pipe = mdev->pipelines[i]; -list_for_each_entry_safe (obj, next, &config->privobj_list, head) -drm_atomic_private_obj_fini (obj); +if (pipe->obj.funcs) +drm_atomic_private_obj_fini (&pipe->obj); + + avail_comps = pipe->avail_comps; +for_each_set_bit (id, &avail_comps,32 ) { + c =komeda_pipeline_get_component (pipe, id); +if (c && c->obj.funcs) +drm_atomic_private_obj_fini (&c->obj); + } + } }
Signature · 1 line
2.25.1
PATCH v3 3/4 drm/komeda: Free the IRQ before clearing dev_private
In reply to Luo LiuThe interrupt is requested with devm_request_irq(), so it remains registered until the device is removed and its devres resources are released. komeda_kms_detach(), and the komeda_kms_attach() error path taken when drm_dev_register() fails, clear drm->dev_private before that, while komeda_kms_irq_handler() still reads mdev from it. The interrupt line is shared, so another device can raise it in that window and make the handler dereference a NULL pointer.
Free the interrupt explicitly with devm_free_irq() before dropping drm->dev_private. free_irq() removes the action and synchronizes with any handler in flight, so the handler cannot run afterwards.
--- drivers/gpu/drm/arm/display/komeda/komeda_kms.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/arm/display/komeda/komeda_kms.c +3 -0
@@ -334,6 +334,7 @@ struct komeda_kms_dev *komeda_kms_attach(struct komeda_dev *mdev) free_interrupts:drm_kms_helper_poll_fini (drm); +devm_free_irq (drm->dev, mdev->irq, drm); cleanup_private_objs:komeda_kms_cleanup_private_objs (mdev); drm->dev_private =NULL ;
@@ -348,6 +349,8 @@ void komeda_kms_detach(struct komeda_kms_dev *kms)drm_dev_unregister (drm);drm_kms_helper_poll_fini (drm);drm_atomic_helper_shutdown (drm); +/* The handler dereferences drm->dev_private, which is about to go. */ +devm_free_irq (drm->dev, mdev->irq, drm);komeda_kms_cleanup_private_objs (mdev); drm->dev_private =NULL ; }
Signature · 1 line
2.25.1
PATCH v3 4/4 drm/bridge: tda998x: fix DRM_BRIDGE_ATTACH_NO_CONNECTOR support
In reply to Luo LiuWhen attached with DRM_BRIDGE_ATTACH_NO_CONNECTOR, the connector is created by drm_bridge_connector_init() and the driver's own connector is never initialised. Several paths still access that connector:
- tda998x_bridge_mode_set() reads display_info from it to decide the RGB quantization range and whether infoframes and audio are supported. As it stays zeroed, the bridge always operates in DVI mode.
- tda998x_audio_get_eld() copies the ELD from it, which is always empty.
- tda998x_detect_work() uses its drm_device to send hotplug events, which never happens because the connector was never registered.
Use the connector passed to the bridge detect and EDID read operations instead of the driver's own connector whenever one was provided, and report hotplug events through drm_bridge_hpd_notify(). Also advertise interlaced mode support through the bridge, otherwise the bridge connector rejects them.
--- drivers/gpu/drm/bridge/tda998x_drv.c | 64 +++++++++++++++++++--------- 1 file changed, 45 insertions(+), 19 deletions(-)
drivers/gpu/drm/bridge/tda998x_drv.c +45 -19
@@ -81,6 +81,7 @@ struct tda998x_priv {struct drm_encoder encoder;struct drm_bridge bridge;struct drm_connector connector; +struct drm_connector *bridge_connector;u8 audio_port_enable[AUDIO_ROUTE_NUM ];struct tda9950_glue cec_glue;
@@ -95,6 +96,19 @@ struct tda998x_priv {#define bridge_to_tda998x_priv (x) \ container_of(x, struct tda998x_priv, bridge) +/* +* When attached with DRM_BRIDGE_ATTACH_NO_CONNECTOR, the connector is created +* by drm_bridge_connector_init() and handed to the bridge detect and EDID +* operations; otherwise it is the driver's own connector. +*/ +static struct drm_connector *tda998x_get_connector (struct tda998x_priv *priv) +{ +if (priv->bridge_connector) +return priv->bridge_connector; + +return &priv->connector; +} +/* The TDA9988 series of devices use a paged register scheme.. to simplify * things we encode the page # in upper bits of the register #. To read/ * write a given register, we need to make sure CURPAGE register is set
@@ -769,6 +783,14 @@ static int tda998x_edid_delay_wait(struct tda998x_priv *priv)return wait_event_killable (priv->edid_delay_waitq, !priv->edid_delay_active); } +static enum drm_connector_status tda998x_conn_detect (struct tda998x_priv *priv) +{ +u8 val =cec_read (priv,REG_CEC_RXSHPDLEV ); + +return (val &CEC_RXSHPDLEV_HPD ) ? connector_status_connected : + connector_status_disconnected; +} +/* * We need to run the KMS hotplug event helper outside of our threaded * interrupt routine as this can call back into our get_modes method,
@@ -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)); +else if (priv->connector.dev) +drm_kms_helper_hotplug_event (priv->connector.dev); }/*
@@ -859,12 +882,12 @@ static void tda998x_write_aif(struct tda998x_priv *priv,static void tda998x_write_avi (struct tda998x_priv *priv,const struct drm_display_mode *mode) { +struct drm_connector *connector =tda998x_get_connector (priv);union hdmi_infoframe frame; -drm_hdmi_avi_infoframe_from_display_mode (&frame.avi, - &priv->connector, mode); +drm_hdmi_avi_infoframe_from_display_mode (&frame.avi, connector, mode); frame.avi.quantization_range =HDMI_QUANTIZATION_RANGE_FULL ; -drm_hdmi_avi_infoframe_quant_range (&frame.avi, &priv->connector, mode, +drm_hdmi_avi_infoframe_quant_range (&frame.avi, connector, mode, priv->rgb_quant_range);tda998x_write_if (priv,DIP_IF_FLAGS_IF2 ,REG_IF2_HB0 , &frame);
@@ -873,10 +896,11 @@ tda998x_write_avi(struct tda998x_priv *priv, const struct drm_display_mode *modestatic void tda998x_write_vsi (struct tda998x_priv *priv,const struct drm_display_mode *mode) { +struct drm_connector *connector =tda998x_get_connector (priv);union hdmi_infoframe frame;if (drm_hdmi_vendor_infoframe_from_display_mode (&frame.vendor.hdmi, - &priv->connector, + connector, mode))reg_clear (priv,REG_DIP_IF_FLAGS ,DIP_IF_FLAGS_IF1 );else
@@ -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 ;
@@ -1193,14 +1217,6 @@ static int tda998x_audio_codec_init(struct tda998x_priv *priv,/* DRM connector functions */ -static enum drm_connector_status tda998x_conn_detect (struct tda998x_priv *priv) -{ -u8 val =cec_read (priv,REG_CEC_RXSHPDLEV ); - -return (val &CEC_RXSHPDLEV_HPD ) ? connector_status_connected : - connector_status_disconnected; -} -static enum drm_connector_status tda998x_connector_detect (struct drm_connector *connector,bool force) {
@@ -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); }
@@ -1449,6 +1467,7 @@ static void tda998x_bridge_mode_set(struct drm_bridge *bridge, const struct drm_display_mode *adjusted_mode) {struct tda998x_priv *priv =bridge_to_tda998x_priv (bridge); +struct drm_connector *connector =tda998x_get_connector (priv);unsigned long tmds_clock;u16 ref_pix, ref_line, n_pix, n_line;u16 hs_pix_s, hs_pix_e;
@@ -1465,7 +1484,7 @@ static void tda998x_bridge_mode_set(struct drm_bridge *bridge,* it, otherwise reduce to limited-range. */ priv->rgb_quant_range = - priv->connector.display_info.rgb_quant_range_selectable ? + connector->display_info.rgb_quant_range_selectable ?HDMI_QUANTIZATION_RANGE_FULL :drm_default_rgb_quant_range (adjusted_mode);
@@ -1674,7 +1693,7 @@ static void tda998x_bridge_mode_set(struct drm_bridge *bridge,* ignore CEA version 2 and below (iow, behave as if we're a * CEA-861 source.) */ - priv->supports_infoframes = priv->connector.display_info.cea_rev >=3 ; + 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 */
@@ -1701,6 +1720,9 @@ tda998x_bridge_edid_read(struct drm_bridge *bridge,const struct drm_edid *drm_edid;const struct edid *edid; +if (connector) + priv->bridge_connector = connector; + drm_edid =tda998x_edid_read (priv, connector);if (!drm_edid) {dev_dbg (&priv->hdmi->dev,"failed to get edid\n" );
@@ -1729,6 +1751,9 @@ tda998x_bridge_detect(struct drm_bridge *bridge, {struct tda998x_priv *priv =bridge_to_tda998x_priv (bridge); +if (connector) + priv->bridge_connector = connector; +return tda998x_conn_detect (priv); }
@@ -2011,6 +2036,7 @@ tda998x_probe(struct i2c_client *client) priv->bridge.ops |=DRM_BRIDGE_OP_EDID |DRM_BRIDGE_OP_DETECT ; priv->bridge.type =DRM_MODE_CONNECTOR_HDMIA ; + priv->bridge.interlace_allowed = true;drm_bridge_add (&priv->bridge);return 0 ;
Signature · 1 line
2.25.1
[email protected]
AI reviewRe: [PATCH v3 4/4] drm/bridge: tda998x: fix DRM_BRIDGE_ATTACH_NO_CONNECTOR support
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…
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 <[email protected]>
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.
Quoted 4 lines
drivers/gpu/drm/bridge/tda998x_drv.c +0
-0
[ ... ]
drivers/gpu/drm/bridge/tda998x_drv.c static void tda998x_detect_work(struct work_struct *work) · line 805
Quoted 10 lines
drivers/gpu/drm/bridge/tda998x_drv.c +2
-3@@ -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)
drivers/gpu/drm/bridge/tda998x_drv.c static void tda998x_detect_work(struct work_struct *work) · line 808
Quoted 3 lines
drivers/gpu/drm/bridge/tda998x_drv.c +2
-0+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.
[ ... ]
Quoted 14 lines
drivers/gpu/drm/bridge/tda998x_drv.c +2
-2@@ -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 ;}
[ ... ]
drivers/gpu/drm/bridge/tda998x_drv.c static void tda998x_bridge_detach(struct drm_bridge *bridge) · line 1413
Quoted 9 lines
drivers/gpu/drm/bridge/tda998x_drv.c +2
-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-freeSignature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4