From 7a616cbc2fb5e247ba53188cde9481eed5464c5f Mon Sep 17 00:00:00 2001 From: William Wu Date: Mon, 10 Oct 2022 11:23:40 +0800 Subject: [PATCH] usb: host: ehci-platform: fix companion-device leak for rockchip Make sure do drop the reference taken to the companion device during probe/remove/resume. Fixes: 68850661b51e ("usb: host: ehci-platform: Add device_link between the ehci and companion") Signed-off-by: William Wu Change-Id: I0bbfe77987a1c11bfaa5006d98a56480ff16224f --- drivers/usb/host/ehci-platform.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c index e6f0871375b9..51da2e36f883 100644 --- a/drivers/usb/host/ehci-platform.c +++ b/drivers/usb/host/ehci-platform.c @@ -422,6 +422,7 @@ static int ehci_platform_probe(struct platform_device *dev) if (companion_dev) { link = device_link_add(companion_dev, hcd->self.controller, DL_FLAG_STATELESS); + put_device(companion_dev); if (!link) { dev_err(&dev->dev, "Unable to link %s\n", dev_name(companion_dev)); @@ -473,8 +474,10 @@ static int ehci_platform_remove(struct platform_device *dev) if (of_device_is_compatible(dev->dev.of_node, "rockchip,rk3588-ehci")) { companion_dev = usb_of_get_companion_dev(hcd->self.controller); - if (companion_dev) + if (companion_dev) { device_link_remove(companion_dev, hcd->self.controller); + put_device(companion_dev); + } } usb_remove_hcd(hcd); @@ -535,8 +538,9 @@ static int __maybe_unused ehci_platform_resume(struct device *dev) } companion_dev = usb_of_get_companion_dev(hcd->self.controller); - if (companion_dev && !device_is_dependent(hcd->self.controller, companion_dev)) { - device_pm_wait_for_dev(hcd->self.controller, companion_dev); + if (companion_dev) { + if (!device_is_dependent(hcd->self.controller, companion_dev)) + device_pm_wait_for_dev(hcd->self.controller, companion_dev); put_device(companion_dev); }