@@ -486,34 +486,30 @@ static int of_translate_one(struct device_node *parent, struct of_bus *bus,
486
486
* device that had registered logical PIO mapping, and the return code is
487
487
* relative to that node.
488
488
*/
489
- static u64 __of_translate_address (struct device_node * dev ,
489
+ static u64 __of_translate_address (struct device_node * node ,
490
490
struct device_node * (* get_parent )(const struct device_node * ),
491
491
const __be32 * in_addr , const char * rprop ,
492
492
struct device_node * * host )
493
493
{
494
- struct device_node * parent = NULL ;
494
+ struct device_node * dev __free (device_node ) = of_node_get (node );
495
+ struct device_node * parent __free (device_node ) = get_parent (dev );
495
496
struct of_bus * bus , * pbus ;
496
497
__be32 addr [OF_MAX_ADDR_CELLS ];
497
498
int na , ns , pna , pns ;
498
- u64 result = OF_BAD_ADDR ;
499
499
500
500
pr_debug ("** translation for device %pOF **\n" , dev );
501
501
502
- /* Increase refcount at current level */
503
- of_node_get (dev );
504
-
505
502
* host = NULL ;
506
- /* Get parent & match bus type */
507
- parent = get_parent (dev );
503
+
508
504
if (parent == NULL )
509
- goto bail ;
505
+ return OF_BAD_ADDR ;
510
506
bus = of_match_bus (parent );
511
507
512
508
/* Count address cells & copy address locally */
513
509
bus -> count_cells (dev , & na , & ns );
514
510
if (!OF_CHECK_COUNTS (na , ns )) {
515
511
pr_debug ("Bad cell count for %pOF\n" , dev );
516
- goto bail ;
512
+ return OF_BAD_ADDR ;
517
513
}
518
514
memcpy (addr , in_addr , na * 4 );
519
515
@@ -533,8 +529,7 @@ static u64 __of_translate_address(struct device_node *dev,
533
529
/* If root, we have finished */
534
530
if (parent == NULL ) {
535
531
pr_debug ("reached root node\n" );
536
- result = of_read_number (addr , na );
537
- break ;
532
+ return of_read_number (addr , na );
538
533
}
539
534
540
535
/*
@@ -543,27 +538,27 @@ static u64 __of_translate_address(struct device_node *dev,
543
538
*/
544
539
iorange = find_io_range_by_fwnode (& dev -> fwnode );
545
540
if (iorange && (iorange -> flags != LOGIC_PIO_CPU_MMIO )) {
546
- result = of_read_number (addr + 1 , na - 1 );
541
+ u64 result = of_read_number (addr + 1 , na - 1 );
547
542
pr_debug ("indirectIO matched(%pOF) 0x%llx\n" ,
548
543
dev , result );
549
- * host = of_node_get (dev );
550
- break ;
544
+ * host = no_free_ptr (dev );
545
+ return result ;
551
546
}
552
547
553
548
/* Get new parent bus and counts */
554
549
pbus = of_match_bus (parent );
555
550
pbus -> count_cells (dev , & pna , & pns );
556
551
if (!OF_CHECK_COUNTS (pna , pns )) {
557
552
pr_err ("Bad cell count for %pOF\n" , dev );
558
- break ;
553
+ return OF_BAD_ADDR ;
559
554
}
560
555
561
556
pr_debug ("parent bus is %s (na=%d, ns=%d) on %pOF\n" ,
562
557
pbus -> name , pna , pns , parent );
563
558
564
559
/* Apply bus translation */
565
560
if (of_translate_one (dev , bus , pbus , addr , na , ns , pna , rprop ))
566
- break ;
561
+ return OF_BAD_ADDR ;
567
562
568
563
/* Complete the move up one level */
569
564
na = pna ;
@@ -572,11 +567,8 @@ static u64 __of_translate_address(struct device_node *dev,
572
567
573
568
of_dump_addr ("one level translation:" , addr , na );
574
569
}
575
- bail :
576
- of_node_put (parent );
577
- of_node_put (dev );
578
570
579
- return result ;
571
+ unreachable () ;
580
572
}
581
573
582
574
u64 of_translate_address (struct device_node * dev , const __be32 * in_addr )
@@ -654,19 +646,16 @@ EXPORT_SYMBOL(of_translate_dma_address);
654
646
const __be32 * of_translate_dma_region (struct device_node * dev , const __be32 * prop ,
655
647
phys_addr_t * start , size_t * length )
656
648
{
657
- struct device_node * parent ;
649
+ struct device_node * parent __free ( device_node ) = __of_get_dma_parent ( dev ) ;
658
650
u64 address , size ;
659
651
int na , ns ;
660
652
661
- parent = __of_get_dma_parent (dev );
662
653
if (!parent )
663
654
return NULL ;
664
655
665
656
na = of_bus_n_addr_cells (parent );
666
657
ns = of_bus_n_size_cells (parent );
667
658
668
- of_node_put (parent );
669
-
670
659
address = of_translate_dma_address (dev , prop );
671
660
if (address == OF_BAD_ADDR )
672
661
return NULL ;
@@ -688,21 +677,19 @@ const __be32 *__of_get_address(struct device_node *dev, int index, int bar_no,
688
677
{
689
678
const __be32 * prop ;
690
679
unsigned int psize ;
691
- struct device_node * parent ;
680
+ struct device_node * parent __free ( device_node ) = of_get_parent ( dev ) ;
692
681
struct of_bus * bus ;
693
682
int onesize , i , na , ns ;
694
683
695
- /* Get parent & match bus type */
696
- parent = of_get_parent (dev );
697
684
if (parent == NULL )
698
685
return NULL ;
686
+
687
+ /* match the parent's bus type */
699
688
bus = of_match_bus (parent );
700
- if (strcmp (bus -> name , "pci" ) && (bar_no >= 0 )) {
701
- of_node_put (parent );
689
+ if (strcmp (bus -> name , "pci" ) && (bar_no >= 0 ))
702
690
return NULL ;
703
- }
691
+
704
692
bus -> count_cells (dev , & na , & ns );
705
- of_node_put (parent );
706
693
if (!OF_CHECK_ADDR_COUNT (na ))
707
694
return NULL ;
708
695
@@ -888,14 +875,13 @@ static u64 of_translate_ioport(struct device_node *dev, const __be32 *in_addr,
888
875
*/
889
876
int of_dma_get_range (struct device_node * np , const struct bus_dma_region * * map )
890
877
{
891
- struct device_node * node = of_node_get (np );
878
+ struct device_node * node __free ( device_node ) = of_node_get (np );
892
879
const __be32 * ranges = NULL ;
893
880
bool found_dma_ranges = false;
894
881
struct of_range_parser parser ;
895
882
struct of_range range ;
896
883
struct bus_dma_region * r ;
897
884
int len , num_ranges = 0 ;
898
- int ret = 0 ;
899
885
900
886
while (node ) {
901
887
ranges = of_get_property (node , "dma-ranges" , & len );
@@ -905,21 +891,18 @@ int of_dma_get_range(struct device_node *np, const struct bus_dma_region **map)
905
891
break ;
906
892
907
893
/* Once we find 'dma-ranges', then a missing one is an error */
908
- if (found_dma_ranges && !ranges ) {
909
- ret = - ENODEV ;
910
- goto out ;
911
- }
894
+ if (found_dma_ranges && !ranges )
895
+ return - ENODEV ;
896
+
912
897
found_dma_ranges = true;
913
898
914
899
node = of_get_next_dma_parent (node );
915
900
}
916
901
917
902
if (!node || !ranges ) {
918
903
pr_debug ("no dma-ranges found for node(%pOF)\n" , np );
919
- ret = - ENODEV ;
920
- goto out ;
904
+ return - ENODEV ;
921
905
}
922
-
923
906
of_dma_range_parser_init (& parser , node );
924
907
for_each_of_range (& parser , & range ) {
925
908
if (range .cpu_addr == OF_BAD_ADDR ) {
@@ -930,16 +913,12 @@ int of_dma_get_range(struct device_node *np, const struct bus_dma_region **map)
930
913
num_ranges ++ ;
931
914
}
932
915
933
- if (!num_ranges ) {
934
- ret = - EINVAL ;
935
- goto out ;
936
- }
916
+ if (!num_ranges )
917
+ return - EINVAL ;
937
918
938
919
r = kcalloc (num_ranges + 1 , sizeof (* r ), GFP_KERNEL );
939
- if (!r ) {
940
- ret = - ENOMEM ;
941
- goto out ;
942
- }
920
+ if (!r )
921
+ return - ENOMEM ;
943
922
944
923
/*
945
924
* Record all info in the generic DMA ranges array for struct device,
@@ -957,9 +936,7 @@ int of_dma_get_range(struct device_node *np, const struct bus_dma_region **map)
957
936
r -> size = range .size ;
958
937
r ++ ;
959
938
}
960
- out :
961
- of_node_put (node );
962
- return ret ;
939
+ return 0 ;
963
940
}
964
941
#endif /* CONFIG_HAS_DMA */
965
942
@@ -1016,24 +993,18 @@ phys_addr_t __init of_dma_get_max_cpu_address(struct device_node *np)
1016
993
*/
1017
994
bool of_dma_is_coherent (struct device_node * np )
1018
995
{
1019
- struct device_node * node ;
1020
- bool is_coherent = dma_default_coherent ;
1021
-
1022
- node = of_node_get (np );
996
+ struct device_node * node __free (device_node ) = of_node_get (np );
1023
997
1024
998
while (node ) {
1025
- if (of_property_read_bool (node , "dma-coherent" )) {
1026
- is_coherent = true;
1027
- break ;
1028
- }
1029
- if (of_property_read_bool (node , "dma-noncoherent" )) {
1030
- is_coherent = false;
1031
- break ;
1032
- }
999
+ if (of_property_read_bool (node , "dma-coherent" ))
1000
+ return true;
1001
+
1002
+ if (of_property_read_bool (node , "dma-noncoherent" ))
1003
+ return false;
1004
+
1033
1005
node = of_get_next_dma_parent (node );
1034
1006
}
1035
- of_node_put (node );
1036
- return is_coherent ;
1007
+ return dma_default_coherent ;
1037
1008
}
1038
1009
EXPORT_SYMBOL_GPL (of_dma_is_coherent );
1039
1010
@@ -1049,20 +1020,14 @@ EXPORT_SYMBOL_GPL(of_dma_is_coherent);
1049
1020
*/
1050
1021
static bool of_mmio_is_nonposted (struct device_node * np )
1051
1022
{
1052
- struct device_node * parent ;
1053
- bool nonposted ;
1054
-
1055
1023
if (!IS_ENABLED (CONFIG_ARCH_APPLE ))
1056
1024
return false;
1057
1025
1058
- parent = of_get_parent (np );
1026
+ struct device_node * parent __free ( device_node ) = of_get_parent (np );
1059
1027
if (!parent )
1060
1028
return false;
1061
1029
1062
- nonposted = of_property_read_bool (parent , "nonposted-mmio" );
1063
-
1064
- of_node_put (parent );
1065
- return nonposted ;
1030
+ return of_property_read_bool (parent , "nonposted-mmio" );
1066
1031
}
1067
1032
1068
1033
static int __of_address_to_resource (struct device_node * dev , int index , int bar_no ,
0 commit comments