[PATCH 2/8] drm/mxsfb/lcdif: don't unnecessarily loop over ports

Luca Ceresoli
2026-03-20T10:46:58Z

According to the bindings [0] there can be only one port. The in-tree board
device trees also don't contain multiple ports (searched thos matching
'fsl,imx(23|28|6sx|8mp|93)-lcdif').

Avoid an unnecessary loop around multipltle ports. This allows to greatly
simplify the code.

[0] Documentation/devicetree/bindings/display/fsl,lcdif.yaml

Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>

---

Viewing this patch with '--ignore-all-space' is recommended
---
drivers/gpu/drm/mxsfb/lcdif_drv.c | 77 ++++++++++++++-------------------------
1 file changed, 27 insertions(+), 50 deletions(-)

diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.c b/drivers/gpu/drm/mxsfb/lcdif_drv.c
index 756ca96373c8..83e134c04882 100644
--- a/drivers/gpu/drm/mxsfb/lcdif_drv.c
+++ b/drivers/gpu/drm/mxsfb/lcdif_drv.c
@@ -48,61 +48,38 @@ static const struct drm_encoder_funcs lcdif_encoder_funcs = {
static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif)
{
struct device *dev = lcdif->drm->dev;
- struct device_node *ep;
+ struct drm_encoder *encoder;
struct drm_bridge *bridge;
int ret;

- for_each_endpoint_of_node(dev->of_node, ep) {
- struct device_node *remote __free(drm_bridge_put) =
- of_graph_get_remote_port_parent(ep);
- struct of_endpoint of_ep;
- struct drm_encoder *encoder;
-
- if (!of_device_is_available(remote))
- continue;
-
- ret = of_graph_parse_endpoint(ep, &of_ep);
- if (ret < 0) {
- dev_err(dev, "Failed to parse endpoint %pOF\n", ep);
- of_node_put(ep);
- return ret;
- }
-
- bridge = devm_drm_of_get_bridge(dev, dev->of_node, 0, of_ep.id);
- if (IS_ERR(bridge)) {
- of_node_put(ep);
- return dev_err_probe(dev, PTR_ERR(bridge),
- "Failed to get bridge for endpoint%u\n",
- of_ep.id);
- }
-
- encoder = devm_kzalloc(dev, sizeof(*encoder), GFP_KERNEL);
- if (!encoder) {
- dev_err(dev, "Failed to allocate encoder for endpoint%u\n",
- of_ep.id);
- of_node_put(ep);
- return -ENOMEM;
- }
-
- encoder->possible_crtcs = drm_crtc_mask(&lcdif->crtc);
- ret = drm_encoder_init(lcdif->drm, encoder, &lcdif_encoder_funcs,
- DRM_MODE_ENCODER_NONE, NULL);
- if (ret) {
- dev_err(dev, "Failed to initialize encoder for endpoint%u: %d\n",
- of_ep.id, ret);
- of_node_put(ep);
- return ret;
- }
-
- ret = drm_bridge_attach(encoder, bridge, NULL, 0);
- if (ret) {
- of_node_put(ep);
- return dev_err_probe(dev, ret,
- "Failed to attach bridge for endpoint%u\n",
- of_ep.id);
- }
+ struct device_node *remote __free(device_node) =
+ of_graph_get_remote_node(dev->of_node, 0, -1);
+
+ if (!of_device_is_available(remote))
+ return 0;
+
+ bridge = devm_drm_of_get_bridge(dev, dev->of_node, 0, -1);
+ if (IS_ERR(bridge))
+ return dev_err_probe(dev, PTR_ERR(bridge), "Failed to get bridge\n");
+
+ encoder = devm_kzalloc(dev, sizeof(*encoder), GFP_KERNEL);
+ if (!encoder) {
+ dev_err(dev, "Failed to allocate encoder\n");
+ return -ENOMEM;
}

+ encoder->possible_crtcs = drm_crtc_mask(&lcdif->crtc);
+ ret = drm_encoder_init(lcdif->drm, encoder, &lcdif_encoder_funcs,
+ DRM_MODE_ENCODER_NONE, NULL);
+ if (ret) {
+ dev_err(dev, "Failed to initialize encoder: %d\n", ret);
+ return ret;
+ }
+
+ ret = drm_bridge_attach(encoder, bridge, NULL, 0);
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed to attach bridge\n");
+
return 0;
}

--
2.53.0