Skip to content

Commit

Permalink
bus: hisi_lpc: fix missing platform_device_put() in hisi_lpc_acpi_pro…
Browse files Browse the repository at this point in the history
…be()

[ Upstream commit 54872fe ]

In error case in hisi_lpc_acpi_probe() after calling platform_device_add(),
hisi_lpc_acpi_remove() can't release the failed 'pdev', so it will be leak,
call platform_device_put() to fix this problem.
I'v constructed this error case and tested this patch on D05 board.

Fixes: 99c0228 ("HISI LPC: Re-Add ACPI child enumeration support")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Acked-by: John Garry <john.garry@huawei.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Yang Yingliang authored and gregkh committed Aug 17, 2022
1 parent a0a9813 commit 4a02020
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions drivers/bus/hisi_lpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,13 +503,13 @@ static int hisi_lpc_acpi_probe(struct device *hostdev)
{
struct acpi_device *adev = ACPI_COMPANION(hostdev);
struct acpi_device *child;
struct platform_device *pdev;
int ret;

/* Only consider the children of the host */
list_for_each_entry(child, &adev->children, node) {
const char *hid = acpi_device_hid(child);
const struct hisi_lpc_acpi_cell *cell;
struct platform_device *pdev;
const struct resource *res;
bool found = false;
int num_res;
Expand Down Expand Up @@ -571,22 +571,24 @@ static int hisi_lpc_acpi_probe(struct device *hostdev)

ret = platform_device_add_resources(pdev, res, num_res);
if (ret)
goto fail;
goto fail_put_device;

ret = platform_device_add_data(pdev, cell->pdata,
cell->pdata_size);
if (ret)
goto fail;
goto fail_put_device;

ret = platform_device_add(pdev);
if (ret)
goto fail;
goto fail_put_device;

acpi_device_set_enumerated(child);
}

return 0;

fail_put_device:
platform_device_put(pdev);
fail:
hisi_lpc_acpi_remove(hostdev);
return ret;
Expand Down

0 comments on commit 4a02020

Please sign in to comment.