imx8qxp_pixel_link_find_next_bridge() uses a sophisticated logic to find
the preferred next bridge, using an array with two supporting index
variables. This is more sophisticated than required because we only ever
need a pointer to the "current" bridge and to the "best so far" bridge.

Additionally this logic is going to make the addition of proper refcounting
quite complex.

Rewrite the logic using two drm_bridge pointers, which is by itself
slightly simpler and is a preparation step for introducing bridge
refcounting in a later commit.

Also reword a comment to make it clearer.

Signed-off-by: Luca Ceresoli <[email protected]>

---

Cc: Liu Ying <[email protected]>
---
 drivers/gpu/drm/bridge/imx/imx8qxp-pixel-link.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/bridge/imx/imx8qxp-pixel-link.c 
b/drivers/gpu/drm/bridge/imx/imx8qxp-pixel-link.c
index e5943506981d..53016f0d53a0 100644
--- a/drivers/gpu/drm/bridge/imx/imx8qxp-pixel-link.c
+++ b/drivers/gpu/drm/bridge/imx/imx8qxp-pixel-link.c
@@ -261,12 +261,10 @@ imx8qxp_pixel_link_find_next_bridge(struct 
imx8qxp_pixel_link *pl)
 {
        struct device_node *np = pl->dev->of_node;
        struct device_node *port, *remote;
-       struct drm_bridge *next_bridge[PL_MAX_NEXT_BRIDGES];
+       struct drm_bridge *selected_bridge = NULL;
        u32 port_id;
        bool found_port = false;
-       int reg, ep_cnt = 0;
-       /* select the first next bridge by default */
-       int bridge_sel = 0;
+       int reg;
 
        for (port_id = 1; port_id <= PL_MAX_MST_ADDR + 1; port_id++) {
                port = of_graph_get_port_by_id(np, port_id);
@@ -300,24 +298,25 @@ imx8qxp_pixel_link_find_next_bridge(struct 
imx8qxp_pixel_link *pl)
                        continue;
                }
 
-               next_bridge[ep_cnt] = of_drm_find_bridge(remote);
-               if (!next_bridge[ep_cnt]) {
+               struct drm_bridge *next_bridge = of_drm_find_bridge(remote);
+               if (!next_bridge) {
                        of_node_put(remote);
                        return ERR_PTR(-EPROBE_DEFER);
                }
 
-               /* specially select the next bridge with companion PXL2DPI */
-               if (of_property_present(remote, "fsl,companion-pxl2dpi"))
-                       bridge_sel = ep_cnt;
-
-               ep_cnt++;
+               /*
+                * Select the next bridge with companion PXL2DPI if
+                * present, otherwise default to the first bridge
+                */
+               if (!selected_bridge || of_property_present(remote, 
"fsl,companion-pxl2dpi"))
+                       selected_bridge = next_bridge;
 
                of_node_put(remote);
        }
 
        pl->mst_addr = port_id - 1;
 
-       return next_bridge[bridge_sel];
+       return selected_bridge;
 }
 
 static int imx8qxp_pixel_link_bridge_probe(struct platform_device *pdev)

-- 
2.51.1

Reply via email to