]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/bridge: panel: convert to devm_drm_bridge_alloc() API
authorLuca Ceresoli <luca.ceresoli@bootlin.com>
Fri, 9 May 2025 13:53:47 +0000 (15:53 +0200)
committerLuca Ceresoli <luca.ceresoli@bootlin.com>
Wed, 21 May 2025 11:40:09 +0000 (13:40 +0200)
This is the new API for allocating DRM bridges.

The devm lifetime management of this driver is peculiar. The underlying
device for the panel_bridge is the panel, and the devm lifetime is tied the
panel device (panel->dev). However the panel_bridge allocation is not
performed by the panel driver, but rather by a separate entity (typically
the previous bridge in the encoder chain).

Thus when that separate entity is destroyed, the panel_bridge is not
removed automatically by devm, so it is rather done explicitly by calling
drm_panel_bridge_remove(). This is the function that does devm_kfree() the
panel_bridge in current code, so update it as well to put the bridge
reference instead.

This is a temporary solution until the panel lifetime is reworked, which
should make this workaround unnecessary, so add a comment to clarify that.

Acked-by: Maxime Ripard <mripard@kernel.org>
Link: https://lore.kernel.org/r/20250509-drm-bridge-convert-to-alloc-api-v3-21-b8bc1f16d7aa@bootlin.com
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
drivers/gpu/drm/bridge/panel.c

index 79b009ab9396048eac57ad47631a902e949d77c6..6cbbfb1381a4a75fbc3acf6e6c5361202627e740 100644 (file)
@@ -287,15 +287,14 @@ struct drm_bridge *drm_panel_bridge_add_typed(struct drm_panel *panel,
        if (!panel)
                return ERR_PTR(-EINVAL);
 
-       panel_bridge = devm_kzalloc(panel->dev, sizeof(*panel_bridge),
-                                   GFP_KERNEL);
-       if (!panel_bridge)
-               return ERR_PTR(-ENOMEM);
+       panel_bridge = devm_drm_bridge_alloc(panel->dev, struct panel_bridge, bridge,
+                                            &panel_bridge_bridge_funcs);
+       if (IS_ERR(panel_bridge))
+               return (void *)panel_bridge;
 
        panel_bridge->connector_type = connector_type;
        panel_bridge->panel = panel;
 
-       panel_bridge->bridge.funcs = &panel_bridge_bridge_funcs;
        panel_bridge->bridge.of_node = panel->dev->of_node;
        panel_bridge->bridge.ops = DRM_BRIDGE_OP_MODES;
        panel_bridge->bridge.type = connector_type;
@@ -327,7 +326,8 @@ void drm_panel_bridge_remove(struct drm_bridge *bridge)
        panel_bridge = drm_bridge_to_panel_bridge(bridge);
 
        drm_bridge_remove(bridge);
-       devm_kfree(panel_bridge->panel->dev, bridge);
+       /* TODO remove this after reworking panel_bridge lifetime */
+       devm_drm_put_bridge(panel_bridge->panel->dev, bridge);
 }
 EXPORT_SYMBOL(drm_panel_bridge_remove);