of: fix sparse warnings in of_find_next_cache_node
Subsystems (2)
Rob Herring
maintainerPATCH 1/3 of: fix sparse warnings in of_find_next_cache_node
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.
--- drivers/of/base.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/of/base.c +6 -7
@@ -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.
Signature · 6 lines
2.11.0 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Rob Herring
maintainerPATCH 2/3 of: fix sparse warning in of_pci_range_parser_one
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.
--- drivers/of/address.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/address.c +1 -1
@@ -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,
Signature · 1 line
2.11.0
Re: [PATCH 2/3] of: fix sparse warning in of_pci_range_parser_one
Quoted 21 lines · Rob Herring
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__be32const [usertype] <noident>It appears that
pci_spaceis only ever accessed on powerpc, so the endian swap is often not needed.Signed-off-by Rob Herring <[email protected]>--- drivers/of/address.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/of/address.c +0
-0
drivers/of/address.c struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser, · line 269
Quoted 8 lines
drivers/of/address.c +1
-1@@ -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,
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Rob Herring
maintainerPATCH 3/3 of: fix sparse warnings in fdt, irq, and resolver code
In reply to Rob Herringsparse generates the following warnings in drivers/of/:
../drivers/of/fdt.c:63:36: warning: cast to restricted __be32 ../drivers/of/fdt.c:68:33: warning: cast to restricted __be32 ../drivers/of/irq.c:105:88: warning: incorrect type in initializer (different base types)../drivers/of/irq.c:105:88: expected restricted __be32../drivers/of/irq.c:105:88: got int../drivers/of/irq.c:526:35: warning: incorrect type in assignment (different modifiers)../drivers/of/irq.c:526:35: expected int ( *const [usertype] irq_init_cb )( ... )../drivers/of/irq.c:526:35: got void const *const data../drivers/of/resolver.c:95:42: warning: incorrect type in assignment (different base types)../drivers/of/resolver.c:95:42: expected unsigned int [unsigned] [usertype] <noident>../drivers/of/resolver.c:95:42: got restricted __be32 [usertype] <noident>
All these are harmless type mismatches fixed by adjusting the types.
--- drivers/of/fdt.c | 4 ++-- drivers/of/irq.c | 2 +- drivers/of/resolver.c | 2 +- include/linux/of_irq.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-)
drivers/of/fdt.c +2 -2
@@ -48,8 +48,8 @@ void of_fdt_limit_memory(int limit)const void *val;int nr_address_cells =OF_ROOT_NODE_ADDR_CELLS_DEFAULT ;int nr_size_cells =OF_ROOT_NODE_SIZE_CELLS_DEFAULT ; -const uint32_t *addr_prop; -const uint32_t *size_prop; +const __be32 *addr_prop; +const __be32 *size_prop;int root_offset;int cell_size;
drivers/of/irq.c +1 -1
@@ -102,7 +102,7 @@ int of_irq_parse_raw(const __be32 *addr, struct of_phandle_args *out_irq)struct device_node *ipar, *tnode, *old =NULL , *newpar =NULL ;__be32 initial_match_array[MAX_PHANDLE_ARGS ];const __be32 *match_array = initial_match_array; -const __be32 *tmp, *imap, *imask, dummy_imask[] = { [0 ...MAX_PHANDLE_ARGS ] = ~0 }; +const __be32 *tmp, *imap, *imask, dummy_imask[] = { [0 ...MAX_PHANDLE_ARGS ] =cpu_to_be32 (~0 ) };u32 intsize =1 , addrsize, newintsize =0 , newaddrsize =0 ;int imaplen, match, i, rc = -EINVAL ;
drivers/of/resolver.c +1 -1
@@ -92,7 +92,7 @@ static void adjust_overlay_phandles(struct device_node *overlay,if (phandle ==OF_PHANDLE_ILLEGAL )continue ; - *(uint32_t *)prop->value =cpu_to_be32 (overlay->phandle); + *(__be32 *)prop->value =cpu_to_be32 (overlay->phandle); }for_each_child_of_node (overlay, child)
include/linux/of_irq.h +1 -1
@@ -8,7 +8,7 @@#include <linux/ioport.h> #include <linux/of.h> -typedef int (*of_irq_init_cb_t )(struct device_node *,struct device_node *); +typedef int const (*of_irq_init_cb_t )(struct device_node *,struct device_node *);/* * Workarounds only applied to 32bit powermac machines
Signature · 6 lines
2.11.0 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] of: fix sparse warnings in fdt, irq, and resolver code
Quoted 71 lines · Rob Herring
sparse generates the following warnings in
drivers/of/:
../drivers/of/fdt.c:63:36: warning: cast to restricted__be32../drivers/of/fdt.c:68:33: warning: cast to restricted__be32../drivers/of/irq.c:105:88: warning: incorrect type in initializer (different base types)../drivers/of/irq.c:105:88: expected restricted__be32../drivers/of/irq.c:105:88: got int../drivers/of/irq.c:526:35: warning: incorrect type in assignment (different modifiers)../drivers/of/irq.c:526:35: expected int ( *const [usertype]irq_init_cb)( ... )../drivers/of/irq.c:526:35: got void const *const data../drivers/of/resolver.c:95:42: warning: incorrect type in assignment (different base types)../drivers/of/resolver.c:95:42: expected unsigned int [unsigned] [usertype] <noident>../drivers/of/resolver.c:95:42: got restricted__be32[usertype] <noident>All these are harmless type mismatches fixed by adjusting the types.
Signed-off-by Rob Herring <[email protected]>--- drivers/of/fdt.c | 4 ++-- drivers/of/irq.c | 2 +- drivers/of/resolver.c | 2 +- include/linux/of_irq.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-)drivers/of/fdt.c +2
-2@@ -48,8 +48,8 @@ void of_fdt_limit_memory(int limit)const void *val;int nr_address_cells =OF_ROOT_NODE_ADDR_CELLS_DEFAULT ;int nr_size_cells =OF_ROOT_NODE_SIZE_CELLS_DEFAULT ; -const uint32_t *addr_prop; -const uint32_t *size_prop; +const __be32 *addr_prop; +const __be32 *size_prop;int root_offset;int cell_size;drivers/of/irq.c +1
-1@@ -102,7 +102,7 @@ int of_irq_parse_raw(const __be32 *addr, struct of_phandle_args *out_irq)struct device_node *ipar, *tnode, *old =NULL , *newpar =NULL ;__be32 initial_match_array[MAX_PHANDLE_ARGS ];const __be32 *match_array = initial_match_array; -const __be32 *tmp, *imap, *imask, dummy_imask[] = { [0 ...MAX_PHANDLE_ARGS ] = ~0 }; +const __be32 *tmp, *imap, *imask, dummy_imask[] = { [0 ...MAX_PHANDLE_ARGS ] =cpu_to_be32 (~0 ) };u32 intsize =1 , addrsize, newintsize =0 , newaddrsize =0 ;int imaplen, match, i, rc = -EINVAL ;drivers/of/resolver.c +1
-1@@ -92,7 +92,7 @@ static void adjust_overlay_phandles(struct device_node *overlay,if (phandle ==OF_PHANDLE_ILLEGAL )continue ; - *(uint32_t *)prop->value =cpu_to_be32 (overlay->phandle); + *(__be32 *)prop->value =cpu_to_be32 (overlay->phandle); }for_each_child_of_node (overlay, child)include/linux/of_irq.h +0
-0
include/linux/of_irq.h line 14
Quoted 8 lines
include/linux/of_irq.h +1
-1@@ -8,7 +8,7 @@#include <linux/ioport.h> #include <linux/of.h> -typedef int (*of_irq_init_cb_t )(struct device_node *,struct device_node *); +typedef int const (*of_irq_init_cb_t )(struct device_node *,struct device_node *);/* * Workarounds only applied to 32bit powermac machines
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 32 lines · Rob Herring
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__be32const [usertype] *p../drivers/of/base.c:2261:61: got unsigned int const [usertype] *[assigned] handleWe could just change the type, but the code can be improved by using
of_parse_phandleinstead of open coding it withof_get_propertyandof_find_node_by_phandle.Signed-off-by Rob Herring <[email protected]>--- drivers/of/base.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)drivers/of/base.c +2
-5@@ -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 );
drivers/of/base.c EXPORT_SYMBOL_GPL(of_console_check); · line 2263
Quoted 10 lines
drivers/of/base.c +4
-2+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.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html