* [PATCH v2 0/8] Add of-graph helpers to loop over endpoints and find ports by id
@ 2014-09-10 10:58 Philipp Zabel
2014-09-10 10:58 ` [PATCH v2 1/8] [media] soc_camera: Do not decrement endpoint node refcount in the loop Philipp Zabel
` (7 more replies)
0 siblings, 8 replies; 12+ messages in thread
From: Philipp Zabel @ 2014-09-10 10:58 UTC (permalink / raw)
To: linux-kernel
Cc: linux-media, devel, Grant Likely, Greg Kroah-Hartman,
Guennadi Liakhovetski, Laurent Pinchart, Mauro Carvalho Chehab,
Russell King, kernel, Philipp Zabel
Hi,
this series converts all existing users of of_graph_get_next_endpoint that pass
a non-NULL prev argument to the function and decrement its refcount themselves
to stop doing that. The of_node_put is moved into of_graph_get_next_endpoint
instead.
This allows to add a for_each_endpoint_of_node helper macro to loop over all
endpoints in a device tree node.
The third of patch adds a of_graph_get_port_by_id function to retrieve a port
by its known port id from the device tree.
Finally, the last three patches convert functions in drm_of.c and imx-drm-core.c
to use the for_each_endpoint_of_node macro instead of of_graph_get_next_endpoint.
Changes since v1:
- Added a comment about the child node reference count when breaking out
of the loop of for_each_endpoint_of_node.
- Changed id parameter to of_graph_get_port_by_id to u32
- Simplified of_graph_get_port_by_id as suggested by Laurent,
making use of port id defaulting to 0 if no "reg" property is given.
- Added Laurent's ack to drm_of_find_possible_crtcs patch
The previous version can be found here: https://lkml.org/lkml/2014/8/19/280
regards
Philipp
Philipp Zabel (8):
[media] soc_camera: Do not decrement endpoint node refcount in the
loop
imx-drm: Do not decrement endpoint node refcount in the loop
of: Decrement refcount of previous endpoint in
of_graph_get_next_endpoint
of: Add for_each_endpoint_of_node helper macro
of: Add of_graph_get_port_by_id function
drm: use for_each_endpoint_of_node macro in drm_of_find_possible_crtcs
imx-drm: use for_each_endpoint_of_node macro in
imx_drm_encoder_get_mux_id
imx-drm: use for_each_endpoint_of_node macro in
imx_drm_encoder_parse_of
drivers/gpu/drm/drm_of.c | 8 ++----
drivers/media/platform/soc_camera/soc_camera.c | 2 +-
drivers/of/base.c | 35 ++++++++++++++++++++------
drivers/staging/imx-drm/imx-drm-core.c | 34 ++++++++-----------------
include/linux/of_graph.h | 18 +++++++++++++
5 files changed, 58 insertions(+), 39 deletions(-)
--
2.1.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2 1/8] [media] soc_camera: Do not decrement endpoint node refcount in the loop
2014-09-10 10:58 [PATCH v2 0/8] Add of-graph helpers to loop over endpoints and find ports by id Philipp Zabel
@ 2014-09-10 10:58 ` Philipp Zabel
2014-09-10 10:58 ` [PATCH v2 2/8] imx-drm: " Philipp Zabel
` (6 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Philipp Zabel @ 2014-09-10 10:58 UTC (permalink / raw)
To: linux-kernel
Cc: linux-media, devel, Grant Likely, Greg Kroah-Hartman,
Guennadi Liakhovetski, Laurent Pinchart, Mauro Carvalho Chehab,
Russell King, kernel, Philipp Zabel
In preparation for a following patch, stop decrementing the endpoint node
refcount in the loop. This temporarily leaks a reference to the endpoint node,
which will be fixed by having of_graph_get_next_endpoint decrement the refcount
of its prev argument instead.
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
drivers/media/platform/soc_camera/soc_camera.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/media/platform/soc_camera/soc_camera.c b/drivers/media/platform/soc_camera/soc_camera.c
index f4308fe..f752489 100644
--- a/drivers/media/platform/soc_camera/soc_camera.c
+++ b/drivers/media/platform/soc_camera/soc_camera.c
@@ -1696,11 +1696,11 @@ 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) {
dev_err(dev, "multiple subdevices aren't supported yet!\n");
+ of_node_put(epn);
break;
}
}
--
2.1.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 2/8] imx-drm: Do not decrement endpoint node refcount in the loop
2014-09-10 10:58 [PATCH v2 0/8] Add of-graph helpers to loop over endpoints and find ports by id Philipp Zabel
2014-09-10 10:58 ` [PATCH v2 1/8] [media] soc_camera: Do not decrement endpoint node refcount in the loop Philipp Zabel
@ 2014-09-10 10:58 ` Philipp Zabel
2014-09-10 10:58 ` [PATCH v2 3/8] of: Decrement refcount of previous endpoint in of_graph_get_next_endpoint Philipp Zabel
` (5 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Philipp Zabel @ 2014-09-10 10:58 UTC (permalink / raw)
To: linux-kernel
Cc: linux-media, devel, Grant Likely, Greg Kroah-Hartman,
Guennadi Liakhovetski, Laurent Pinchart, Mauro Carvalho Chehab,
Russell King, kernel, Philipp Zabel
In preparation for the following patch, stop decrementing the endpoint node
refcount in the loop. This temporarily leaks a reference to the endpoint node,
which will be fixed by having of_graph_get_next_endpoint decrement the refcount
of its prev argument instead.
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
drivers/staging/imx-drm/imx-drm-core.c | 12 ++----------
1 file changed, 2 insertions(+), 10 deletions(-)
diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
index 6b22106..12303b3 100644
--- a/drivers/staging/imx-drm/imx-drm-core.c
+++ b/drivers/staging/imx-drm/imx-drm-core.c
@@ -434,14 +434,6 @@ static uint32_t imx_drm_find_crtc_mask(struct imx_drm_device *imxdrm,
return 0;
}
-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;
-}
-
int imx_drm_encoder_parse_of(struct drm_device *drm,
struct drm_encoder *encoder, struct device_node *np)
{
@@ -453,7 +445,7 @@ int imx_drm_encoder_parse_of(struct drm_device *drm,
for (i = 0; ; i++) {
u32 mask;
- ep = imx_drm_of_get_next_endpoint(np, ep);
+ ep = of_graph_get_next_endpoint(np, ep);
if (!ep)
break;
@@ -502,7 +494,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;
--
2.1.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 3/8] of: Decrement refcount of previous endpoint in of_graph_get_next_endpoint
2014-09-10 10:58 [PATCH v2 0/8] Add of-graph helpers to loop over endpoints and find ports by id Philipp Zabel
2014-09-10 10:58 ` [PATCH v2 1/8] [media] soc_camera: Do not decrement endpoint node refcount in the loop Philipp Zabel
2014-09-10 10:58 ` [PATCH v2 2/8] imx-drm: " Philipp Zabel
@ 2014-09-10 10:58 ` Philipp Zabel
2014-09-11 9:21 ` Laurent Pinchart
2014-09-10 10:58 ` [PATCH v2 4/8] of: Add for_each_endpoint_of_node helper macro Philipp Zabel
` (4 subsequent siblings)
7 siblings, 1 reply; 12+ messages in thread
From: Philipp Zabel @ 2014-09-10 10:58 UTC (permalink / raw)
To: linux-kernel
Cc: linux-media, devel, Grant Likely, Greg Kroah-Hartman,
Guennadi Liakhovetski, Laurent Pinchart, Mauro Carvalho Chehab,
Russell King, kernel, Philipp Zabel
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.
Prior to this patch, all current users of this function that actually pass
a non-NULL prev parameter should be changed to not decrement the passed
prev argument's refcount themselves.
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
drivers/of/base.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index d8574ad..a49b5628 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2058,8 +2058,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)
@@ -2095,12 +2094,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) {
--
2.1.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 4/8] of: Add for_each_endpoint_of_node helper macro
2014-09-10 10:58 [PATCH v2 0/8] Add of-graph helpers to loop over endpoints and find ports by id Philipp Zabel
` (2 preceding siblings ...)
2014-09-10 10:58 ` [PATCH v2 3/8] of: Decrement refcount of previous endpoint in of_graph_get_next_endpoint Philipp Zabel
@ 2014-09-10 10:58 ` Philipp Zabel
2014-09-11 9:22 ` Laurent Pinchart
2014-09-10 10:58 ` [PATCH v2 5/8] of: Add of_graph_get_port_by_id function Philipp Zabel
` (3 subsequent siblings)
7 siblings, 1 reply; 12+ messages in thread
From: Philipp Zabel @ 2014-09-10 10:58 UTC (permalink / raw)
To: linux-kernel
Cc: linux-media, devel, Grant Likely, Greg Kroah-Hartman,
Guennadi Liakhovetski, Laurent Pinchart, Mauro Carvalho Chehab,
Russell King, kernel, Philipp Zabel
Note that while of_graph_get_next_endpoint decrements the reference count
of the child node passed to it, of_node_put(child) still has to be called
manually when breaking out of the loop.
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
Changes since v1:
- Added a comment about the child node reference count when breaking out
of the loop
---
include/linux/of_graph.h | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/include/linux/of_graph.h b/include/linux/of_graph.h
index befef42..e43442e 100644
--- a/include/linux/of_graph.h
+++ b/include/linux/of_graph.h
@@ -26,6 +26,17 @@ struct of_endpoint {
const struct device_node *local_node;
};
+/**
+ * for_each_endpoint_of_node - iterate over every endpoint in a device node
+ * @parent: parent device node containing ports and endpoints
+ * @child: loop variable pointing to the current endpoint node
+ *
+ * When breaking out of the loop, of_node_put(child) has to be called manually.
+ */
+#define for_each_endpoint_of_node(parent, child) \
+ for (child = of_graph_get_next_endpoint(parent, NULL); child != NULL; \
+ child = of_graph_get_next_endpoint(parent, child))
+
#ifdef CONFIG_OF
int of_graph_parse_endpoint(const struct device_node *node,
struct of_endpoint *endpoint);
--
2.1.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 5/8] of: Add of_graph_get_port_by_id function
2014-09-10 10:58 [PATCH v2 0/8] Add of-graph helpers to loop over endpoints and find ports by id Philipp Zabel
` (3 preceding siblings ...)
2014-09-10 10:58 ` [PATCH v2 4/8] of: Add for_each_endpoint_of_node helper macro Philipp Zabel
@ 2014-09-10 10:58 ` Philipp Zabel
2014-09-11 9:26 ` Laurent Pinchart
2014-09-10 10:58 ` [PATCH v2 6/8] drm: use for_each_endpoint_of_node macro in drm_of_find_possible_crtcs Philipp Zabel
` (2 subsequent siblings)
7 siblings, 1 reply; 12+ messages in thread
From: Philipp Zabel @ 2014-09-10 10:58 UTC (permalink / raw)
To: linux-kernel
Cc: linux-media, devel, Grant Likely, Greg Kroah-Hartman,
Guennadi Liakhovetski, Laurent Pinchart, Mauro Carvalho Chehab,
Russell King, kernel, Philipp Zabel
This patch adds a function to get a port device tree node by port id,
or reg property value.
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
Changes since v1:
- Fixed whitespace in comment
- Changed id parameter to of_graph_get_port_by_id to u32
- Simplified of_graph_get_port_by_id as suggested by Laurent,
making use of port id defaulting to 0 if no "reg" property is given.
---
drivers/of/base.c | 26 ++++++++++++++++++++++++++
include/linux/of_graph.h | 7 +++++++
2 files changed, 33 insertions(+)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index a49b5628..b282474 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2053,6 +2053,32 @@ int of_graph_parse_endpoint(const struct device_node *node,
EXPORT_SYMBOL(of_graph_parse_endpoint);
/**
+ * of_graph_get_port_by_id() - get the port matching a given id
+ * @parent: pointer to the parent device node
+ * @id: id of the port
+ *
+ * Return: A 'port' node pointer with refcount incremented. The caller
+ * has to use of_node_put() on it when done.
+ */
+struct device_node *of_graph_get_port_by_id(struct device_node *node, u32 id)
+{
+ struct device_node *port = NULL;
+ u32 port_id = 0;
+
+ while (true) {
+ port = of_get_next_child(node, port);
+ if (!port)
+ return NULL;
+ if (of_node_cmp(port->name, "port") != 0)
+ continue;
+ of_property_read_u32(port, "reg", &port_id);
+ if (id == port_id)
+ return port;
+ }
+}
+EXPORT_SYMBOL(of_graph_get_port_by_id);
+
+/**
* of_graph_get_next_endpoint() - get next endpoint node
* @parent: pointer to the parent device node
* @prev: previous endpoint node, or NULL to get first
diff --git a/include/linux/of_graph.h b/include/linux/of_graph.h
index e43442e..e028e49 100644
--- a/include/linux/of_graph.h
+++ b/include/linux/of_graph.h
@@ -40,6 +40,7 @@ struct of_endpoint {
#ifdef CONFIG_OF
int of_graph_parse_endpoint(const struct device_node *node,
struct of_endpoint *endpoint);
+struct device_node *of_graph_get_port_by_id(struct device_node *node, u32 id);
struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
struct device_node *previous);
struct device_node *of_graph_get_remote_port_parent(
@@ -53,6 +54,12 @@ static inline int of_graph_parse_endpoint(const struct device_node *node,
return -ENOSYS;
}
+static inline struct device_node *of_graph_get_port_by_id(
+ struct device_node *node, int id)
+{
+ return NULL;
+}
+
static inline struct device_node *of_graph_get_next_endpoint(
const struct device_node *parent,
struct device_node *previous)
--
2.1.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 6/8] drm: use for_each_endpoint_of_node macro in drm_of_find_possible_crtcs
2014-09-10 10:58 [PATCH v2 0/8] Add of-graph helpers to loop over endpoints and find ports by id Philipp Zabel
` (4 preceding siblings ...)
2014-09-10 10:58 ` [PATCH v2 5/8] of: Add of_graph_get_port_by_id function Philipp Zabel
@ 2014-09-10 10:58 ` Philipp Zabel
2014-09-10 10:58 ` [PATCH v2 7/8] imx-drm: use for_each_endpoint_of_node macro in imx_drm_encoder_get_mux_id Philipp Zabel
2014-09-10 10:58 ` [PATCH v2 8/8] imx-drm: use for_each_endpoint_of_node macro in imx_drm_encoder_parse_of Philipp Zabel
7 siblings, 0 replies; 12+ messages in thread
From: Philipp Zabel @ 2014-09-10 10:58 UTC (permalink / raw)
To: linux-kernel
Cc: linux-media, devel, Grant Likely, Greg Kroah-Hartman,
Guennadi Liakhovetski, Laurent Pinchart, Mauro Carvalho Chehab,
Russell King, kernel, Philipp Zabel
Using the for_each_... macro should make the code a bit shorter and
easier to read.
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
drivers/gpu/drm/drm_of.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/drm_of.c b/drivers/gpu/drm/drm_of.c
index 16150a0..024fa77 100644
--- a/drivers/gpu/drm/drm_of.c
+++ b/drivers/gpu/drm/drm_of.c
@@ -46,11 +46,7 @@ uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
struct device_node *remote_port, *ep = NULL;
uint32_t possible_crtcs = 0;
- do {
- ep = of_graph_get_next_endpoint(port, ep);
- if (!ep)
- break;
-
+ for_each_endpoint_of_node(port, ep) {
remote_port = of_graph_get_remote_port(ep);
if (!remote_port) {
of_node_put(ep);
@@ -60,7 +56,7 @@ uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
possible_crtcs |= drm_crtc_port_mask(dev, remote_port);
of_node_put(remote_port);
- } while (1);
+ }
return possible_crtcs;
}
--
2.1.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 7/8] imx-drm: use for_each_endpoint_of_node macro in imx_drm_encoder_get_mux_id
2014-09-10 10:58 [PATCH v2 0/8] Add of-graph helpers to loop over endpoints and find ports by id Philipp Zabel
` (5 preceding siblings ...)
2014-09-10 10:58 ` [PATCH v2 6/8] drm: use for_each_endpoint_of_node macro in drm_of_find_possible_crtcs Philipp Zabel
@ 2014-09-10 10:58 ` Philipp Zabel
2014-09-10 10:58 ` [PATCH v2 8/8] imx-drm: use for_each_endpoint_of_node macro in imx_drm_encoder_parse_of Philipp Zabel
7 siblings, 0 replies; 12+ messages in thread
From: Philipp Zabel @ 2014-09-10 10:58 UTC (permalink / raw)
To: linux-kernel
Cc: linux-media, devel, Grant Likely, Greg Kroah-Hartman,
Guennadi Liakhovetski, Laurent Pinchart, Mauro Carvalho Chehab,
Russell King, kernel, Philipp Zabel
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/staging/imx-drm/imx-drm-core.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
index 12303b3..9b5222c 100644
--- a/drivers/staging/imx-drm/imx-drm-core.c
+++ b/drivers/staging/imx-drm/imx-drm-core.c
@@ -493,18 +493,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->port) {
ret = of_graph_parse_endpoint(ep, &endpoint);
+ of_node_put(ep);
return ret ? ret : endpoint.port;
}
- } while (ep);
+ }
return -EINVAL;
}
--
2.1.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 8/8] imx-drm: use for_each_endpoint_of_node macro in imx_drm_encoder_parse_of
2014-09-10 10:58 [PATCH v2 0/8] Add of-graph helpers to loop over endpoints and find ports by id Philipp Zabel
` (6 preceding siblings ...)
2014-09-10 10:58 ` [PATCH v2 7/8] imx-drm: use for_each_endpoint_of_node macro in imx_drm_encoder_get_mux_id Philipp Zabel
@ 2014-09-10 10:58 ` Philipp Zabel
7 siblings, 0 replies; 12+ messages in thread
From: Philipp Zabel @ 2014-09-10 10:58 UTC (permalink / raw)
To: linux-kernel
Cc: linux-media, devel, Grant Likely, Greg Kroah-Hartman,
Guennadi Liakhovetski, Laurent Pinchart, Mauro Carvalho Chehab,
Russell King, kernel, Philipp Zabel
Using the for_each_... macro should make the code bit shorter and
easier to read.
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
drivers/staging/imx-drm/imx-drm-core.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
index 9b5222c..460d785 100644
--- a/drivers/staging/imx-drm/imx-drm-core.c
+++ b/drivers/staging/imx-drm/imx-drm-core.c
@@ -438,17 +438,13 @@ int imx_drm_encoder_parse_of(struct drm_device *drm,
struct drm_encoder *encoder, struct device_node *np)
{
struct imx_drm_device *imxdrm = drm->dev_private;
- struct device_node *ep = NULL;
+ struct device_node *ep;
uint32_t crtc_mask = 0;
- int i;
+ int i = 0;
- for (i = 0; ; i++) {
+ for_each_endpoint_of_node(np, ep) {
u32 mask;
- ep = of_graph_get_next_endpoint(np, ep);
- if (!ep)
- break;
-
mask = imx_drm_find_crtc_mask(imxdrm, ep);
/*
@@ -457,14 +453,15 @@ int imx_drm_encoder_parse_of(struct drm_device *drm,
* not been registered yet. Defer probing, and hope that
* the required CRTC is added later.
*/
- if (mask == 0)
+ if (mask == 0) {
+ of_node_put(ep);
return -EPROBE_DEFER;
+ }
crtc_mask |= mask;
+ i++;
}
- if (ep)
- of_node_put(ep);
if (i == 0)
return -ENOENT;
--
2.1.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v2 3/8] of: Decrement refcount of previous endpoint in of_graph_get_next_endpoint
2014-09-10 10:58 ` [PATCH v2 3/8] of: Decrement refcount of previous endpoint in of_graph_get_next_endpoint Philipp Zabel
@ 2014-09-11 9:21 ` Laurent Pinchart
0 siblings, 0 replies; 12+ messages in thread
From: Laurent Pinchart @ 2014-09-11 9:21 UTC (permalink / raw)
To: Philipp Zabel
Cc: linux-kernel, linux-media, devel, Grant Likely,
Greg Kroah-Hartman, Guennadi Liakhovetski, Mauro Carvalho Chehab,
Russell King, kernel
Hi Philipp,
Thank you for the patch.
On Wednesday 10 September 2014 12:58:23 Philipp Zabel wrote:
> 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.
> Prior to this patch, all current users of this function that actually pass
> a non-NULL prev parameter should be changed to not decrement the passed
> prev argument's refcount themselves.
>
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
> drivers/of/base.c | 9 +--------
> 1 file changed, 1 insertion(+), 8 deletions(-)
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index d8574ad..a49b5628 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -2058,8 +2058,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)
> @@ -2095,12 +2094,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) {
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 4/8] of: Add for_each_endpoint_of_node helper macro
2014-09-10 10:58 ` [PATCH v2 4/8] of: Add for_each_endpoint_of_node helper macro Philipp Zabel
@ 2014-09-11 9:22 ` Laurent Pinchart
0 siblings, 0 replies; 12+ messages in thread
From: Laurent Pinchart @ 2014-09-11 9:22 UTC (permalink / raw)
To: Philipp Zabel
Cc: linux-kernel, linux-media, devel, Grant Likely,
Greg Kroah-Hartman, Guennadi Liakhovetski, Mauro Carvalho Chehab,
Russell King, kernel
Hi Philipp,
Thank you for the patch.
On Wednesday 10 September 2014 12:58:24 Philipp Zabel wrote:
> Note that while of_graph_get_next_endpoint decrements the reference count
> of the child node passed to it, of_node_put(child) still has to be called
> manually when breaking out of the loop.
>
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
> Changes since v1:
> - Added a comment about the child node reference count when breaking out
> of the loop
> ---
> include/linux/of_graph.h | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/include/linux/of_graph.h b/include/linux/of_graph.h
> index befef42..e43442e 100644
> --- a/include/linux/of_graph.h
> +++ b/include/linux/of_graph.h
> @@ -26,6 +26,17 @@ struct of_endpoint {
> const struct device_node *local_node;
> };
>
> +/**
> + * for_each_endpoint_of_node - iterate over every endpoint in a device node
> + * @parent: parent device node containing ports and endpoints
> + * @child: loop variable pointing to the current endpoint node
> + *
> + * When breaking out of the loop, of_node_put(child) has to be called
> manually. + */
> +#define for_each_endpoint_of_node(parent, child) \
> + for (child = of_graph_get_next_endpoint(parent, NULL); child != NULL; \
> + child = of_graph_get_next_endpoint(parent, child))
> +
> #ifdef CONFIG_OF
> int of_graph_parse_endpoint(const struct device_node *node,
> struct of_endpoint *endpoint);
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 5/8] of: Add of_graph_get_port_by_id function
2014-09-10 10:58 ` [PATCH v2 5/8] of: Add of_graph_get_port_by_id function Philipp Zabel
@ 2014-09-11 9:26 ` Laurent Pinchart
0 siblings, 0 replies; 12+ messages in thread
From: Laurent Pinchart @ 2014-09-11 9:26 UTC (permalink / raw)
To: Philipp Zabel
Cc: linux-kernel, linux-media, devel, Grant Likely,
Greg Kroah-Hartman, Guennadi Liakhovetski, Mauro Carvalho Chehab,
Russell King, kernel
Hi Philipp,
Thank you for the patch.
On Wednesday 10 September 2014 12:58:25 Philipp Zabel wrote:
> This patch adds a function to get a port device tree node by port id,
> or reg property value.
>
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> ---
> Changes since v1:
> - Fixed whitespace in comment
> - Changed id parameter to of_graph_get_port_by_id to u32
> - Simplified of_graph_get_port_by_id as suggested by Laurent,
> making use of port id defaulting to 0 if no "reg" property is given.
> ---
> drivers/of/base.c | 26 ++++++++++++++++++++++++++
> include/linux/of_graph.h | 7 +++++++
> 2 files changed, 33 insertions(+)
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index a49b5628..b282474 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -2053,6 +2053,32 @@ int of_graph_parse_endpoint(const struct device_node
> *node, EXPORT_SYMBOL(of_graph_parse_endpoint);
>
> /**
> + * of_graph_get_port_by_id() - get the port matching a given id
> + * @parent: pointer to the parent device node
> + * @id: id of the port
> + *
> + * Return: A 'port' node pointer with refcount incremented. The caller
> + * has to use of_node_put() on it when done.
> + */
> +struct device_node *of_graph_get_port_by_id(struct device_node *node, u32
> id) +{
> + struct device_node *port = NULL;
No need to initialize port to NULL.
> + u32 port_id = 0;
> +
> + while (true) {
> + port = of_get_next_child(node, port);
> + if (!port)
> + return NULL;
How about using for_each_child_of_node() ?
> + if (of_node_cmp(port->name, "port") != 0)
> + continue;
> + of_property_read_u32(port, "reg", &port_id);
A port with no reg property will be treated as having the id of the previous
port. You can fix this by moving the port_id variable declaration inside the
loop.
> + if (id == port_id)
> + return port;
> + }
> +}
> +EXPORT_SYMBOL(of_graph_get_port_by_id);
> +
> +/**
> * of_graph_get_next_endpoint() - get next endpoint node
> * @parent: pointer to the parent device node
> * @prev: previous endpoint node, or NULL to get first
> diff --git a/include/linux/of_graph.h b/include/linux/of_graph.h
> index e43442e..e028e49 100644
> --- a/include/linux/of_graph.h
> +++ b/include/linux/of_graph.h
> @@ -40,6 +40,7 @@ struct of_endpoint {
> #ifdef CONFIG_OF
> int of_graph_parse_endpoint(const struct device_node *node,
> struct of_endpoint *endpoint);
> +struct device_node *of_graph_get_port_by_id(struct device_node *node, u32
> id); struct device_node *of_graph_get_next_endpoint(const struct
> device_node *parent, struct device_node *previous);
> struct device_node *of_graph_get_remote_port_parent(
> @@ -53,6 +54,12 @@ static inline int of_graph_parse_endpoint(const struct
> device_node *node, return -ENOSYS;
> }
>
> +static inline struct device_node *of_graph_get_port_by_id(
> + struct device_node *node, int id)
id should be u32 here.
> +{
> + return NULL;
> +}
> +
> static inline struct device_node *of_graph_get_next_endpoint(
> const struct device_node *parent,
> struct device_node *previous)
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2014-09-11 9:26 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-10 10:58 [PATCH v2 0/8] Add of-graph helpers to loop over endpoints and find ports by id Philipp Zabel
2014-09-10 10:58 ` [PATCH v2 1/8] [media] soc_camera: Do not decrement endpoint node refcount in the loop Philipp Zabel
2014-09-10 10:58 ` [PATCH v2 2/8] imx-drm: " Philipp Zabel
2014-09-10 10:58 ` [PATCH v2 3/8] of: Decrement refcount of previous endpoint in of_graph_get_next_endpoint Philipp Zabel
2014-09-11 9:21 ` Laurent Pinchart
2014-09-10 10:58 ` [PATCH v2 4/8] of: Add for_each_endpoint_of_node helper macro Philipp Zabel
2014-09-11 9:22 ` Laurent Pinchart
2014-09-10 10:58 ` [PATCH v2 5/8] of: Add of_graph_get_port_by_id function Philipp Zabel
2014-09-11 9:26 ` Laurent Pinchart
2014-09-10 10:58 ` [PATCH v2 6/8] drm: use for_each_endpoint_of_node macro in drm_of_find_possible_crtcs Philipp Zabel
2014-09-10 10:58 ` [PATCH v2 7/8] imx-drm: use for_each_endpoint_of_node macro in imx_drm_encoder_get_mux_id Philipp Zabel
2014-09-10 10:58 ` [PATCH v2 8/8] imx-drm: use for_each_endpoint_of_node macro in imx_drm_encoder_parse_of Philipp Zabel
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.