Skip to content

Commit 9cf8766

Browse files
jhovoldgregkh
authored andcommitted
USB: dwc3: qcom: fix ACPI platform device leak
Make sure to free the "urs" platform device, which is created for some ACPI platforms, on probe errors and on driver unbind. Compile-tested only. Fixes: c25c210 ("usb: dwc3: qcom: add URS Host support for sdm845 ACPI boot") Cc: Shawn Guo <[email protected]> Signed-off-by: Johan Hovold <[email protected]> Acked-by: Andrew Halaney <[email protected]> Acked-by: Shawn Guo <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 9feefbf commit 9cf8766

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

drivers/usb/dwc3/dwc3-qcom.c

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -763,9 +763,9 @@ static int dwc3_qcom_of_register_core(struct platform_device *pdev)
763763
return ret;
764764
}
765765

766-
static struct platform_device *
767-
dwc3_qcom_create_urs_usb_platdev(struct device *dev)
766+
static struct platform_device *dwc3_qcom_create_urs_usb_platdev(struct device *dev)
768767
{
768+
struct platform_device *urs_usb = NULL;
769769
struct fwnode_handle *fwh;
770770
struct acpi_device *adev;
771771
char name[8];
@@ -785,9 +785,26 @@ dwc3_qcom_create_urs_usb_platdev(struct device *dev)
785785

786786
adev = to_acpi_device_node(fwh);
787787
if (!adev)
788-
return NULL;
788+
goto err_put_handle;
789+
790+
urs_usb = acpi_create_platform_device(adev, NULL);
791+
if (IS_ERR_OR_NULL(urs_usb))
792+
goto err_put_handle;
793+
794+
return urs_usb;
789795

790-
return acpi_create_platform_device(adev, NULL);
796+
err_put_handle:
797+
fwnode_handle_put(fwh);
798+
799+
return urs_usb;
800+
}
801+
802+
static void dwc3_qcom_destroy_urs_usb_platdev(struct platform_device *urs_usb)
803+
{
804+
struct fwnode_handle *fwh = urs_usb->dev.fwnode;
805+
806+
platform_device_unregister(urs_usb);
807+
fwnode_handle_put(fwh);
791808
}
792809

793810
static int dwc3_qcom_probe(struct platform_device *pdev)
@@ -871,13 +888,13 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
871888
qcom->qscratch_base = devm_ioremap_resource(dev, parent_res);
872889
if (IS_ERR(qcom->qscratch_base)) {
873890
ret = PTR_ERR(qcom->qscratch_base);
874-
goto clk_disable;
891+
goto free_urs;
875892
}
876893

877894
ret = dwc3_qcom_setup_irq(pdev);
878895
if (ret) {
879896
dev_err(dev, "failed to setup IRQs, err=%d\n", ret);
880-
goto clk_disable;
897+
goto free_urs;
881898
}
882899

883900
/*
@@ -896,7 +913,7 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
896913

897914
if (ret) {
898915
dev_err(dev, "failed to register DWC3 Core, err=%d\n", ret);
899-
goto clk_disable;
916+
goto free_urs;
900917
}
901918

902919
ret = dwc3_qcom_interconnect_init(qcom);
@@ -935,6 +952,9 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
935952
platform_device_del(qcom->dwc3);
936953
}
937954
platform_device_put(qcom->dwc3);
955+
free_urs:
956+
if (qcom->urs_usb)
957+
dwc3_qcom_destroy_urs_usb_platdev(qcom->urs_usb);
938958
clk_disable:
939959
for (i = qcom->num_clocks - 1; i >= 0; i--) {
940960
clk_disable_unprepare(qcom->clks[i]);
@@ -961,6 +981,9 @@ static void dwc3_qcom_remove(struct platform_device *pdev)
961981
}
962982
platform_device_put(qcom->dwc3);
963983

984+
if (qcom->urs_usb)
985+
dwc3_qcom_destroy_urs_usb_platdev(qcom->urs_usb);
986+
964987
for (i = qcom->num_clocks - 1; i >= 0; i--) {
965988
clk_disable_unprepare(qcom->clks[i]);
966989
clk_put(qcom->clks[i]);

0 commit comments

Comments
 (0)