linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: ulpi: Add missing of_node_get() in ulpi_of_register()
@ 2017-11-11  1:43 Stephen Boyd
  2017-11-11 15:25 ` Johan Hovold
  2017-11-11 15:31 ` [PATCH] USB: ulpi: fix bus-node lookup Johan Hovold
  0 siblings, 2 replies; 3+ messages in thread
From: Stephen Boyd @ 2017-11-11  1:43 UTC (permalink / raw)
  To: Heikki Krogerus, Greg Kroah-Hartman
  Cc: linux-kernel, linux-arm-msm, linux-usb, Rob Clark, Peter Robinson

In ulpi_of_register() we call of_find_node_by_name() which
unconditionally calls of_node_put() on the 'from' argument. We
haven't called of_node_get() though, so we've put the node once
without getting it first. Add the of_node_get() call so that
things are properly balanced.

Fixes: ef6a7bcfb01c ("usb: ulpi: Support device discovery via DT")
Reported-by: Peter Robinson <pbrobinson@gmail.com>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
---
 drivers/usb/common/ulpi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
index 4aa5195db8ea..59e05eff76f9 100644
--- a/drivers/usb/common/ulpi.c
+++ b/drivers/usb/common/ulpi.c
@@ -182,9 +182,9 @@ static int ulpi_of_register(struct ulpi *ulpi)
 
 	/* Find a ulpi bus underneath the parent or the grandparent */
 	parent = ulpi->dev.parent;
-	if (parent->of_node)
+	if (of_node_get(parent->of_node))
 		np = of_find_node_by_name(parent->of_node, "ulpi");
-	else if (parent->parent && parent->parent->of_node)
+	else if (parent->parent && of_node_get(parent->parent->of_node))
 		np = of_find_node_by_name(parent->parent->of_node, "ulpi");
 	if (!np)
 		return 0;
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* Re: [PATCH] usb: ulpi: Add missing of_node_get() in ulpi_of_register()
  2017-11-11  1:43 [PATCH] usb: ulpi: Add missing of_node_get() in ulpi_of_register() Stephen Boyd
@ 2017-11-11 15:25 ` Johan Hovold
  2017-11-11 15:31 ` [PATCH] USB: ulpi: fix bus-node lookup Johan Hovold
  1 sibling, 0 replies; 3+ messages in thread
From: Johan Hovold @ 2017-11-11 15:25 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Heikki Krogerus, Greg Kroah-Hartman, linux-kernel, linux-arm-msm,
	linux-usb, Rob Clark, Peter Robinson

On Fri, Nov 10, 2017 at 05:43:00PM -0800, Stephen Boyd wrote:
> In ulpi_of_register() we call of_find_node_by_name() which
> unconditionally calls of_node_put() on the 'from' argument. We
> haven't called of_node_get() though, so we've put the node once
> without getting it first. Add the of_node_get() call so that
> things are properly balanced.
> 
> Fixes: ef6a7bcfb01c ("usb: ulpi: Support device discovery via DT")
> Reported-by: Peter Robinson <pbrobinson@gmail.com>
> Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
> ---
>  drivers/usb/common/ulpi.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
> index 4aa5195db8ea..59e05eff76f9 100644
> --- a/drivers/usb/common/ulpi.c
> +++ b/drivers/usb/common/ulpi.c
> @@ -182,9 +182,9 @@ static int ulpi_of_register(struct ulpi *ulpi)
>  
>  	/* Find a ulpi bus underneath the parent or the grandparent */
>  	parent = ulpi->dev.parent;
> -	if (parent->of_node)
> +	if (of_node_get(parent->of_node))
>  		np = of_find_node_by_name(parent->of_node, "ulpi");
> -	else if (parent->parent && parent->parent->of_node)
> +	else if (parent->parent && of_node_get(parent->parent->of_node))
>  		np = of_find_node_by_name(parent->parent->of_node, "ulpi");

I'm afraid this isn't the right fix; the code shouldn't have been using
of_find_node_by_name() in the first place as that function searches the
whole device tree depth-first starting at the parent (or grand parent),
which could end up matching an unrelated node.

of_get_child_by_name() is the helper to use for such lookups instead.

Turns out we have a few other driver with similar bugs. I've started
fixing a few of them that'll be sending out per subsystem.

I'll post a fix for this one as follow up to this mail meanwhile.

Thanks,
Johan

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

* [PATCH] USB: ulpi: fix bus-node lookup
  2017-11-11  1:43 [PATCH] usb: ulpi: Add missing of_node_get() in ulpi_of_register() Stephen Boyd
  2017-11-11 15:25 ` Johan Hovold
@ 2017-11-11 15:31 ` Johan Hovold
  1 sibling, 0 replies; 3+ messages in thread
From: Johan Hovold @ 2017-11-11 15:31 UTC (permalink / raw)
  To: Heikki Krogerus
  Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, linux-arm-msm,
	Rob Clark, Peter Robinson, Johan Hovold, stable

Fix bus-node lookup during registration, which ended up searching the whole
device tree depth-first starting at the parent (or grand parent) rather
than just matching on its children.

To make things worse, the parent (or grand-parent) node could end being
prematurely freed as well.

Fixes: ef6a7bcfb01c ("usb: ulpi: Support device discovery via DT")
Reported-by: Peter Robinson <pbrobinson@gmail.com>
Reported-by: Stephen Boyd <sboyd@codeaurora.org>
Cc: stable <stable@vger.kernel.org>     # 4.10
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/common/ulpi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
index 8b351444cc40..9a2ab6751a23 100644
--- a/drivers/usb/common/ulpi.c
+++ b/drivers/usb/common/ulpi.c
@@ -180,9 +180,9 @@ static int ulpi_of_register(struct ulpi *ulpi)
 	/* Find a ulpi bus underneath the parent or the grandparent */
 	parent = ulpi->dev.parent;
 	if (parent->of_node)
-		np = of_find_node_by_name(parent->of_node, "ulpi");
+		np = of_get_child_by_name(parent->of_node, "ulpi");
 	else if (parent->parent && parent->parent->of_node)
-		np = of_find_node_by_name(parent->parent->of_node, "ulpi");
+		np = of_get_child_by_name(parent->parent->of_node, "ulpi");
 	if (!np)
 		return 0;
 
-- 
2.15.0

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

end of thread, other threads:[~2017-11-11 15:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-11  1:43 [PATCH] usb: ulpi: Add missing of_node_get() in ulpi_of_register() Stephen Boyd
2017-11-11 15:25 ` Johan Hovold
2017-11-11 15:31 ` [PATCH] USB: ulpi: fix bus-node lookup Johan Hovold

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).