drm/komeda: Use the bridge connector
Subsystems (4)
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.
Luo Liu (2):
drm/komeda: Use the bridge connector
drm/komeda: Use drmm_mode_config_init()
drivers/gpu/drm/arm/display/Kconfig | 2 ++ .../gpu/drm/arm/display/komeda/komeda_crtc.c | 18 ++++++++-- .../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 +++++++++--- 5 files changed, 57 insertions(+), 24 deletions(-)
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.25.1
PATCH 1/2 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
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] drm/komeda: broken HDMI mode and infoframes with tda998x in komeda_attach_bridge() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] drm/komeda: broken HDMI mode and infoframes with tda998x in komeda_attach_bridge()
--
commit 293b61d44e25857ad3d8e0efc9c67e615c5a4933
Author: Luo Liu <[email protected]>
drm/komeda: Use the bridge connector
This commit attaches komeda's downstream bridge with DRM_BRIDGE_ATTACH_NO_CONNECTOR and initializes a bridge connector using drm_bridge_connector_init().
Quoted 4 lines
drivers/gpu/drm/arm/display/komeda/komeda_crtc.c +0
-0
[ ... ]
drivers/gpu/drm/arm/display/komeda/komeda_crtc.c static int komeda_attach_bridge(struct device *dev, · line 632
Quoted 8 lines
drivers/gpu/drm/arm/display/komeda/komeda_crtc.c +2
-2@@ -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 );
[Severity: Medium]
Does passing DRM_BRIDGE_ATTACH_NO_CONNECTOR break HDMI output, infoframes and audio with the nxp,tda998x bridge used on Arm Morello SDP (arch/arm64/boot/dts/arm/morello-sdp.dts)?
When attached with DRM_BRIDGE_ATTACH_NO_CONNECTOR, tda998x_bridge_attach() skips tda998x_connector_init() and leaves priv->connector zeroed, while drm_edid_connector_update() populates display_info on the newly created drm_bridge_connector instead. However, tda998x_bridge_mode_set() still reads display_info from its internal priv->connector:
drivers/gpu/drm/bridge/tda998x_drv.c:tda998x_bridge_mode_set() {
...
priv->supports_infoframes = priv->connector.display_info.cea_rev >= 3;
...
}Because priv->connector.display_info.cea_rev remains 0, priv->supports_infoframes is always false, forcing the transmitter into DVI mode and disabling AVI/VSI infoframes and HDMI audio.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH 2/2 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
[email protected]
AI reviewRe: [PATCH 2/2] drm/komeda: Use drmm_mode_config_init()
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [High] drm/komeda: null pointer dereference in…
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [High] drm/komeda: null pointer dereference in komeda_kms_irq_handler() [1]
--
commit 0e65e87085171dcf76021a4ce18f9f49413797fc
Author: Luo Liu <[email protected]>
drm/komeda: Use drmm_mode_config_init()
This commit switches komeda to drmm_mode_config_init(), drops explicit drm_mode_config_cleanup() calls, and updates komeda_kms_cleanup_private_objs() to walk pipelines instead of mode_config.privobj_list.
Quoted 4 lines
drivers/gpu/drm/arm/display/komeda/komeda_kms.c +0
-0
[ ... ]
Quoted 25 lines
drivers/gpu/drm/arm/display/komeda/komeda_kms.c +3
-4@@ -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;
drivers/gpu/drm/arm/display/komeda/komeda_kms.c struct komeda_kms_dev *komeda_kms_attach(struct komeda_dev *mdev) · line 353
Quoted 10 lines
drivers/gpu/drm/arm/display/komeda/komeda_kms.c +2
-2+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 ; }
[Severity: High]
This problem wasn't introduced by this patch, but can clearing drm->dev_private here cause a NULL pointer dereference in komeda_kms_irq_handler() [1]?
The IRQ is registered with IRQF_SHARED via devm_request_irq(), so it stays active until devres cleanup runs after komeda_kms_attach() fails or komeda_kms_detach() returns. If another device on the shared line raises an interrupt after drm->dev_private is set to NULL, komeda_kms_irq_handler() dereferences mdev:
drivers/gpu/drm/arm/display/komeda/komeda_kms.c:komeda_kms_irq_handler() {
struct drm_device *drm = data;
struct komeda_dev *mdev = drm->dev_private;
...
status = mdev->funcs->irq_handler(mdev, &evts);
}[1] https://sashiko.dev/#/bug/linux-7f3e9b9f-7fcd-447d-9114-8e6de2954834
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2