Skip to contentSkip to conversation

cxl/test: Rework cxl_type2_mem_init() to use cxl_mock_platform_device_add()

PATCH Applied Li Ming 2 participants 3 messages Jul 13 – Jul 14 CXL

lore
Share & tools
lore

Li Ming

author reviewer
#0 lore raw

PATCH 1/1 cxl/test: Rework cxl_type2_mem_init() to use cxl_mock_platform_device_add()

cxl_type2_mem_init() is used to set up mock CXL type2 memory device for cxl testing, it introduces a known bug fixed by the following commit:

commit d90f236f8b9e ("cxl/test: Update mock dev array before calling platform_device_add()")

Mock CXL devices require updating the mock device array prior to platform_device_add(), otherwise, the CXL subsystem could fail to recognize the newly added mock device. Switch to cxl_mock_platform_device_add() helper to resolve this ordering issue.

Besides, this patch also includes two minor changes.
1. Preserve the original error code returned by cxl_mock_platform_device_add(), rather than unconditionally overriding it with -ENOMEM.
2. Drop redundant NULL check before platform_device_unregister(), as the function internally handles NULL pointer.

Fixes 6b2e585142e6 ("cxl/test: Add hierarchy enumeration support for type2 device")

---
base-commit: 31adec5c3dc489966e6061cbe427dddb81d2e6b5 cxl/next

---
 tools/testing/cxl/test/cxl.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)
tools/testing/cxl/test/cxl.c +4 -13
index 8ab2ce1262f3..62bd92b3be45 100644
@@ -1947,25 +1947,16 @@ static int cxl_type2_mem_init(void)
 		pdev->dev.parent = &dport->dev;
 		set_dev_node(&pdev->dev, i % 2);
 
-		rc = platform_device_add(pdev);
-		if (rc) {
-			rc = -ENOMEM;
-			platform_device_put(pdev);
+		rc = cxl_mock_platform_device_add(pdev, &cxl_mem[i]);
+		if (rc)
 			goto err_mem;
-		}
-		cxl_mem[i] = pdev;
 	}
 
 	return 0;
 
 err_mem:
-	for (i = NR_CXL_TYPE2_ACCEL - 1; i >= 0; i--) {
-		struct platform_device *pdev = cxl_mem[i];
-
-		if (!pdev)
-			continue;
-		platform_device_unregister(pdev);
-	}
+	for (i = NR_CXL_TYPE2_ACCEL - 1; i >= 0; i--)
+		platform_device_unregister(cxl_mem[i]);
 	return rc;
 }
 
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Li Ming

cxl_type2_mem_init() is used to set up mock CXL type2 memory device for cxl testing, it introduces a known bug fixed by the following commit:

commit d90f236f8b9e ("cxl/test: Update mock dev array before calling platform_device_add()")

Mock CXL devices require updating the mock device array prior to platform_device_add(), otherwise, the CXL subsystem could fail to recognize the newly added mock device. Switch to cxl_mock_platform_device_add() helper to resolve this ordering issue.

Besides, this patch also includes two minor changes.
1. Preserve the original error code returned by cxl_mock_platform_device_add(), rather than unconditionally overriding it with -ENOMEM.
2. Drop redundant NULL check before platform_device_unregister(), as the function internally handles NULL pointer.

Quoted 2 lines
Fixes 6b2e585142e6 ("cxl/test: Add hierarchy enumeration support for type2 device")
Quoted 40 lines

---
base-commit: 31adec5c3dc489966e6061cbe427dddb81d2e6b5 cxl/next

---
 tools/testing/cxl/test/cxl.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)
tools/testing/cxl/test/cxl.c +4 -13
index 8ab2ce1262f3..62bd92b3be45 100644
@@ -1947,25 +1947,16 @@ static int cxl_type2_mem_init(void)
 		pdev->dev.parent = &dport->dev;
 		set_dev_node(&pdev->dev, i % 2);
 
-		rc = platform_device_add(pdev);
-		if (rc) {
-			rc = -ENOMEM;
-			platform_device_put(pdev);
+		rc = cxl_mock_platform_device_add(pdev, &cxl_mem[i]);
+		if (rc)
 			goto err_mem;
-		}
-		cxl_mem[i] = pdev;
 	}
 
 	return 0;
 
 err_mem:
-	for (i = NR_CXL_TYPE2_ACCEL - 1; i >= 0; i--) {
-		struct platform_device *pdev = cxl_mem[i];
-
-		if (!pdev)
-			continue;
-		platform_device_unregister(pdev);
-	}
+	for (i = NR_CXL_TYPE2_ACCEL - 1; i >= 0; i--)
+		platform_device_unregister(cxl_mem[i]);
 	return rc;
 }
 
maintainer Applied
#2 lore raw
In reply to Li Ming
Quoted 17 lines · Li Ming

cxl_type2_mem_init() is used to set up mock CXL type2 memory device for cxl testing, it introduces a known bug fixed by the following commit:

commit d90f236f8b9e ("cxl/test: Update mock dev array before calling platform_device_add()")

Mock CXL devices require updating the mock device array prior to platform_device_add(), otherwise, the CXL subsystem could fail to recognize the newly added mock device. Switch to cxl_mock_platform_device_add() helper to resolve this ordering issue.

Besides, this patch also includes two minor changes.
1. Preserve the original error code returned by cxl_mock_platform_device_add(), rather than unconditionally overriding it with -ENOMEM.
2. Drop redundant NULL check before platform_device_unregister(), as the function internally handles NULL pointer.

Quoted 2 lines
Fixes 6b2e585142e6 ("cxl/test: Add hierarchy enumeration support for type2 device")

Applied to cxl/next
9515af581da976911aea820175afb05be803ae8c

Quoted 40 lines

---
base-commit: 31adec5c3dc489966e6061cbe427dddb81d2e6b5 cxl/next

---
 tools/testing/cxl/test/cxl.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)
tools/testing/cxl/test/cxl.c +4 -13
index 8ab2ce1262f3..62bd92b3be45 100644
@@ -1947,25 +1947,16 @@ static int cxl_type2_mem_init(void)
 		pdev->dev.parent = &dport->dev;
 		set_dev_node(&pdev->dev, i % 2);
 
-		rc = platform_device_add(pdev);
-		if (rc) {
-			rc = -ENOMEM;
-			platform_device_put(pdev);
+		rc = cxl_mock_platform_device_add(pdev, &cxl_mem[i]);
+		if (rc)
 			goto err_mem;
-		}
-		cxl_mem[i] = pdev;
 	}
 
 	return 0;
 
 err_mem:
-	for (i = NR_CXL_TYPE2_ACCEL - 1; i >= 0; i--) {
-		struct platform_device *pdev = cxl_mem[i];
-
-		if (!pdev)
-			continue;
-		platform_device_unregister(pdev);
-	}
+	for (i = NR_CXL_TYPE2_ACCEL - 1; i >= 0; i--)
+		platform_device_unregister(cxl_mem[i]);
 	return rc;
 }