diff mbox series

[-next] ACPI: HMAT: Release platform device in case of platform_device_add_data() fails

Message ID 20220914033755.99924-1-linyujun809@huawei.com (mailing list archive)
State Accepted
Commit 6a02124c87f0b61dcaaeb65e7fd406d8afb40fd4
Headers show
Series [-next] ACPI: HMAT: Release platform device in case of platform_device_add_data() fails | expand

Commit Message

Lin Yujun Sept. 14, 2022, 3:37 a.m. UTC
The platform device is not released when platform_device_add_data()
fails. And platform_device_put() perfom one more pointer check than
put_device() to check for errors in the 'pdev' pointer.

Use platform_device_put() to release platform device in
platform_device_add()/platform_device_add_data()/
platform_device_add_resources() error case.

Fixes: c01044cc8191 ("ACPI: HMAT: refactor hmat_register_target_device to hmem_register_device")
Signed-off-by: Lin Yujun <linyujun809@huawei.com>
---
 drivers/dax/hmem/device.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Lin Yujun Sept. 26, 2022, 9:15 a.m. UTC | #1
kindly ping

在 2022/9/14 11:37, Lin Yujun 写道:
> The platform device is not released when platform_device_add_data()
> fails. And platform_device_put() perfom one more pointer check than
> put_device() to check for errors in the 'pdev' pointer.
>
> Use platform_device_put() to release platform device in
> platform_device_add()/platform_device_add_data()/
> platform_device_add_resources() error case.
>
> Fixes: c01044cc8191 ("ACPI: HMAT: refactor hmat_register_target_device to hmem_register_device")
> Signed-off-by: Lin Yujun <linyujun809@huawei.com>
> ---
>   drivers/dax/hmem/device.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/dax/hmem/device.c b/drivers/dax/hmem/device.c
> index cb6401c9e9a4..f87ae005431a 100644
> --- a/drivers/dax/hmem/device.c
> +++ b/drivers/dax/hmem/device.c
> @@ -47,7 +47,7 @@ void hmem_register_device(int target_nid, struct resource *r)
>   	rc = platform_device_add_data(pdev, &info, sizeof(info));
>   	if (rc < 0) {
>   		pr_err("hmem memregion_info allocation failure for %pr\n", &res);
> -		goto out_pdev;
> +		goto out_resource;
>   	}
>   
>   	rc = platform_device_add_resources(pdev, &res, 1);
> @@ -65,7 +65,7 @@ void hmem_register_device(int target_nid, struct resource *r)
>   	return;
>   
>   out_resource:
> -	put_device(&pdev->dev);
> +	platform_device_put(pdev);
>   out_pdev:
>   	memregion_free(id);
>   }
diff mbox series

Patch

diff --git a/drivers/dax/hmem/device.c b/drivers/dax/hmem/device.c
index cb6401c9e9a4..f87ae005431a 100644
--- a/drivers/dax/hmem/device.c
+++ b/drivers/dax/hmem/device.c
@@ -47,7 +47,7 @@  void hmem_register_device(int target_nid, struct resource *r)
 	rc = platform_device_add_data(pdev, &info, sizeof(info));
 	if (rc < 0) {
 		pr_err("hmem memregion_info allocation failure for %pr\n", &res);
-		goto out_pdev;
+		goto out_resource;
 	}
 
 	rc = platform_device_add_resources(pdev, &res, 1);
@@ -65,7 +65,7 @@  void hmem_register_device(int target_nid, struct resource *r)
 	return;
 
 out_resource:
-	put_device(&pdev->dev);
+	platform_device_put(pdev);
 out_pdev:
 	memregion_free(id);
 }