From 96476ab8690290aa27084b12a481e48f3af7afb2 Mon Sep 17 00:00:00 2001 From: Luca Ceresoli Date: Wed, 7 Jan 2026 10:56:26 +0100 Subject: [PATCH] drm/bridge: imx8qxp-pixel-link: simplify logic to find next bridge 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. Reviewed-by: Liu Ying Link: https://patch.msgid.link/20260107-drm-bridge-alloc-getput-drm_of_find_bridge-v4-1-a62b4399a6bf@bootlin.com Signed-off-by: Luca Ceresoli --- .../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 433c080197a2..4f84825fddca 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)