devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] of: fix reference counting in of_graph_get_endpoint_by_regs
@ 2016-07-06 10:11 Lucas Stach
       [not found] ` <1467799896-18573-1-git-send-email-l.stach-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Lucas Stach @ 2016-07-06 10:11 UTC (permalink / raw)
  To: Rob Herring, Frank Rowand
  Cc: devicetree-u79uwXL29TY76Z2rM5mHXA, kernel-bIcnvbaLZ9MEGnE8C9+IrQ,
	patchwork-lst-bIcnvbaLZ9MEGnE8C9+IrQ

The called of_graph_get_next_endpoint() already decrements the refcount
of the prev node, so it is wrong to do it again in the calling function.

Use the for_each_endpoint_of_node() helper to interate through the
endpoint OF nodes, which already does the right thing and simplifies
the code a bit.

Fixes: 8ccd0d0ca041
(of: add helper for getting endpoint node of specific identifiers)
Cc: stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Reported-by: David Jander <david-/Q/L1SwJa3aEVqv0pETR8A@public.gmane.org>
Signed-off-by: Lucas Stach <l.stach-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
---
v2: Switch over to use for_each_endpoint_of_node() helper as requested
    by Rob Herring.
---
 drivers/of/base.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index ebf84e3b56d5..c60d47c8c863 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2306,11 +2306,9 @@ struct device_node *of_graph_get_endpoint_by_regs(
 	const struct device_node *parent, int port_reg, int reg)
 {
 	struct of_endpoint endpoint;
-	struct device_node *node, *prev_node = NULL;
+	struct device_node *node = NULL;
 
-	while (1) {
-		node = of_graph_get_next_endpoint(parent, prev_node);
-		of_node_put(prev_node);
+	for_each_endpoint_of_node(parent, node) {
 		if (!node)
 			break;
 
@@ -2318,8 +2316,6 @@ struct device_node *of_graph_get_endpoint_by_regs(
 		if (((port_reg == -1) || (endpoint.port == port_reg)) &&
 			((reg == -1) || (endpoint.id == reg)))
 			return node;
-
-		prev_node = node;
 	}
 
 	return NULL;
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] of: fix reference counting in of_graph_get_endpoint_by_regs
       [not found] ` <1467799896-18573-1-git-send-email-l.stach-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
@ 2016-07-06 15:59   ` Philipp Zabel
  2016-07-18 12:59   ` Rob Herring
  1 sibling, 0 replies; 3+ messages in thread
From: Philipp Zabel @ 2016-07-06 15:59 UTC (permalink / raw)
  To: Lucas Stach
  Cc: Rob Herring, Frank Rowand, devicetree-u79uwXL29TY76Z2rM5mHXA,
	kernel-bIcnvbaLZ9MEGnE8C9+IrQ,
	patchwork-lst-bIcnvbaLZ9MEGnE8C9+IrQ

Am Mittwoch, den 06.07.2016, 12:11 +0200 schrieb Lucas Stach:
> The called of_graph_get_next_endpoint() already decrements the refcount
> of the prev node, so it is wrong to do it again in the calling function.
> 
> Use the for_each_endpoint_of_node() helper to interate through the
> endpoint OF nodes, which already does the right thing and simplifies
> the code a bit.
> 
> Fixes: 8ccd0d0ca041
> (of: add helper for getting endpoint node of specific identifiers)
> Cc: stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> Reported-by: David Jander <david-/Q/L1SwJa3aEVqv0pETR8A@public.gmane.org>
> Signed-off-by: Lucas Stach <l.stach-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>

Acked-by: Philipp Zabel <p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>

regards
Philipp

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] of: fix reference counting in of_graph_get_endpoint_by_regs
       [not found] ` <1467799896-18573-1-git-send-email-l.stach-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
  2016-07-06 15:59   ` Philipp Zabel
@ 2016-07-18 12:59   ` Rob Herring
  1 sibling, 0 replies; 3+ messages in thread
From: Rob Herring @ 2016-07-18 12:59 UTC (permalink / raw)
  To: Lucas Stach
  Cc: Frank Rowand, devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org,
	patchwork-lst-bIcnvbaLZ9MEGnE8C9+IrQ

On Wed, Jul 6, 2016 at 5:11 AM, Lucas Stach <l.stach-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> wrote:
> The called of_graph_get_next_endpoint() already decrements the refcount
> of the prev node, so it is wrong to do it again in the calling function.
>
> Use the for_each_endpoint_of_node() helper to interate through the
> endpoint OF nodes, which already does the right thing and simplifies
> the code a bit.
>
> Fixes: 8ccd0d0ca041
> (of: add helper for getting endpoint node of specific identifiers)
> Cc: stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> Reported-by: David Jander <david-/Q/L1SwJa3aEVqv0pETR8A@public.gmane.org>
> Signed-off-by: Lucas Stach <l.stach-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> ---
> v2: Switch over to use for_each_endpoint_of_node() helper as requested
>     by Rob Herring.
> ---
>  drivers/of/base.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index ebf84e3b56d5..c60d47c8c863 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -2306,11 +2306,9 @@ struct device_node *of_graph_get_endpoint_by_regs(
>         const struct device_node *parent, int port_reg, int reg)
>  {
>         struct of_endpoint endpoint;
> -       struct device_node *node, *prev_node = NULL;
> +       struct device_node *node = NULL;
>
> -       while (1) {
> -               node = of_graph_get_next_endpoint(parent, prev_node);
> -               of_node_put(prev_node);
> +       for_each_endpoint_of_node(parent, node) {
>                 if (!node)
>                         break;

These 2 lines are no longer needed.

>
> @@ -2318,8 +2316,6 @@ struct device_node *of_graph_get_endpoint_by_regs(
>                 if (((port_reg == -1) || (endpoint.port == port_reg)) &&
>                         ((reg == -1) || (endpoint.id == reg)))
>                         return node;
> -
> -               prev_node = node;
>         }
>
>         return NULL;
> --
> 2.8.1
>
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-07-18 12:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-06 10:11 [PATCH v2] of: fix reference counting in of_graph_get_endpoint_by_regs Lucas Stach
     [not found] ` <1467799896-18573-1-git-send-email-l.stach-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2016-07-06 15:59   ` Philipp Zabel
2016-07-18 12:59   ` Rob Herring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).