of: Decrement refcount of previous endpoint in of_graph_get_next_endpoint
authorPhilipp Zabel <p.zabel@pengutronix.de>
Mon, 1 Dec 2014 12:32:32 +0000 (13:32 +0100)
committerPhilipp Zabel <p.zabel@pengutronix.de>
Mon, 23 Feb 2015 10:42:23 +0000 (11:42 +0100)
Decrementing the reference count of the previous endpoint node allows to
use the of_graph_get_next_endpoint function in a for_each_... style macro.
All current users of this function that pass a non-NULL prev parameter
(that is, soc_camera and imx-drm) are changed to not decrement the passed
prev argument's refcount themselves.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Acked-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
drivers/coresight/of_coresight.c
drivers/gpu/drm/imx/imx-drm-core.c
drivers/gpu/drm/rcar-du/rcar_du_kms.c
drivers/media/platform/am437x/am437x-vpfe.c
drivers/media/platform/soc_camera/soc_camera.c
drivers/of/base.c
drivers/video/fbdev/omap2/dss/omapdss-boot-init.c

index c3efa418a86d8eda8f715cecd97382deb965a8e8..6f75e9d5b6fb0755d41b3e252daea83179efb4b6 100644 (file)
@@ -52,15 +52,6 @@ of_coresight_get_endpoint_device(struct device_node *endpoint)
                               endpoint, of_dev_node_match);
 }
 
-static struct device_node *of_get_coresight_endpoint(
-               const struct device_node *parent, struct device_node *prev)
-{
-       struct device_node *node = of_graph_get_next_endpoint(parent, prev);
-
-       of_node_put(prev);
-       return node;
-}
-
 static void of_coresight_get_ports(struct device_node *node,
                                   int *nr_inport, int *nr_outport)
 {
@@ -68,7 +59,7 @@ static void of_coresight_get_ports(struct device_node *node,
        int in = 0, out = 0;
 
        do {
-               ep = of_get_coresight_endpoint(node, ep);
+               ep = of_graph_get_next_endpoint(node, ep);
                if (!ep)
                        break;
 
@@ -140,7 +131,7 @@ struct coresight_platform_data *of_get_coresight_platform_data(
                /* Iterate through each port to discover topology */
                do {
                        /* Get a handle on a port */
-                       ep = of_get_coresight_endpoint(node, ep);
+                       ep = of_graph_get_next_endpoint(node, ep);
                        if (!ep)
                                break;
 
index a002f53aab0e3a3654a722f218be7854ffb70cd4..84cf99f8d957ae1218412066346aece4b77e9dd4 100644 (file)
@@ -431,15 +431,6 @@ int imx_drm_encoder_parse_of(struct drm_device *drm,
 }
 EXPORT_SYMBOL_GPL(imx_drm_encoder_parse_of);
 
-static struct device_node *imx_drm_of_get_next_endpoint(
-               const struct device_node *parent, struct device_node *prev)
-{
-       struct device_node *node = of_graph_get_next_endpoint(parent, prev);
-
-       of_node_put(prev);
-       return node;
-}
-
 /*
  * @node: device tree node containing encoder input ports
  * @encoder: drm_encoder
@@ -457,7 +448,7 @@ int imx_drm_encoder_get_mux_id(struct device_node *node,
                return -EINVAL;
 
        do {
-               ep = imx_drm_of_get_next_endpoint(node, ep);
+               ep = of_graph_get_next_endpoint(node, ep);
                if (!ep)
                        break;
 
index cc9136e8ee9cd2f73c65850215fad60a584358ee..68dab2601bf54a8e44dda63c87341ff558bec3e1 100644 (file)
@@ -206,7 +206,7 @@ static int rcar_du_encoders_init_one(struct rcar_du_device *rcdu,
        enum rcar_du_encoder_type enc_type = RCAR_DU_ENCODER_NONE;
        struct device_node *connector = NULL;
        struct device_node *encoder = NULL;
-       struct device_node *prev = NULL;
+       struct device_node *ep_node = NULL;
        struct device_node *entity_ep_node;
        struct device_node *entity;
        int ret;
@@ -225,11 +225,7 @@ static int rcar_du_encoders_init_one(struct rcar_du_device *rcdu,
        entity_ep_node = of_parse_phandle(ep->local_node, "remote-endpoint", 0);
 
        while (1) {
-               struct device_node *ep_node;
-
-               ep_node = of_graph_get_next_endpoint(entity, prev);
-               of_node_put(prev);
-               prev = ep_node;
+               ep_node = of_graph_get_next_endpoint(entity, ep_node);
 
                if (!ep_node)
                        break;
@@ -300,7 +296,7 @@ static int rcar_du_encoders_init_one(struct rcar_du_device *rcdu,
 static int rcar_du_encoders_init(struct rcar_du_device *rcdu)
 {
        struct device_node *np = rcdu->dev->of_node;
-       struct device_node *prev = NULL;
+       struct device_node *ep_node = NULL;
        unsigned int num_encoders = 0;
 
        /*
@@ -308,15 +304,12 @@ static int rcar_du_encoders_init(struct rcar_du_device *rcdu)
         * pipeline.
         */
        while (1) {
-               struct device_node *ep_node;
                enum rcar_du_output output;
                struct of_endpoint ep;
                unsigned int i;
                int ret;
 
-               ep_node = of_graph_get_next_endpoint(np, prev);
-               of_node_put(prev);
-               prev = ep_node;
+               ep_node = of_graph_get_next_endpoint(np, ep_node);
 
                if (ep_node == NULL)
                        break;
index 56a5cb0d215203f242b55e7609c4ddf6e7b4bc8f..0d07fca756fee2e8b5b8680b945ff3c2bed188ef 100644 (file)
@@ -2504,7 +2504,6 @@ vpfe_get_pdata(struct platform_device *pdev)
                                             GFP_KERNEL);
                pdata->asd[i]->match_type = V4L2_ASYNC_MATCH_OF;
                pdata->asd[i]->match.of.node = rem;
-               of_node_put(endpoint);
                of_node_put(rem);
        }
 
index cee7b56f840499440142bc598fbd588bd8469f67..f2a3d960b1a60f63dc9586e4f591d9a1574ea8a2 100644 (file)
@@ -1694,7 +1694,6 @@ static void scan_of_host(struct soc_camera_host *ici)
                if (!i)
                        soc_of_bind(ici, epn, ren->parent);
 
-               of_node_put(epn);
                of_node_put(ren);
 
                if (i) {
@@ -1702,6 +1701,8 @@ static void scan_of_host(struct soc_camera_host *ici)
                        break;
                }
        }
+
+       of_node_put(epn);
 }
 
 #else
index 0a8aeb8523fe7d54a66207f25eb145e88addb90d..05b20f1cca7b31928d575f06570d1e23df11be91 100644 (file)
@@ -2086,8 +2086,7 @@ EXPORT_SYMBOL(of_graph_parse_endpoint);
  * @prev: previous endpoint node, or NULL to get first
  *
  * Return: An 'endpoint' node pointer with refcount incremented. Refcount
- * of the passed @prev node is not decremented, the caller have to use
- * of_node_put() on it when done.
+ * of the passed @prev node is decremented.
  */
 struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
                                        struct device_node *prev)
@@ -2123,12 +2122,6 @@ struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
                if (WARN_ONCE(!port, "%s(): endpoint %s has no parent node\n",
                              __func__, prev->full_name))
                        return NULL;
-
-               /*
-                * Avoid dropping prev node refcount to 0 when getting the next
-                * child below.
-                */
-               of_node_get(prev);
        }
 
        while (1) {
index 42b87f95267c255f26bce067615607021eca99cd..8b6f6d5fdd68bc442449d4e4d5a5ea1ce9a85f41 100644 (file)
@@ -164,20 +164,15 @@ static void __init omapdss_walk_device(struct device_node *node, bool root)
 
                pn = of_graph_get_remote_port_parent(n);
 
-               if (!pn) {
-                       of_node_put(n);
+               if (!pn)
                        continue;
-               }
 
                if (!of_device_is_available(pn) || omapdss_list_contains(pn)) {
                        of_node_put(pn);
-                       of_node_put(n);
                        continue;
                }
 
                omapdss_walk_device(pn, false);
-
-               of_node_put(n);
        }
 }