]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm: renesas: rz-du: rzg2l_du_encoder: convert to of_drm_find_and_get_bridge()
authorLuca Ceresoli <luca.ceresoli@bootlin.com>
Thu, 9 Apr 2026 13:23:28 +0000 (15:23 +0200)
committerLuca Ceresoli <luca.ceresoli@bootlin.com>
Thu, 16 Apr 2026 08:14:43 +0000 (10:14 +0200)
of_drm_find_bridge() is deprecated. Move to its replacement
of_drm_find_and_get_bridge() which gets a bridge reference, and ensure it
is put when done.

This is made somewhat simpler by the fact that 'bridge' is a local
variable.

However we need to handle both branches of the main if().

In the 'else' case, just switch to of_drm_find_and_get_bridge() to ensure
the bridge is not freed while in use in the function tail
(drm_bridge_attach() mainly).

In the 'then' case, devm_drm_panel_bridge_add_typed() already increments
the refcount using devres which ties the bridge allocation lifetime to the
device lifetime, so we would not need to do anything. However to have the
same behaviour in both branches take an additional reference here, so that
the bridge needs to be put whichever branch is taken without more
complicated logic.

Reviewed-by: Biju Das <biju.das.jz@bp.renesas.com>
Tested-by: Biju Das <biju.das.jz@bp.renesas.com>
Reviewed-by: Linus Walleij <linusw@kernel.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
Link: https://patch.msgid.link/20260409-drm-bridge-alloc-getput-drm_of_find_bridge-4-v5-1-d7381c07788a@bootlin.com
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
drivers/gpu/drm/renesas/rz-du/rzg2l_du_encoder.c

index 5e6dd16705e60a196f607819336ed41135fdec44..d53068733c66f2709deb7e9eb49d8c1acad73f35 100644 (file)
@@ -67,7 +67,7 @@ int rzg2l_du_encoder_init(struct rzg2l_du_device  *rcdu,
 {
        struct rzg2l_du_encoder *renc;
        struct drm_connector *connector;
-       struct drm_bridge *bridge;
+       struct drm_bridge *bridge __free(drm_bridge_put) = NULL;
        int ret;
 
        /*
@@ -84,9 +84,16 @@ int rzg2l_du_encoder_init(struct rzg2l_du_device  *rcdu,
                bridge = devm_drm_panel_bridge_add_typed(rcdu->dev, panel,
                                                         DRM_MODE_CONNECTOR_DPI);
                if (IS_ERR(bridge))
-                       return PTR_ERR(bridge);
+                       return PTR_ERR(no_free_ptr(bridge));
+
+               /*
+                * The reference taken by devm_drm_panel_bridge_add_typed() is
+                * released automatically. Take a second one for the __free()
+                * when this function will return.
+                */
+               drm_bridge_get(bridge);
        } else {
-               bridge = of_drm_find_bridge(enc_node);
+               bridge = of_drm_find_and_get_bridge(enc_node);
                if (!bridge)
                        return -EPROBE_DEFER;
        }