By the documentation drm_of_find_panel_or_bridge() returns a "drm_panel or
drm_bridge", without specifying which one is returned in case both exist.

Definitely it never returns both. If both exist (and @bridge is != NULL),
the current implementation prioritizes the drm_panel pointer and returns
that. In most cases (including devm_drm_of_get_bridge() and
drmm_of_get_bridge()) this is used to implement the following logic
(simplified):

    drm_of_find_panel_or_bridge(..., &panel, &bridge);
    if (panel)
        bridge = [devm_]drm_panel_bridge_add[_typed](panel);

Work is in progress to make every drm_panel automatically create a
panel_bridge, so a panel_bridge will always be present for every
drm_panel. This means the above logic would create a panel_bridge that
already exists. Avoid it by returning the drm_bridge when both are present,
instead of the drm_panel.

For the case where @bridge == NULL, this commit does not change anything:
the 'if (bridge)' body is never executed and the drm_panel (if found) is
always returned.

Signed-off-by: Luca Ceresoli <[email protected]>
---
 drivers/gpu/drm/drm_of.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/drm_of.c b/drivers/gpu/drm/drm_of.c
index 8ec352f3df93..f92f02f9b202 100644
--- a/drivers/gpu/drm/drm_of.c
+++ b/drivers/gpu/drm/drm_of.c
@@ -308,14 +308,7 @@ int drm_of_find_panel_or_bridge(const struct device_node 
*np,
        if (!remote)
                return -ENODEV;
 
-       *panel = of_drm_find_panel(remote);
-       if (!IS_ERR(*panel))
-               return 0;
-
-       *panel = NULL;
-
        if (bridge) {
-               /* No panel found yet, check for a bridge next. */
                *bridge = of_drm_find_bridge(remote);
                if (*bridge)
                        return 0;
@@ -323,6 +316,13 @@ int drm_of_find_panel_or_bridge(const struct device_node 
*np,
                *bridge = NULL;
        }
 
+       /* No bridge found yet, check for a panel next. */
+       *panel = of_drm_find_panel(remote);
+       if (!IS_ERR(*panel))
+               return 0;
+
+       *panel = NULL;
+
        return -EPROBE_DEFER;
 }
 EXPORT_SYMBOL_GPL(drm_of_find_panel_or_bridge);

-- 
2.55.0

Reply via email to