[PATCH -next] tools/testing/cxl: Fix error return code in cxl_test_init()

From: Yang Yingliang
Date: Wed Aug 25 2021 - 23:43:04 EST


Return a negative error code when platform_device_alloc() or
alloc_memdev() fail.

Reported-by: Hulk Robot <hulkci@xxxxxxxxxx>
Signed-off-by: Yang Yingliang <yangyingliang@xxxxxxxxxx>
---
tools/testing/cxl/test/cxl.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/tools/testing/cxl/test/cxl.c b/tools/testing/cxl/test/cxl.c
index 314b09d40333..92735e2e7146 100644
--- a/tools/testing/cxl/test/cxl.c
+++ b/tools/testing/cxl/test/cxl.c
@@ -472,8 +472,10 @@ static __init int cxl_test_init(void)
struct platform_device *pdev;

pdev = platform_device_alloc("cxl_host_bridge", i);
- if (!pdev)
+ if (!pdev) {
+ rc = -ENOMEM;
goto err_bridge;
+ }

mock_companion(adev, &pdev->dev);
rc = platform_device_add(pdev);
@@ -490,8 +492,10 @@ static __init int cxl_test_init(void)
struct platform_device *pdev;

pdev = platform_device_alloc("cxl_root_port", i);
- if (!pdev)
+ if (!pdev) {
+ rc = -ENOMEM;
goto err_port;
+ }
pdev->dev.parent = &bridge->dev;

rc = platform_device_add(pdev);
@@ -508,8 +512,10 @@ static __init int cxl_test_init(void)
struct platform_device *pdev;

pdev = alloc_memdev(i);
- if (!pdev)
+ if (!pdev) {
+ rc = -ENOMEM;
goto err_mem;
+ }
pdev->dev.parent = &port->dev;

rc = platform_device_add(pdev);
@@ -521,8 +527,10 @@ static __init int cxl_test_init(void)
}

cxl_acpi = platform_device_alloc("cxl_acpi", 0);
- if (!cxl_acpi)
+ if (!cxl_acpi) {
+ rc = -ENOMEM;
goto err_mem;
+ }

mock_companion(&acpi0017_mock, &cxl_acpi->dev);
acpi0017_mock.dev.bus = &platform_bus_type;
--
2.25.1