@@ -693,7 +693,8 @@ static int of_find_trip_id(struct device_node *np, struct device_node *trip)
693
693
*
694
694
* Return: 0 on success, proper error code otherwise
695
695
*/
696
- static int thermal_of_populate_bind_params (struct device_node * np ,
696
+ static int thermal_of_populate_bind_params (struct device_node * tz_np ,
697
+ struct device_node * np ,
697
698
struct __thermal_bind_params * __tbp )
698
699
{
699
700
struct of_phandle_args cooling_spec ;
@@ -715,7 +716,7 @@ static int thermal_of_populate_bind_params(struct device_node *np,
715
716
return - ENODEV ;
716
717
}
717
718
718
- trip_id = of_find_trip_id (np , trip );
719
+ trip_id = of_find_trip_id (tz_np , trip );
719
720
if (trip_id < 0 ) {
720
721
ret = trip_id ;
721
722
goto end ;
@@ -849,6 +850,53 @@ static int thermal_of_populate_trip(struct device_node *np,
849
850
return 0 ;
850
851
}
851
852
853
+ static struct thermal_trip * thermal_of_trips_init (struct device_node * np , int * ntrips )
854
+ {
855
+ struct thermal_trip * tt ;
856
+ struct device_node * trips , * trip ;
857
+ int ret , count ;
858
+
859
+ trips = of_get_child_by_name (np , "trips" );
860
+ if (!trips ) {
861
+ pr_err ("Failed to find 'trips' node\n" );
862
+ return ERR_PTR (- EINVAL );
863
+ }
864
+
865
+ count = of_get_child_count (trips );
866
+ if (!count ) {
867
+ pr_err ("No trip point defined\n" );
868
+ ret = - EINVAL ;
869
+ goto out_of_node_put ;
870
+ }
871
+
872
+ tt = kzalloc (sizeof (* tt ) * count , GFP_KERNEL );
873
+ if (!tt ) {
874
+ ret = - ENOMEM ;
875
+ goto out_of_node_put ;
876
+ }
877
+
878
+ * ntrips = count ;
879
+
880
+ count = 0 ;
881
+ for_each_child_of_node (trips , trip ) {
882
+ ret = thermal_of_populate_trip (trip , & tt [count ++ ]);
883
+ if (ret )
884
+ goto out_kfree ;
885
+ }
886
+
887
+ of_node_put (trips );
888
+
889
+ return tt ;
890
+
891
+ out_kfree :
892
+ kfree (tt );
893
+ * ntrips = 0 ;
894
+ out_of_node_put :
895
+ of_node_put (trips );
896
+
897
+ return ERR_PTR (ret );
898
+ }
899
+
852
900
/**
853
901
* thermal_of_build_thermal_zone - parse and fill one thermal zone data
854
902
* @np: DT node containing a thermal zone node
@@ -867,7 +915,6 @@ static struct __thermal_zone
867
915
__init * thermal_of_build_thermal_zone (struct device_node * np )
868
916
{
869
917
struct device_node * child = NULL , * gchild ;
870
- struct device_node * trips ;
871
918
struct __thermal_zone * tz ;
872
919
int ret , i ;
873
920
u32 prop , coef [2 ];
@@ -909,28 +956,10 @@ __init *thermal_of_build_thermal_zone(struct device_node *np)
909
956
tz -> offset = 0 ;
910
957
}
911
958
912
- /* trips */
913
- trips = of_get_child_by_name (np , "trips" );
914
-
915
- /* No trips provided */
916
- if (!trips )
959
+ tz -> trips = thermal_of_trips_init (np , & tz -> ntrips );
960
+ if (IS_ERR (tz -> trips )) {
961
+ ret = PTR_ERR (tz -> trips );
917
962
goto finish ;
918
-
919
- tz -> ntrips = of_get_child_count (trips );
920
- if (tz -> ntrips == 0 ) /* must have at least one child */
921
- goto finish ;
922
-
923
- tz -> trips = kcalloc (tz -> ntrips , sizeof (* tz -> trips ), GFP_KERNEL );
924
- if (!tz -> trips ) {
925
- ret = - ENOMEM ;
926
- goto free_tz ;
927
- }
928
-
929
- i = 0 ;
930
- for_each_child_of_node (trips , gchild ) {
931
- ret = thermal_of_populate_trip (gchild , & tz -> trips [i ++ ]);
932
- if (ret )
933
- goto free_trips ;
934
963
}
935
964
936
965
/* cooling-maps */
@@ -952,13 +981,14 @@ __init *thermal_of_build_thermal_zone(struct device_node *np)
952
981
953
982
i = 0 ;
954
983
for_each_child_of_node (child , gchild ) {
955
- ret = thermal_of_populate_bind_params (gchild , & tz -> tbps [i ++ ]);
956
- if (ret )
984
+ ret = thermal_of_populate_bind_params (np , gchild , & tz -> tbps [i ++ ]);
985
+ if (ret ) {
986
+ of_node_put (gchild );
957
987
goto free_tbps ;
988
+ }
958
989
}
959
990
960
991
finish :
961
- of_node_put (trips );
962
992
of_node_put (child );
963
993
964
994
return tz ;
@@ -977,8 +1007,6 @@ __init *thermal_of_build_thermal_zone(struct device_node *np)
977
1007
kfree (tz -> tbps );
978
1008
free_trips :
979
1009
kfree (tz -> trips );
980
- of_node_put (trips );
981
- of_node_put (gchild );
982
1010
free_tz :
983
1011
kfree (tz );
984
1012
of_node_put (child );
0 commit comments