of: restructure for_each macros to fix compile warnings

Commit 00b2c76a6a "include/linux/of.h: make for_each_child_of_node()
reference its args when CONFIG_OF=n" fixed warnings for unused
variables, but introduced variable "used uninitialized" warnings.
Simply initializing the variables would result in "set but not used"
warnings with W=1.

Fix both types of warnings by making all the for_each macros
unconditional and rely on the dummy static inline functions to
initialize and reference any variables.

Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: David Howells <dhowells@redhat.com>
Signed-off-by: Rob Herring <robh@kernel.org>
Acked-by: Grant Likely <grant.likely@linaro.org>

+89 -74
+89 -74
include/linux/of.h
··· 169 169 170 170 extern struct device_node *of_find_node_by_name(struct device_node *from, 171 171 const char *name); 172 - #define for_each_node_by_name(dn, name) \ 173 - for (dn = of_find_node_by_name(NULL, name); dn; \ 174 - dn = of_find_node_by_name(dn, name)) 175 172 extern struct device_node *of_find_node_by_type(struct device_node *from, 176 173 const char *type); 177 - #define for_each_node_by_type(dn, type) \ 178 - for (dn = of_find_node_by_type(NULL, type); dn; \ 179 - dn = of_find_node_by_type(dn, type)) 180 174 extern struct device_node *of_find_compatible_node(struct device_node *from, 181 175 const char *type, const char *compat); 182 - #define for_each_compatible_node(dn, type, compatible) \ 183 - for (dn = of_find_compatible_node(NULL, type, compatible); dn; \ 184 - dn = of_find_compatible_node(dn, type, compatible)) 185 176 extern struct device_node *of_find_matching_node_and_match( 186 177 struct device_node *from, 187 178 const struct of_device_id *matches, 188 179 const struct of_device_id **match); 189 - static inline struct device_node *of_find_matching_node( 190 - struct device_node *from, 191 - const struct of_device_id *matches) 192 - { 193 - return of_find_matching_node_and_match(from, matches, NULL); 194 - } 195 - #define for_each_matching_node(dn, matches) \ 196 - for (dn = of_find_matching_node(NULL, matches); dn; \ 197 - dn = of_find_matching_node(dn, matches)) 198 - #define for_each_matching_node_and_match(dn, matches, match) \ 199 - for (dn = of_find_matching_node_and_match(NULL, matches, match); \ 200 - dn; dn = of_find_matching_node_and_match(dn, matches, match)) 180 + 201 181 extern struct device_node *of_find_node_by_path(const char *path); 202 182 extern struct device_node *of_find_node_by_phandle(phandle handle); 203 183 extern struct device_node *of_get_parent(const struct device_node *node); ··· 189 209 190 210 extern struct device_node *of_get_child_by_name(const struct device_node *node, 191 211 const char *name); 192 - #define for_each_child_of_node(parent, child) \ 193 - for (child = of_get_next_child(parent, NULL); child != NULL; \ 194 - child = of_get_next_child(parent, child)) 195 - 196 - #define for_each_available_child_of_node(parent, child) \ 197 - for (child = of_get_next_available_child(parent, NULL); child != NULL; \ 198 - child = of_get_next_available_child(parent, child)) 199 - 200 - static inline int of_get_child_count(const struct device_node *np) 201 - { 202 - struct device_node *child; 203 - int num = 0; 204 - 205 - for_each_child_of_node(np, child) 206 - num++; 207 - 208 - return num; 209 - } 210 - 211 - static inline int of_get_available_child_count(const struct device_node *np) 212 - { 213 - struct device_node *child; 214 - int num = 0; 215 - 216 - for_each_available_child_of_node(np, child) 217 - num++; 218 - 219 - return num; 220 - } 221 212 222 213 /* cache lookup */ 223 214 extern struct device_node *of_find_next_cache_node(const struct device_node *); 224 215 extern struct device_node *of_find_node_with_property( 225 216 struct device_node *from, const char *prop_name); 226 - #define for_each_node_with_property(dn, prop_name) \ 227 - for (dn = of_find_node_with_property(NULL, prop_name); dn; \ 228 - dn = of_find_node_with_property(dn, prop_name)) 229 217 230 218 extern struct property *of_find_property(const struct device_node *np, 231 219 const char *name, ··· 315 367 return NULL; 316 368 } 317 369 370 + static inline struct device_node *of_find_node_by_type(struct device_node *from, 371 + const char *type) 372 + { 373 + return NULL; 374 + } 375 + 376 + static inline struct device_node *of_find_matching_node_and_match( 377 + struct device_node *from, 378 + const struct of_device_id *matches, 379 + const struct of_device_id **match) 380 + { 381 + return NULL; 382 + } 383 + 318 384 static inline struct device_node *of_get_parent(const struct device_node *node) 385 + { 386 + return NULL; 387 + } 388 + 389 + static inline struct device_node *of_get_next_child( 390 + const struct device_node *node, struct device_node *prev) 391 + { 392 + return NULL; 393 + } 394 + 395 + static inline struct device_node *of_get_next_available_child( 396 + const struct device_node *node, struct device_node *prev) 397 + { 398 + return NULL; 399 + } 400 + 401 + static inline struct device_node *of_find_node_with_property( 402 + struct device_node *from, const char *prop_name) 319 403 { 320 404 return NULL; 321 405 } ··· 357 377 return false; 358 378 } 359 379 360 - /* Kill an unused variable warning on a device_node pointer */ 361 - static inline void __of_use_dn(const struct device_node *np) 362 - { 363 - } 364 - 365 - #define for_each_child_of_node(parent, child) \ 366 - while (__of_use_dn(parent), __of_use_dn(child), 0) 367 - 368 - #define for_each_available_child_of_node(parent, child) \ 369 - while (0) 370 - 371 380 static inline struct device_node *of_get_child_by_name( 372 381 const struct device_node *node, 373 382 const char *name) 374 383 { 375 384 return NULL; 376 - } 377 - 378 - static inline int of_get_child_count(const struct device_node *np) 379 - { 380 - return 0; 381 - } 382 - 383 - static inline int of_get_available_child_count(const struct device_node *np) 384 - { 385 - return 0; 386 385 } 387 386 388 387 static inline int of_device_is_compatible(const struct device_node *device, ··· 528 569 static inline int of_node_to_nid(struct device_node *device) { return 0; } 529 570 #endif 530 571 572 + static inline struct device_node *of_find_matching_node( 573 + struct device_node *from, 574 + const struct of_device_id *matches) 575 + { 576 + return of_find_matching_node_and_match(from, matches, NULL); 577 + } 578 + 531 579 /** 532 580 * of_property_read_bool - Findfrom a property 533 581 * @np: device node from which the property value is to be read. ··· 583 617 s = of_prop_next_string(prop, NULL); \ 584 618 s; \ 585 619 s = of_prop_next_string(prop, s)) 620 + 621 + #define for_each_node_by_name(dn, name) \ 622 + for (dn = of_find_node_by_name(NULL, name); dn; \ 623 + dn = of_find_node_by_name(dn, name)) 624 + #define for_each_node_by_type(dn, type) \ 625 + for (dn = of_find_node_by_type(NULL, type); dn; \ 626 + dn = of_find_node_by_type(dn, type)) 627 + #define for_each_compatible_node(dn, type, compatible) \ 628 + for (dn = of_find_compatible_node(NULL, type, compatible); dn; \ 629 + dn = of_find_compatible_node(dn, type, compatible)) 630 + #define for_each_matching_node(dn, matches) \ 631 + for (dn = of_find_matching_node(NULL, matches); dn; \ 632 + dn = of_find_matching_node(dn, matches)) 633 + #define for_each_matching_node_and_match(dn, matches, match) \ 634 + for (dn = of_find_matching_node_and_match(NULL, matches, match); \ 635 + dn; dn = of_find_matching_node_and_match(dn, matches, match)) 636 + 637 + #define for_each_child_of_node(parent, child) \ 638 + for (child = of_get_next_child(parent, NULL); child != NULL; \ 639 + child = of_get_next_child(parent, child)) 640 + #define for_each_available_child_of_node(parent, child) \ 641 + for (child = of_get_next_available_child(parent, NULL); child != NULL; \ 642 + child = of_get_next_available_child(parent, child)) 643 + 644 + #define for_each_node_with_property(dn, prop_name) \ 645 + for (dn = of_find_node_with_property(NULL, prop_name); dn; \ 646 + dn = of_find_node_with_property(dn, prop_name)) 647 + 648 + static inline int of_get_child_count(const struct device_node *np) 649 + { 650 + struct device_node *child; 651 + int num = 0; 652 + 653 + for_each_child_of_node(np, child) 654 + num++; 655 + 656 + return num; 657 + } 658 + 659 + static inline int of_get_available_child_count(const struct device_node *np) 660 + { 661 + struct device_node *child; 662 + int num = 0; 663 + 664 + for_each_available_child_of_node(np, child) 665 + num++; 666 + 667 + return num; 668 + } 586 669 587 670 #if defined(CONFIG_PROC_FS) && defined(CONFIG_PROC_DEVICETREE) 588 671 extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *);