diff mbox series

[1/3] of: fix sparse warnings in of_find_next_cache_node

Message ID 20170504180035.12834-1-robh@kernel.org
State Accepted
Commit 91d967497f11dbb5038c7b84bc30dae684ae5ffb
Headers show
Series [1/3] of: fix sparse warnings in of_find_next_cache_node | expand

Commit Message

Rob Herring (Arm) May 4, 2017, 6 p.m. UTC
sparse gives a warning that 'handle' is not a __be32:

../drivers/of/base.c:2261:61: warning: incorrect type in argument 1 (different base types)
../drivers/of/base.c:2261:61:    expected restricted __be32 const [usertype] *p
../drivers/of/base.c:2261:61:    got unsigned int const [usertype] *[assigned] handle

We could just change the type, but the code can be improved by using
of_parse_phandle instead of open coding it with of_get_property and
of_find_node_by_phandle.

Signed-off-by: Rob Herring <robh@kernel.org>

---
 drivers/of/base.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

-- 
2.11.0

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

Comments

Frank Rowand May 5, 2017, 5:15 a.m. UTC | #1
On 05/04/17 11:00, Rob Herring wrote:
> sparse gives a warning that 'handle' is not a __be32:

> 

> ../drivers/of/base.c:2261:61: warning: incorrect type in argument 1 (different base types)

> ../drivers/of/base.c:2261:61:    expected restricted __be32 const [usertype] *p

> ../drivers/of/base.c:2261:61:    got unsigned int const [usertype] *[assigned] handle

> 

> We could just change the type, but the code can be improved by using

> of_parse_phandle instead of open coding it with of_get_property and

> of_find_node_by_phandle.

> 

> Signed-off-by: Rob Herring <robh@kernel.org>

> ---

>  drivers/of/base.c | 13 ++++++-------

>  1 file changed, 6 insertions(+), 7 deletions(-)

> 

> diff --git a/drivers/of/base.c b/drivers/of/base.c

> index d7c4629a3a2d..016f9d77d64d 100644

> --- a/drivers/of/base.c

> +++ b/drivers/of/base.c

> @@ -2250,15 +2250,14 @@ EXPORT_SYMBOL_GPL(of_console_check);

>   */

>  struct device_node *of_find_next_cache_node(const struct device_node *np)

>  {

> -	struct device_node *child;

> -	const phandle *handle;

> +	struct device_node *child, *cache_node;

>  

> -	handle = of_get_property(np, "l2-cache", NULL);

> -	if (!handle)

> -		handle = of_get_property(np, "next-level-cache", NULL);

> +	cache_node = of_parse_phandle(np, "l2-cache", 0);

> +	if (!cache_node)

> +		cache_node = of_parse_phandle(np, "next-level-cache", 0);

>  

> -	if (handle)

> -		return of_find_node_by_phandle(be32_to_cpup(handle));

> +	if (cache_node)

> +		return cache_node;

>  

>  	/* OF on pmac has nodes instead of properties named "l2-cache"

>  	 * beneath CPU nodes.

> 


Reviewed-by: Frank Rowand <frank.rowand@sony.com>

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Frank Rowand May 5, 2017, 5:16 a.m. UTC | #2
On 05/04/17 11:00, Rob Herring wrote:
> sparse gives the following warning for 'pci_space':

> 

> ../drivers/of/address.c:266:26: warning: incorrect type in assignment (different base types)

> ../drivers/of/address.c:266:26:    expected unsigned int [unsigned] [usertype] pci_space

> ../drivers/of/address.c:266:26:    got restricted __be32 const [usertype] <noident>

> 

> It appears that pci_space is only ever accessed on powerpc, so the endian

> swap is often not needed.

> 

> Cc: stable@vger.kernel.org

> Signed-off-by: Rob Herring <robh@kernel.org>

> ---

>  drivers/of/address.c | 2 +-

>  1 file changed, 1 insertion(+), 1 deletion(-)

> 

> diff --git a/drivers/of/address.c b/drivers/of/address.c

> index 02b2903fe9d2..72914cdfce2a 100644

> --- a/drivers/of/address.c

> +++ b/drivers/of/address.c

> @@ -263,7 +263,7 @@ struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser,

>  	if (!parser->range || parser->range + parser->np > parser->end)

>  		return NULL;

>  

> -	range->pci_space = parser->range[0];

> +	range->pci_space = be32_to_cpup(parser->range);

>  	range->flags = of_bus_pci_get_flags(parser->range);

>  	range->pci_addr = of_read_number(parser->range + 1, ns);

>  	range->cpu_addr = of_translate_address(parser->node,

> 


Reviewed-by: Frank Rowand <frank.rowand@sony.com>

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

Patch

diff --git a/drivers/of/base.c b/drivers/of/base.c
index d7c4629a3a2d..016f9d77d64d 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2250,15 +2250,14 @@  EXPORT_SYMBOL_GPL(of_console_check);
  */
 struct device_node *of_find_next_cache_node(const struct device_node *np)
 {
-	struct device_node *child;
-	const phandle *handle;
+	struct device_node *child, *cache_node;
 
-	handle = of_get_property(np, "l2-cache", NULL);
-	if (!handle)
-		handle = of_get_property(np, "next-level-cache", NULL);
+	cache_node = of_parse_phandle(np, "l2-cache", 0);
+	if (!cache_node)
+		cache_node = of_parse_phandle(np, "next-level-cache", 0);
 
-	if (handle)
-		return of_find_node_by_phandle(be32_to_cpup(handle));
+	if (cache_node)
+		return cache_node;
 
 	/* OF on pmac has nodes instead of properties named "l2-cache"
 	 * beneath CPU nodes.