@@ -1065,9 +1065,9 @@ void pwm_put(struct pwm_device *pwm)
1065
1065
}
1066
1066
EXPORT_SYMBOL_GPL (pwm_put );
1067
1067
1068
- static void devm_pwm_release (struct device * dev , void * res )
1068
+ static void devm_pwm_release (void * pwm )
1069
1069
{
1070
- pwm_put (* ( struct pwm_device * * ) res );
1070
+ pwm_put (pwm );
1071
1071
}
1072
1072
1073
1073
/**
@@ -1083,19 +1083,16 @@ static void devm_pwm_release(struct device *dev, void *res)
1083
1083
*/
1084
1084
struct pwm_device * devm_pwm_get (struct device * dev , const char * con_id )
1085
1085
{
1086
- struct pwm_device * * ptr , * pwm ;
1087
-
1088
- ptr = devres_alloc (devm_pwm_release , sizeof (* ptr ), GFP_KERNEL );
1089
- if (!ptr )
1090
- return ERR_PTR (- ENOMEM );
1086
+ struct pwm_device * pwm ;
1087
+ int ret ;
1091
1088
1092
1089
pwm = pwm_get (dev , con_id );
1093
- if (! IS_ERR (pwm )) {
1094
- * ptr = pwm ;
1095
- devres_add ( dev , ptr );
1096
- } else {
1097
- devres_free ( ptr );
1098
- }
1090
+ if (IS_ERR (pwm ))
1091
+ return pwm ;
1092
+
1093
+ ret = devm_add_action_or_reset ( dev , devm_pwm_release , pwm );
1094
+ if ( ret )
1095
+ return ERR_PTR ( ret );
1099
1096
1100
1097
return pwm ;
1101
1098
}
@@ -1116,19 +1113,16 @@ EXPORT_SYMBOL_GPL(devm_pwm_get);
1116
1113
struct pwm_device * devm_of_pwm_get (struct device * dev , struct device_node * np ,
1117
1114
const char * con_id )
1118
1115
{
1119
- struct pwm_device * * ptr , * pwm ;
1120
-
1121
- ptr = devres_alloc (devm_pwm_release , sizeof (* ptr ), GFP_KERNEL );
1122
- if (!ptr )
1123
- return ERR_PTR (- ENOMEM );
1116
+ struct pwm_device * pwm ;
1117
+ int ret ;
1124
1118
1125
1119
pwm = of_pwm_get (dev , np , con_id );
1126
- if (! IS_ERR (pwm )) {
1127
- * ptr = pwm ;
1128
- devres_add ( dev , ptr );
1129
- } else {
1130
- devres_free ( ptr );
1131
- }
1120
+ if (IS_ERR (pwm ))
1121
+ return pwm ;
1122
+
1123
+ ret = devm_add_action_or_reset ( dev , devm_pwm_release , pwm );
1124
+ if ( ret )
1125
+ return ERR_PTR ( ret );
1132
1126
1133
1127
return pwm ;
1134
1128
}
@@ -1150,23 +1144,19 @@ struct pwm_device *devm_fwnode_pwm_get(struct device *dev,
1150
1144
struct fwnode_handle * fwnode ,
1151
1145
const char * con_id )
1152
1146
{
1153
- struct pwm_device * * ptr , * pwm = ERR_PTR (- ENODEV );
1154
-
1155
- ptr = devres_alloc (devm_pwm_release , sizeof (* ptr ), GFP_KERNEL );
1156
- if (!ptr )
1157
- return ERR_PTR (- ENOMEM );
1147
+ struct pwm_device * pwm = ERR_PTR (- ENODEV );
1148
+ int ret ;
1158
1149
1159
1150
if (is_of_node (fwnode ))
1160
1151
pwm = of_pwm_get (dev , to_of_node (fwnode ), con_id );
1161
1152
else if (is_acpi_node (fwnode ))
1162
1153
pwm = acpi_pwm_get (fwnode );
1154
+ if (IS_ERR (pwm ))
1155
+ return pwm ;
1163
1156
1164
- if (!IS_ERR (pwm )) {
1165
- * ptr = pwm ;
1166
- devres_add (dev , ptr );
1167
- } else {
1168
- devres_free (ptr );
1169
- }
1157
+ ret = devm_add_action_or_reset (dev , devm_pwm_release , pwm );
1158
+ if (ret )
1159
+ return ERR_PTR (ret );
1170
1160
1171
1161
return pwm ;
1172
1162
}
0 commit comments