Commit f033c0bc authored by Philipp Zabel's avatar Philipp Zabel

of: Decrement refcount of previous endpoint in of_graph_get_next_endpoint

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: default avatarPhilipp Zabel <p.zabel@pengutronix.de>
Acked-by: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: default avatarMathieu Poirier <mathieu.poirier@linaro.org>
Acked-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: default avatarTomi Valkeinen <tomi.valkeinen@ti.com>
parent c517d838
...@@ -52,15 +52,6 @@ of_coresight_get_endpoint_device(struct device_node *endpoint) ...@@ -52,15 +52,6 @@ of_coresight_get_endpoint_device(struct device_node *endpoint)
endpoint, of_dev_node_match); 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, static void of_coresight_get_ports(struct device_node *node,
int *nr_inport, int *nr_outport) int *nr_inport, int *nr_outport)
{ {
...@@ -68,7 +59,7 @@ static void of_coresight_get_ports(struct device_node *node, ...@@ -68,7 +59,7 @@ static void of_coresight_get_ports(struct device_node *node,
int in = 0, out = 0; int in = 0, out = 0;
do { do {
ep = of_get_coresight_endpoint(node, ep); ep = of_graph_get_next_endpoint(node, ep);
if (!ep) if (!ep)
break; break;
...@@ -140,7 +131,7 @@ struct coresight_platform_data *of_get_coresight_platform_data( ...@@ -140,7 +131,7 @@ struct coresight_platform_data *of_get_coresight_platform_data(
/* Iterate through each port to discover topology */ /* Iterate through each port to discover topology */
do { do {
/* Get a handle on a port */ /* Get a handle on a port */
ep = of_get_coresight_endpoint(node, ep); ep = of_graph_get_next_endpoint(node, ep);
if (!ep) if (!ep)
break; break;
......
...@@ -431,15 +431,6 @@ int imx_drm_encoder_parse_of(struct drm_device *drm, ...@@ -431,15 +431,6 @@ int imx_drm_encoder_parse_of(struct drm_device *drm,
} }
EXPORT_SYMBOL_GPL(imx_drm_encoder_parse_of); 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 * @node: device tree node containing encoder input ports
* @encoder: drm_encoder * @encoder: drm_encoder
...@@ -457,7 +448,7 @@ int imx_drm_encoder_get_mux_id(struct device_node *node, ...@@ -457,7 +448,7 @@ int imx_drm_encoder_get_mux_id(struct device_node *node,
return -EINVAL; return -EINVAL;
do { do {
ep = imx_drm_of_get_next_endpoint(node, ep); ep = of_graph_get_next_endpoint(node, ep);
if (!ep) if (!ep)
break; break;
......
...@@ -206,7 +206,7 @@ static int rcar_du_encoders_init_one(struct rcar_du_device *rcdu, ...@@ -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; enum rcar_du_encoder_type enc_type = RCAR_DU_ENCODER_NONE;
struct device_node *connector = NULL; struct device_node *connector = NULL;
struct device_node *encoder = 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_ep_node;
struct device_node *entity; struct device_node *entity;
int ret; int ret;
...@@ -225,11 +225,7 @@ static int rcar_du_encoders_init_one(struct rcar_du_device *rcdu, ...@@ -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); entity_ep_node = of_parse_phandle(ep->local_node, "remote-endpoint", 0);
while (1) { while (1) {
struct device_node *ep_node; ep_node = of_graph_get_next_endpoint(entity, ep_node);
ep_node = of_graph_get_next_endpoint(entity, prev);
of_node_put(prev);
prev = ep_node;
if (!ep_node) if (!ep_node)
break; break;
...@@ -300,7 +296,7 @@ static int rcar_du_encoders_init_one(struct rcar_du_device *rcdu, ...@@ -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) static int rcar_du_encoders_init(struct rcar_du_device *rcdu)
{ {
struct device_node *np = rcdu->dev->of_node; struct device_node *np = rcdu->dev->of_node;
struct device_node *prev = NULL; struct device_node *ep_node = NULL;
unsigned int num_encoders = 0; unsigned int num_encoders = 0;
/* /*
...@@ -308,15 +304,12 @@ static int rcar_du_encoders_init(struct rcar_du_device *rcdu) ...@@ -308,15 +304,12 @@ static int rcar_du_encoders_init(struct rcar_du_device *rcdu)
* pipeline. * pipeline.
*/ */
while (1) { while (1) {
struct device_node *ep_node;
enum rcar_du_output output; enum rcar_du_output output;
struct of_endpoint ep; struct of_endpoint ep;
unsigned int i; unsigned int i;
int ret; int ret;
ep_node = of_graph_get_next_endpoint(np, prev); ep_node = of_graph_get_next_endpoint(np, ep_node);
of_node_put(prev);
prev = ep_node;
if (ep_node == NULL) if (ep_node == NULL)
break; break;
......
...@@ -2504,7 +2504,6 @@ vpfe_get_pdata(struct platform_device *pdev) ...@@ -2504,7 +2504,6 @@ vpfe_get_pdata(struct platform_device *pdev)
GFP_KERNEL); GFP_KERNEL);
pdata->asd[i]->match_type = V4L2_ASYNC_MATCH_OF; pdata->asd[i]->match_type = V4L2_ASYNC_MATCH_OF;
pdata->asd[i]->match.of.node = rem; pdata->asd[i]->match.of.node = rem;
of_node_put(endpoint);
of_node_put(rem); of_node_put(rem);
} }
......
...@@ -1694,7 +1694,6 @@ static void scan_of_host(struct soc_camera_host *ici) ...@@ -1694,7 +1694,6 @@ static void scan_of_host(struct soc_camera_host *ici)
if (!i) if (!i)
soc_of_bind(ici, epn, ren->parent); soc_of_bind(ici, epn, ren->parent);
of_node_put(epn);
of_node_put(ren); of_node_put(ren);
if (i) { if (i) {
...@@ -1702,6 +1701,8 @@ static void scan_of_host(struct soc_camera_host *ici) ...@@ -1702,6 +1701,8 @@ static void scan_of_host(struct soc_camera_host *ici)
break; break;
} }
} }
of_node_put(epn);
} }
#else #else
......
...@@ -2086,8 +2086,7 @@ EXPORT_SYMBOL(of_graph_parse_endpoint); ...@@ -2086,8 +2086,7 @@ EXPORT_SYMBOL(of_graph_parse_endpoint);
* @prev: previous endpoint node, or NULL to get first * @prev: previous endpoint node, or NULL to get first
* *
* Return: An 'endpoint' node pointer with refcount incremented. Refcount * Return: An 'endpoint' node pointer with refcount incremented. Refcount
* of the passed @prev node is not decremented, the caller have to use * of the passed @prev node is decremented.
* of_node_put() on it when done.
*/ */
struct device_node *of_graph_get_next_endpoint(const struct device_node *parent, struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
struct device_node *prev) struct device_node *prev)
...@@ -2123,12 +2122,6 @@ struct device_node *of_graph_get_next_endpoint(const struct device_node *parent, ...@@ -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", if (WARN_ONCE(!port, "%s(): endpoint %s has no parent node\n",
__func__, prev->full_name)) __func__, prev->full_name))
return NULL; return NULL;
/*
* Avoid dropping prev node refcount to 0 when getting the next
* child below.
*/
of_node_get(prev);
} }
while (1) { while (1) {
......
...@@ -164,20 +164,15 @@ static void __init omapdss_walk_device(struct device_node *node, bool root) ...@@ -164,20 +164,15 @@ static void __init omapdss_walk_device(struct device_node *node, bool root)
pn = of_graph_get_remote_port_parent(n); pn = of_graph_get_remote_port_parent(n);
if (!pn) { if (!pn)
of_node_put(n);
continue; continue;
}
if (!of_device_is_available(pn) || omapdss_list_contains(pn)) { if (!of_device_is_available(pn) || omapdss_list_contains(pn)) {
of_node_put(pn); of_node_put(pn);
of_node_put(n);
continue; continue;
} }
omapdss_walk_device(pn, false); omapdss_walk_device(pn, false);
of_node_put(n);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment