2015-08-19 20:17:55

by David Daney

[permalink] [raw]
Subject: [PATCH] of/address: Don't loop forever in of_find_matching_node_by_address().

From: David Daney <[email protected]>

If the internal call to of_address_to_resource() fails, we end up
looping forever in of_find_matching_node_by_address(). This can be
caused by a defective device tree, or calling with an incorrect
matches argument.

Fix by calling of_find_matching_node() unconditionally at the end of
the loop.

Signed-off-by: David Daney <[email protected]>
---
drivers/of/address.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/of/address.c b/drivers/of/address.c
index 8bfda6a..384574c 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -845,10 +845,10 @@ struct device_node *of_find_matching_node_by_address(struct device_node *from,
struct resource res;

while (dn) {
- if (of_address_to_resource(dn, 0, &res))
- continue;
- if (res.start == base_address)
+ if (!of_address_to_resource(dn, 0, &res) &&
+ res.start == base_address)
return dn;
+
dn = of_find_matching_node(dn, matches);
}

--
1.9.1


2015-08-24 15:17:59

by Rob Herring

[permalink] [raw]
Subject: Re: [PATCH] of/address: Don't loop forever in of_find_matching_node_by_address().

On Wed, Aug 19, 2015 at 3:17 PM, David Daney <[email protected]> wrote:
> From: David Daney <[email protected]>
>
> If the internal call to of_address_to_resource() fails, we end up
> looping forever in of_find_matching_node_by_address(). This can be
> caused by a defective device tree, or calling with an incorrect
> matches argument.
>
> Fix by calling of_find_matching_node() unconditionally at the end of
> the loop.
>
> Signed-off-by: David Daney <[email protected]>

Applied and tagged for stable. Thanks.

Rob

> ---
> drivers/of/address.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/of/address.c b/drivers/of/address.c
> index 8bfda6a..384574c 100644
> --- a/drivers/of/address.c
> +++ b/drivers/of/address.c
> @@ -845,10 +845,10 @@ struct device_node *of_find_matching_node_by_address(struct device_node *from,
> struct resource res;
>
> while (dn) {
> - if (of_address_to_resource(dn, 0, &res))
> - continue;
> - if (res.start == base_address)
> + if (!of_address_to_resource(dn, 0, &res) &&
> + res.start == base_address)
> return dn;
> +
> dn = of_find_matching_node(dn, matches);
> }
>
> --
> 1.9.1
>