@@ -1058,7 +1058,7 @@ static void mock_companion(struct acpi_device *adev, struct device *dev)
10581058#define SZ_64G (SZ_32G * 2)
10591059#endif
10601060
1061- static __init int cxl_rch_init (void )
1061+ static __init int cxl_rch_topo_init (void )
10621062{
10631063 int rc , i ;
10641064
@@ -1086,30 +1086,8 @@ static __init int cxl_rch_init(void)
10861086 goto err_bridge ;
10871087 }
10881088
1089- for (i = 0 ; i < ARRAY_SIZE (cxl_rcd ); i ++ ) {
1090- int idx = NR_MEM_MULTI + NR_MEM_SINGLE + i ;
1091- struct platform_device * rch = cxl_rch [i ];
1092- struct platform_device * pdev ;
1093-
1094- pdev = platform_device_alloc ("cxl_rcd" , idx );
1095- if (!pdev )
1096- goto err_mem ;
1097- pdev -> dev .parent = & rch -> dev ;
1098- set_dev_node (& pdev -> dev , i % 2 );
1099-
1100- rc = platform_device_add (pdev );
1101- if (rc ) {
1102- platform_device_put (pdev );
1103- goto err_mem ;
1104- }
1105- cxl_rcd [i ] = pdev ;
1106- }
1107-
11081089 return 0 ;
11091090
1110- err_mem :
1111- for (i = ARRAY_SIZE (cxl_rcd ) - 1 ; i >= 0 ; i -- )
1112- platform_device_unregister (cxl_rcd [i ]);
11131091err_bridge :
11141092 for (i = ARRAY_SIZE (cxl_rch ) - 1 ; i >= 0 ; i -- ) {
11151093 struct platform_device * pdev = cxl_rch [i ];
@@ -1123,12 +1101,10 @@ static __init int cxl_rch_init(void)
11231101 return rc ;
11241102}
11251103
1126- static void cxl_rch_exit (void )
1104+ static void cxl_rch_topo_exit (void )
11271105{
11281106 int i ;
11291107
1130- for (i = ARRAY_SIZE (cxl_rcd ) - 1 ; i >= 0 ; i -- )
1131- platform_device_unregister (cxl_rcd [i ]);
11321108 for (i = ARRAY_SIZE (cxl_rch ) - 1 ; i >= 0 ; i -- ) {
11331109 struct platform_device * pdev = cxl_rch [i ];
11341110
@@ -1139,7 +1115,7 @@ static void cxl_rch_exit(void)
11391115 }
11401116}
11411117
1142- static __init int cxl_single_init (void )
1118+ static __init int cxl_single_topo_init (void )
11431119{
11441120 int i , rc ;
11451121
@@ -1224,29 +1200,8 @@ static __init int cxl_single_init(void)
12241200 cxl_swd_single [i ] = pdev ;
12251201 }
12261202
1227- for (i = 0 ; i < ARRAY_SIZE (cxl_mem_single ); i ++ ) {
1228- struct platform_device * dport = cxl_swd_single [i ];
1229- struct platform_device * pdev ;
1230-
1231- pdev = platform_device_alloc ("cxl_mem" , NR_MEM_MULTI + i );
1232- if (!pdev )
1233- goto err_mem ;
1234- pdev -> dev .parent = & dport -> dev ;
1235- set_dev_node (& pdev -> dev , i % 2 );
1236-
1237- rc = platform_device_add (pdev );
1238- if (rc ) {
1239- platform_device_put (pdev );
1240- goto err_mem ;
1241- }
1242- cxl_mem_single [i ] = pdev ;
1243- }
1244-
12451203 return 0 ;
12461204
1247- err_mem :
1248- for (i = ARRAY_SIZE (cxl_mem_single ) - 1 ; i >= 0 ; i -- )
1249- platform_device_unregister (cxl_mem_single [i ]);
12501205err_dport :
12511206 for (i = ARRAY_SIZE (cxl_swd_single ) - 1 ; i >= 0 ; i -- )
12521207 platform_device_unregister (cxl_swd_single [i ]);
@@ -1269,12 +1224,10 @@ static __init int cxl_single_init(void)
12691224 return rc ;
12701225}
12711226
1272- static void cxl_single_exit (void )
1227+ static void cxl_single_topo_exit (void )
12731228{
12741229 int i ;
12751230
1276- for (i = ARRAY_SIZE (cxl_mem_single ) - 1 ; i >= 0 ; i -- )
1277- platform_device_unregister (cxl_mem_single [i ]);
12781231 for (i = ARRAY_SIZE (cxl_swd_single ) - 1 ; i >= 0 ; i -- )
12791232 platform_device_unregister (cxl_swd_single [i ]);
12801233 for (i = ARRAY_SIZE (cxl_swu_single ) - 1 ; i >= 0 ; i -- )
@@ -1291,6 +1244,91 @@ static void cxl_single_exit(void)
12911244 }
12921245}
12931246
1247+ static void cxl_mem_exit (void )
1248+ {
1249+ int i ;
1250+
1251+ for (i = ARRAY_SIZE (cxl_rcd ) - 1 ; i >= 0 ; i -- )
1252+ platform_device_unregister (cxl_rcd [i ]);
1253+ for (i = ARRAY_SIZE (cxl_mem_single ) - 1 ; i >= 0 ; i -- )
1254+ platform_device_unregister (cxl_mem_single [i ]);
1255+ for (i = ARRAY_SIZE (cxl_mem ) - 1 ; i >= 0 ; i -- )
1256+ platform_device_unregister (cxl_mem [i ]);
1257+ }
1258+
1259+ static int cxl_mem_init (void )
1260+ {
1261+ int i , rc ;
1262+
1263+ for (i = 0 ; i < ARRAY_SIZE (cxl_mem ); i ++ ) {
1264+ struct platform_device * dport = cxl_switch_dport [i ];
1265+ struct platform_device * pdev ;
1266+
1267+ pdev = platform_device_alloc ("cxl_mem" , i );
1268+ if (!pdev )
1269+ goto err_mem ;
1270+ pdev -> dev .parent = & dport -> dev ;
1271+ set_dev_node (& pdev -> dev , i % 2 );
1272+
1273+ rc = platform_device_add (pdev );
1274+ if (rc ) {
1275+ platform_device_put (pdev );
1276+ goto err_mem ;
1277+ }
1278+ cxl_mem [i ] = pdev ;
1279+ }
1280+
1281+ for (i = 0 ; i < ARRAY_SIZE (cxl_mem_single ); i ++ ) {
1282+ struct platform_device * dport = cxl_swd_single [i ];
1283+ struct platform_device * pdev ;
1284+
1285+ pdev = platform_device_alloc ("cxl_mem" , NR_MEM_MULTI + i );
1286+ if (!pdev )
1287+ goto err_single ;
1288+ pdev -> dev .parent = & dport -> dev ;
1289+ set_dev_node (& pdev -> dev , i % 2 );
1290+
1291+ rc = platform_device_add (pdev );
1292+ if (rc ) {
1293+ platform_device_put (pdev );
1294+ goto err_single ;
1295+ }
1296+ cxl_mem_single [i ] = pdev ;
1297+ }
1298+
1299+ for (i = 0 ; i < ARRAY_SIZE (cxl_rcd ); i ++ ) {
1300+ int idx = NR_MEM_MULTI + NR_MEM_SINGLE + i ;
1301+ struct platform_device * rch = cxl_rch [i ];
1302+ struct platform_device * pdev ;
1303+
1304+ pdev = platform_device_alloc ("cxl_rcd" , idx );
1305+ if (!pdev )
1306+ goto err_rcd ;
1307+ pdev -> dev .parent = & rch -> dev ;
1308+ set_dev_node (& pdev -> dev , i % 2 );
1309+
1310+ rc = platform_device_add (pdev );
1311+ if (rc ) {
1312+ platform_device_put (pdev );
1313+ goto err_rcd ;
1314+ }
1315+ cxl_rcd [i ] = pdev ;
1316+ }
1317+
1318+ return 0 ;
1319+
1320+ err_rcd :
1321+ for (i = ARRAY_SIZE (cxl_rcd ) - 1 ; i >= 0 ; i -- )
1322+ platform_device_unregister (cxl_rcd [i ]);
1323+ err_single :
1324+ for (i = ARRAY_SIZE (cxl_mem_single ) - 1 ; i >= 0 ; i -- )
1325+ platform_device_unregister (cxl_mem_single [i ]);
1326+ err_mem :
1327+ for (i = ARRAY_SIZE (cxl_mem ) - 1 ; i >= 0 ; i -- )
1328+ platform_device_unregister (cxl_mem [i ]);
1329+ return rc ;
1330+ }
1331+
12941332static __init int cxl_test_init (void )
12951333{
12961334 int rc , i ;
@@ -1403,29 +1441,11 @@ static __init int cxl_test_init(void)
14031441 cxl_switch_dport [i ] = pdev ;
14041442 }
14051443
1406- for (i = 0 ; i < ARRAY_SIZE (cxl_mem ); i ++ ) {
1407- struct platform_device * dport = cxl_switch_dport [i ];
1408- struct platform_device * pdev ;
1409-
1410- pdev = platform_device_alloc ("cxl_mem" , i );
1411- if (!pdev )
1412- goto err_mem ;
1413- pdev -> dev .parent = & dport -> dev ;
1414- set_dev_node (& pdev -> dev , i % 2 );
1415-
1416- rc = platform_device_add (pdev );
1417- if (rc ) {
1418- platform_device_put (pdev );
1419- goto err_mem ;
1420- }
1421- cxl_mem [i ] = pdev ;
1422- }
1423-
1424- rc = cxl_single_init ();
1444+ rc = cxl_single_topo_init ();
14251445 if (rc )
1426- goto err_mem ;
1446+ goto err_dport ;
14271447
1428- rc = cxl_rch_init ();
1448+ rc = cxl_rch_topo_init ();
14291449 if (rc )
14301450 goto err_single ;
14311451
@@ -1438,19 +1458,20 @@ static __init int cxl_test_init(void)
14381458
14391459 rc = platform_device_add (cxl_acpi );
14401460 if (rc )
1441- goto err_add ;
1461+ goto err_root ;
1462+
1463+ rc = cxl_mem_init ();
1464+ if (rc )
1465+ goto err_root ;
14421466
14431467 return 0 ;
14441468
1445- err_add :
1469+ err_root :
14461470 platform_device_put (cxl_acpi );
14471471err_rch :
1448- cxl_rch_exit ();
1472+ cxl_rch_topo_exit ();
14491473err_single :
1450- cxl_single_exit ();
1451- err_mem :
1452- for (i = ARRAY_SIZE (cxl_mem ) - 1 ; i >= 0 ; i -- )
1453- platform_device_unregister (cxl_mem [i ]);
1474+ cxl_single_topo_exit ();
14541475err_dport :
14551476 for (i = ARRAY_SIZE (cxl_switch_dport ) - 1 ; i >= 0 ; i -- )
14561477 platform_device_unregister (cxl_switch_dport [i ]);
@@ -1482,11 +1503,10 @@ static __exit void cxl_test_exit(void)
14821503{
14831504 int i ;
14841505
1506+ cxl_mem_exit ();
14851507 platform_device_unregister (cxl_acpi );
1486- cxl_rch_exit ();
1487- cxl_single_exit ();
1488- for (i = ARRAY_SIZE (cxl_mem ) - 1 ; i >= 0 ; i -- )
1489- platform_device_unregister (cxl_mem [i ]);
1508+ cxl_rch_topo_exit ();
1509+ cxl_single_topo_exit ();
14901510 for (i = ARRAY_SIZE (cxl_switch_dport ) - 1 ; i >= 0 ; i -- )
14911511 platform_device_unregister (cxl_switch_dport [i ]);
14921512 for (i = ARRAY_SIZE (cxl_switch_uport ) - 1 ; i >= 0 ; i -- )
0 commit comments