Skip to contentSkip to conversation

cxl/test: Free the decoder registry when cxl_test_init() fails

PATCH Applied Alison Schofield 3 participants 3 messages Nov 6 – Nov 16 CXL

lore
Share & tools
lore

Alison Schofield

author maintainer
#0 lore raw

PATCH 1/1 cxl/test: Free the decoder registry when cxl_test_init() fails

Decoder registry entries persist across mock device removal to support topology replay. Sashiko review found that if cxl_test_init() fails after decoders are enumerated, the entries leak because cxl_test_exit() is never called.

Free the registry entries and destroy the xarray during error unwind.

Fixes f3b1d2260703 ("tools/testing/cxl: Enable replay of user regions as auto regions")
---
 tools/testing/cxl/test/cxl.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
tools/testing/cxl/test/cxl.c +13 -11
index 3eb1051b1ee8..e3bed17ae253 100644
@@ -2436,6 +2436,17 @@ static int cxl_topo_init(void)
 	return cxl_type3_topo_init();
 }
 
+static void free_decoder_registry(void)
+{
+	unsigned long index;
+	void *entry;
+
+	xa_for_each(&decoder_registry, index, entry) {
+		xa_erase(&decoder_registry, index);
+		kfree(entry);
+	}
+}
+
 static __init int cxl_test_init(void)
 {
 	struct range mappable;
@@ -2525,20 +2536,11 @@ static __init int cxl_test_init(void)
 	gen_pool_destroy(cxl_mock_pool);
 err_gen_pool_create:
 	unregister_cxl_mock_ops(&cxl_mock_ops);
+	free_decoder_registry();
+	xa_destroy(&decoder_registry);
 	return rc;
 }
 
-static void free_decoder_registry(void)
-{
-	unsigned long index;
-	void *entry;
-
-	xa_for_each(&decoder_registry, index, entry) {
-		xa_erase(&decoder_registry, index);
-		kfree(entry);
-	}
-}
-
 static __exit void cxl_test_exit(void)
 {
 	hmem_test_exit();

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

Signature · 1 line
2.37.3
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · On Fri, 6 Nov 2026 14:22:37 -0800 Alison Schofield…

Decoder registry entries persist across mock device removal to support topology replay. Sashiko review found that if cxl_test_init() fails after decoders are enumerated, the entries leak because cxl_test_exit() is never called.

Free the registry entries and destroy the xarray during error unwind.

Fixes f3b1d2260703 ("tools/testing/cxl: Enable replay of user regions as auto regions")
maintainer Applied
#2 lore raw
In reply to Alison Schofield
Quoted 9 lines · Alison Schofield

Decoder registry entries persist across mock device removal to support topology replay. Sashiko review found that if cxl_test_init() fails after decoders are enumerated, the entries leak because cxl_test_exit() is never called.

Free the registry entries and destroy the xarray during error unwind.

Fixes f3b1d2260703 ("tools/testing/cxl: Enable replay of user regions as auto regions")

Applied to cxl/fixes:
a5fb83dcf19a

Quoted 51 lines
---
 tools/testing/cxl/test/cxl.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
tools/testing/cxl/test/cxl.c +13 -11
index 3eb1051b1ee8..e3bed17ae253 100644
@@ -2436,6 +2436,17 @@ static int cxl_topo_init(void)
 	return cxl_type3_topo_init();
 }
 
+static void free_decoder_registry(void)
+{
+	unsigned long index;
+	void *entry;
+
+	xa_for_each(&decoder_registry, index, entry) {
+		xa_erase(&decoder_registry, index);
+		kfree(entry);
+	}
+}
+
 static __init int cxl_test_init(void)
 {
 	struct range mappable;
@@ -2525,20 +2536,11 @@ static __init int cxl_test_init(void)
 	gen_pool_destroy(cxl_mock_pool);
 err_gen_pool_create:
 	unregister_cxl_mock_ops(&cxl_mock_ops);
+	free_decoder_registry();
+	xa_destroy(&decoder_registry);
 	return rc;
 }
 
-static void free_decoder_registry(void)
-{
-	unsigned long index;
-	void *entry;
-
-	xa_for_each(&decoder_registry, index, entry) {
-		xa_erase(&decoder_registry, index);
-		kfree(entry);
-	}
-}
-
 static __exit void cxl_test_exit(void)
 {
 	hmem_test_exit();

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4