* Re: [PATCH] usb: renesas_usbhs: Stop an active host on removal
2026-11-29 16:31 [PATCH] usb: renesas_usbhs: Stop an active host on removal Guangshuo Li
@ 2026-11-29 16:48 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-29 16:48 UTC (permalink / raw)
To: Guangshuo Li; +Cc: linux-usb
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] usb: renesas_usbhs: wrong power-off order and leak in
usbhs_remove()
- [Medium] usb: renesas_usbhs: deadlock on setup_ack_done in
usbhs_remove()
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] usb: renesas_usbhs: unchecked pm_runtime_get_sync() in
usbhsc_power_ctrl() [1]
--
commit 25a84d9054639b6536f6c92a19f9076160ea996e
Author: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
usb: renesas_usbhs: Stop an active host on removal
This commit disables hotplug work and stops an active host controller in
usbhs_remove() while skipping host teardown in usbhsh_stop() if the root
hub was never registered.
> diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c
> index 22a5175dcceb9..6e3c6891b6b4b 100644
> --- a/drivers/usb/renesas_usbhs/common.c
> +++ b/drivers/usb/renesas_usbhs/common.c
> @@ -811,7 +811,7 @@ static void usbhs_remove(struct platform_device *pdev)
>
> dev_dbg(&pdev->dev, "usb remove\n");
>
> - flush_delayed_work(&priv->notify_hotplug_work);
> + disable_delayed_work_sync(&priv->notify_hotplug_work);
>
> /*
> * Explicitly free the IRQ to ensure the interrupt handler is
> @@ -821,6 +821,13 @@ static void usbhs_remove(struct platform_device *pdev)
> */
> devm_free_irq(&pdev->dev, priv->irq, priv);
>
> + if (usbhs_mod_is_host(priv) > 0) {
> + usbhs_mod_call(priv, stop, priv);
[Severity: Medium]
Can freeing priv->irq before stopping the host hang usb_remove_hcd() when
a control transfer is in the setup stage?
usbhsh_urb_enqueue() links the control URB onto ep->urb_list and waits
uninterruptibly on hpriv->setup_ack_done in
usbhsh_setup_stage_packet_push() before setting urb->hcpriv. Because
setup_ack_done is only completed from usbhs_interrupt() via
usbhsh_irq_setup_ack() or usbhsh_irq_setup_err(), freeing the IRQ (and
clearing mod->irq_sack and mod->irq_sign in usbhsh_stop()) before
usb_remove_hcd() prevents the setup stage from completing, while
usbhsh_urb_dequeue() cannot cancel the URB because urb->hcpriv is still
NULL.
> + usbhs_mod_change(priv, -1);
> + if (usbhs_get_dparam(priv, runtime_pwctrl))
> + usbhsc_power_ctrl(priv, 0);
> + }
> +
> usbhs_mod_remove(priv);
[Severity: High]
When runtime_pwctrl is enabled, does calling usbhsc_power_ctrl(priv, 0)
before usbhs_mod_remove(priv) access SYSCFG after clocks are disabled,
and leak power and clocks when removing in gadget mode?
If a gadget driver is bound to the UDC while in host mode,
usbhs_mod_remove() -> usb_del_gadget_udc() calls usbhsg_pullup() ->
usbhs_sys_function_pullup(), which reads and writes SYSCFG after
usbhsc_power_ctrl(priv, 0) has already disabled the clocks and suspended
the device. Conversely, if the controller is active in gadget mode when
removed under runtime_pwctrl, usbhs_mod_is_host(priv) is false and the
later !usbhs_get_dparam(priv, runtime_pwctrl) check is also false, so
usbhsc_power_ctrl(priv, 0) is never called.
Should this follow usbhsc_suspend() by stopping any active module and
calling usbhsc_power_ctrl(priv, 0) after usbhs_mod_remove(priv) whenever
a module was active or runtime_pwctrl is disabled?
[Severity: High]
This problem wasn't introduced by this patch, but usbhsc_power_ctrl()
does not check the return value of pm_runtime_get_sync() [1]:
drivers/usb/renesas_usbhs/common.c:usbhsc_power_ctrl() {
if (enable) {
/* enable PM */
pm_runtime_get_sync(dev);
/* enable clks */
if (usbhsc_clk_prepare_enable(priv))
return;
/* enable platform power */
usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable);
/* USB on */
usbhs_sys_clock_ctrl(priv, enable);
}
If runtime resume fails, usbhsc_power_ctrl() still accesses hardware
registers while the device is unpowered and leaves the runtime PM usage
counter elevated.
[1] https://sashiko.dev/#/bug/linux-7b7fec09-1915-42cd-b05f-29a47b39550d
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130-7242f82796-u58-0@mail.sdu.edu.cn?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread