@@ -596,17 +596,17 @@ EXPORT_SYMBOL_GPL(fwnode_get_next_parent);
596
596
*/
597
597
struct device * fwnode_get_next_parent_dev (struct fwnode_handle * fwnode )
598
598
{
599
+ struct fwnode_handle * parent ;
599
600
struct device * dev ;
600
601
601
- fwnode_handle_get (fwnode );
602
- do {
603
- fwnode = fwnode_get_next_parent (fwnode );
604
- if (!fwnode )
605
- return NULL ;
602
+ fwnode_for_each_parent_node (fwnode , parent ) {
606
603
dev = get_dev_from_fwnode (fwnode );
607
- } while (!dev );
608
- fwnode_handle_put (fwnode );
609
- return dev ;
604
+ if (dev ) {
605
+ fwnode_handle_put (parent );
606
+ return dev ;
607
+ }
608
+ }
609
+ return NULL ;
610
610
}
611
611
612
612
/**
@@ -617,13 +617,11 @@ struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode)
617
617
*/
618
618
unsigned int fwnode_count_parents (const struct fwnode_handle * fwnode )
619
619
{
620
- struct fwnode_handle * __fwnode ;
621
- unsigned int count ;
622
-
623
- __fwnode = fwnode_get_parent (fwnode );
620
+ struct fwnode_handle * parent ;
621
+ unsigned int count = 0 ;
624
622
625
- for ( count = 0 ; __fwnode ; count ++ )
626
- __fwnode = fwnode_get_next_parent ( __fwnode ) ;
623
+ fwnode_for_each_parent_node ( fwnode , parent )
624
+ count ++ ;
627
625
628
626
return count ;
629
627
}
@@ -644,15 +642,16 @@ EXPORT_SYMBOL_GPL(fwnode_count_parents);
644
642
struct fwnode_handle * fwnode_get_nth_parent (struct fwnode_handle * fwnode ,
645
643
unsigned int depth )
646
644
{
647
- fwnode_handle_get ( fwnode ) ;
645
+ struct fwnode_handle * parent ;
648
646
649
- do {
650
- if (depth -- == 0 )
651
- break ;
652
- fwnode = fwnode_get_next_parent (fwnode );
653
- } while (fwnode );
647
+ if (depth == 0 )
648
+ return fwnode_handle_get (fwnode );
654
649
655
- return fwnode ;
650
+ fwnode_for_each_parent_node (fwnode , parent ) {
651
+ if (-- depth == 0 )
652
+ return parent ;
653
+ }
654
+ return NULL ;
656
655
}
657
656
EXPORT_SYMBOL_GPL (fwnode_get_nth_parent );
658
657
@@ -669,17 +668,20 @@ EXPORT_SYMBOL_GPL(fwnode_get_nth_parent);
669
668
bool fwnode_is_ancestor_of (struct fwnode_handle * test_ancestor ,
670
669
struct fwnode_handle * test_child )
671
670
{
671
+ struct fwnode_handle * parent ;
672
+
672
673
if (IS_ERR_OR_NULL (test_ancestor ))
673
674
return false;
674
675
675
- fwnode_handle_get (test_child );
676
- do {
677
- if (test_child == test_ancestor ) {
678
- fwnode_handle_put (test_child );
676
+ if (test_child == test_ancestor )
677
+ return true;
678
+
679
+ fwnode_for_each_parent_node (test_child , parent ) {
680
+ if (parent == test_ancestor ) {
681
+ fwnode_handle_put (parent );
679
682
return true;
680
683
}
681
- test_child = fwnode_get_next_parent (test_child );
682
- } while (test_child );
684
+ }
683
685
return false;
684
686
}
685
687
0 commit comments