Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 85016743 authored by Yang Yingliang's avatar Yang Yingliang Committed by Greg Kroah-Hartman
Browse files

bus: hisi_lpc: fix missing platform_device_put() in hisi_lpc_acpi_probe()



[ Upstream commit 54872fea6a5ac967ec2272aea525d1438ac6735a ]

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: 99c0228d ("HISI LPC: Re-Add ACPI child enumeration support")
Reported-by: default avatarHulk Robot <hulkci@huawei.com>
Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
Acked-by: default avatarJohn Garry <john.garry@huawei.com>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 3d698238
Loading
Loading
Loading
Loading
+6 −4
Original line number Original line Diff line number Diff line
@@ -504,13 +504,13 @@ static int hisi_lpc_acpi_probe(struct device *hostdev)
{
{
	struct acpi_device *adev = ACPI_COMPANION(hostdev);
	struct acpi_device *adev = ACPI_COMPANION(hostdev);
	struct acpi_device *child;
	struct acpi_device *child;
	struct platform_device *pdev;
	int ret;
	int ret;


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


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


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


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


		acpi_device_set_enumerated(child);
		acpi_device_set_enumerated(child);
	}
	}


	return 0;
	return 0;


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