Skip to content

Commit

Permalink
ACPI: HMAT: release platform device in case of platform_device_add_da…
Browse files Browse the repository at this point in the history
…ta() failure

The platform device is not released when platform_device_add_data() fails.
And platform_device_put() performs 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.

Link: https://lkml.kernel.org/r/20220914033755.99924-1-linyujun809@huawei.com
Fixes: c01044c ("ACPI: HMAT: refactor hmat_register_target_device to hmem_register_device")
Signed-off-by: Lin Yujun <linyujun809@huawei.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Joao Martins <joao.m.martins@oracle.com>
Cc: Vishal Verma <vishal.l.verma@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
  • Loading branch information
Lin Yujun authored and Andrew Morton committed Sep 27, 2022
1 parent 17f02f2 commit 546f08c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/dax/hmem/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down

0 comments on commit 546f08c

Please sign in to comment.