drm/imx: use for_each_endpoint_of_node macro in imx_drm_encoder_get_mux_id
authorPhilipp Zabel <p.zabel@pengutronix.de>
Thu, 3 Jul 2014 21:07:49 +0000 (23:07 +0200)
committerPhilipp Zabel <p.zabel@pengutronix.de>
Wed, 8 Apr 2015 09:14:26 +0000 (11:14 +0200)
Using the for_each_... macro should make the code bit shorter and
easier to read. This patch also properly decrements the endpoint node
reference count before returning out of the loop.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
drivers/gpu/drm/imx/imx-drm-core.c

index 84cf99f8d957ae1218412066346aece4b77e9dd4..db2f5a739e058f6096a6a41911a6fdf1386766a3 100644 (file)
@@ -439,7 +439,7 @@ int imx_drm_encoder_get_mux_id(struct device_node *node,
                               struct drm_encoder *encoder)
 {
        struct imx_drm_crtc *imx_crtc = imx_drm_find_crtc(encoder->crtc);
-       struct device_node *ep = NULL;
+       struct device_node *ep;
        struct of_endpoint endpoint;
        struct device_node *port;
        int ret;
@@ -447,18 +447,15 @@ int imx_drm_encoder_get_mux_id(struct device_node *node,
        if (!node || !imx_crtc)
                return -EINVAL;
 
-       do {
-               ep = of_graph_get_next_endpoint(node, ep);
-               if (!ep)
-                       break;
-
+       for_each_endpoint_of_node(node, ep) {
                port = of_graph_get_remote_port(ep);
                of_node_put(port);
                if (port == imx_crtc->crtc->port) {
                        ret = of_graph_parse_endpoint(ep, &endpoint);
+                       of_node_put(ep);
                        return ret ? ret : endpoint.port;
                }
-       } while (ep);
+       }
 
        return -EINVAL;
 }