@@ -1021,6 +1021,16 @@ static void anx7411_port_unregister_altmodes(struct typec_altmode **adev)
1021
1021
}
1022
1022
}
1023
1023
1024
+ static void anx7411_port_unregister (struct typec_params * typecp )
1025
+ {
1026
+ fwnode_handle_put (typecp -> caps .fwnode );
1027
+ anx7411_port_unregister_altmodes (typecp -> port_amode );
1028
+ if (typecp -> port )
1029
+ typec_unregister_port (typecp -> port );
1030
+ if (typecp -> role_sw )
1031
+ usb_role_switch_put (typecp -> role_sw );
1032
+ }
1033
+
1024
1034
static int anx7411_usb_mux_set (struct typec_mux_dev * mux ,
1025
1035
struct typec_mux_state * state )
1026
1036
{
@@ -1154,34 +1164,34 @@ static int anx7411_typec_port_probe(struct anx7411_data *ctx,
1154
1164
ret = fwnode_property_read_string (fwnode , "power-role" , & buf );
1155
1165
if (ret ) {
1156
1166
dev_err (dev , "power-role not found: %d\n" , ret );
1157
- return ret ;
1167
+ goto put_fwnode ;
1158
1168
}
1159
1169
1160
1170
ret = typec_find_port_power_role (buf );
1161
1171
if (ret < 0 )
1162
- return ret ;
1172
+ goto put_fwnode ;
1163
1173
cap -> type = ret ;
1164
1174
1165
1175
ret = fwnode_property_read_string (fwnode , "data-role" , & buf );
1166
1176
if (ret ) {
1167
1177
dev_err (dev , "data-role not found: %d\n" , ret );
1168
- return ret ;
1178
+ goto put_fwnode ;
1169
1179
}
1170
1180
1171
1181
ret = typec_find_port_data_role (buf );
1172
1182
if (ret < 0 )
1173
- return ret ;
1183
+ goto put_fwnode ;
1174
1184
cap -> data = ret ;
1175
1185
1176
1186
ret = fwnode_property_read_string (fwnode , "try-power-role" , & buf );
1177
1187
if (ret ) {
1178
1188
dev_err (dev , "try-power-role not found: %d\n" , ret );
1179
- return ret ;
1189
+ goto put_fwnode ;
1180
1190
}
1181
1191
1182
1192
ret = typec_find_power_role (buf );
1183
1193
if (ret < 0 )
1184
- return ret ;
1194
+ goto put_fwnode ;
1185
1195
cap -> prefer_role = ret ;
1186
1196
1187
1197
/* Get source pdos */
@@ -1193,7 +1203,7 @@ static int anx7411_typec_port_probe(struct anx7411_data *ctx,
1193
1203
typecp -> src_pdo_nr );
1194
1204
if (ret < 0 ) {
1195
1205
dev_err (dev , "source cap validate failed: %d\n" , ret );
1196
- return - EINVAL ;
1206
+ goto put_fwnode ;
1197
1207
}
1198
1208
1199
1209
typecp -> caps_flags |= HAS_SOURCE_CAP ;
@@ -1207,7 +1217,7 @@ static int anx7411_typec_port_probe(struct anx7411_data *ctx,
1207
1217
typecp -> sink_pdo_nr );
1208
1218
if (ret < 0 ) {
1209
1219
dev_err (dev , "sink cap validate failed: %d\n" , ret );
1210
- return - EINVAL ;
1220
+ goto put_fwnode ;
1211
1221
}
1212
1222
1213
1223
for (i = 0 ; i < typecp -> sink_pdo_nr ; i ++ ) {
@@ -1251,13 +1261,21 @@ static int anx7411_typec_port_probe(struct anx7411_data *ctx,
1251
1261
ret = PTR_ERR (ctx -> typec .port );
1252
1262
ctx -> typec .port = NULL ;
1253
1263
dev_err (dev , "Failed to register type c port %d\n" , ret );
1254
- return ret ;
1264
+ goto put_usb_role_switch ;
1255
1265
}
1256
1266
1257
1267
typec_port_register_altmodes (ctx -> typec .port , NULL , ctx ,
1258
1268
ctx -> typec .port_amode ,
1259
1269
MAX_ALTMODE );
1260
1270
return 0 ;
1271
+
1272
+ put_usb_role_switch :
1273
+ if (ctx -> typec .role_sw )
1274
+ usb_role_switch_put (ctx -> typec .role_sw );
1275
+ put_fwnode :
1276
+ fwnode_handle_put (fwnode );
1277
+
1278
+ return ret ;
1261
1279
}
1262
1280
1263
1281
static int anx7411_typec_check_connection (struct anx7411_data * ctx )
@@ -1523,8 +1541,7 @@ static int anx7411_i2c_probe(struct i2c_client *client)
1523
1541
destroy_workqueue (plat -> workqueue );
1524
1542
1525
1543
free_typec_port :
1526
- typec_unregister_port (plat -> typec .port );
1527
- anx7411_port_unregister_altmodes (plat -> typec .port_amode );
1544
+ anx7411_port_unregister (& plat -> typec );
1528
1545
1529
1546
free_typec_switch :
1530
1547
anx7411_unregister_switch (plat );
@@ -1548,17 +1565,11 @@ static void anx7411_i2c_remove(struct i2c_client *client)
1548
1565
1549
1566
i2c_unregister_device (plat -> spi_client );
1550
1567
1551
- if (plat -> typec .role_sw )
1552
- usb_role_switch_put (plat -> typec .role_sw );
1553
-
1554
1568
anx7411_unregister_mux (plat );
1555
1569
1556
1570
anx7411_unregister_switch (plat );
1557
1571
1558
- if (plat -> typec .port )
1559
- typec_unregister_port (plat -> typec .port );
1560
-
1561
- anx7411_port_unregister_altmodes (plat -> typec .port_amode );
1572
+ anx7411_port_unregister (& plat -> typec );
1562
1573
}
1563
1574
1564
1575
static const struct i2c_device_id anx7411_id [] = {
0 commit comments