Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] USB: dwc2: shut down the wakeup timer before removing the HCD
@ 2026-11-24  2:40 Yuming Hu
  2026-11-24  6:44 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Yuming Hu @ 2026-11-24  2:40 UTC (permalink / raw)
  To: huyuming; +Cc: stable

The wakeup timer is armed from hardirq context (WKUPINT, 71 ms) and its
callback dwc2_wakeup_detected() ends up calling
usb_hcd_resume_root_hub(hsotg->priv) when the port is suspended.

dwc2_hcd_remove() invokes usb_remove_hcd() and clears hsotg->priv before
it reaches dwc2_hcd_release(), where fd772af9512c ("USB: dwc2: shut down
wakeup timer before freeing HCD state") performs the
timer_shutdown_sync().  If the timer expires inside that window, or its
callback is in flight while hsotg->priv is being cleared,
dwc2_hcd_rem_wakeup() passes the NULL hcd to
usb_hcd_resume_root_hub(), which dereferences it without a NULL check
and oopses in softirq context.

Shut the timer down before usb_remove_hcd(), so that an in-flight
callback always observes a valid hsotg->priv and any later rearm attempt
is ignored by the timer core.  The timer_shutdown_sync() call in
dwc2_hcd_release() is idempotent and keeps covering the probe error
path.

Fixes: 7359d482eb4d ("staging: HCD files for the DWC2 driver")
Cc: stable@vger.kernel.org
Signed-off-by: Yuming Hu <huyuming@kylinos.cn>
---
 drivers/usb/dwc2/hcd.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index 2e1927dfa..0d6549832 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -5377,6 +5377,14 @@ void dwc2_hcd_remove(struct dwc2_hsotg *hsotg)
 	if (!IS_ERR_OR_NULL(hsotg->uphy))
 		otg_set_host(hsotg->uphy->otg, NULL);
 
+	/*
+	 * Shut down the wakeup timer before the HCD is removed: its callback
+	 * reaches usb_hcd_resume_root_hub(hsotg->priv), which must never see
+	 * hsotg->priv == NULL.  The call in dwc2_hcd_release() is idempotent
+	 * and still covers the probe error path.
+	 */
+	timer_shutdown_sync(&hsotg->wkp_timer);
+
 	usb_remove_hcd(hcd);
 	hsotg->priv = NULL;
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] USB: dwc2: shut down the wakeup timer before removing the HCD
@ 2026-11-24  2:45 Yuming Hu
  0 siblings, 0 replies; 3+ messages in thread
From: Yuming Hu @ 2026-11-24  2:45 UTC (permalink / raw)
  To: hminas, gregkh; +Cc: linux-usb, linux-kernel, Thinh.Nguyen, stable, Yuming Hu

The wakeup timer is armed from hardirq context (WKUPINT, 71 ms) and its
callback dwc2_wakeup_detected() ends up calling
usb_hcd_resume_root_hub(hsotg->priv) when the port is suspended.

dwc2_hcd_remove() invokes usb_remove_hcd() and clears hsotg->priv before
it reaches dwc2_hcd_release(), where fd772af9512c ("USB: dwc2: shut down
wakeup timer before freeing HCD state") performs the
timer_shutdown_sync().  If the timer expires inside that window, or its
callback is in flight while hsotg->priv is being cleared,
dwc2_hcd_rem_wakeup() passes the NULL hcd to
usb_hcd_resume_root_hub(), which dereferences it without a NULL check
and oopses in softirq context.

Shut the timer down before usb_remove_hcd(), so that an in-flight
callback always observes a valid hsotg->priv and any later rearm attempt
is ignored by the timer core.  The timer_shutdown_sync() call in
dwc2_hcd_release() is idempotent and keeps covering the probe error
path.

Fixes: 7359d482eb4d ("staging: HCD files for the DWC2 driver")
Cc: stable@vger.kernel.org
Signed-off-by: Yuming Hu <huyuming@kylinos.cn>
---
 drivers/usb/dwc2/hcd.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index 2e1927dfa..0d6549832 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -5377,6 +5377,14 @@ void dwc2_hcd_remove(struct dwc2_hsotg *hsotg)
 	if (!IS_ERR_OR_NULL(hsotg->uphy))
 		otg_set_host(hsotg->uphy->otg, NULL);
 
+	/*
+	 * Shut down the wakeup timer before the HCD is removed: its callback
+	 * reaches usb_hcd_resume_root_hub(hsotg->priv), which must never see
+	 * hsotg->priv == NULL.  The call in dwc2_hcd_release() is idempotent
+	 * and still covers the probe error path.
+	 */
+	timer_shutdown_sync(&hsotg->wkp_timer);
+
 	usb_remove_hcd(hcd);
 	hsotg->priv = NULL;
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] USB: dwc2: shut down the wakeup timer before removing the HCD
  2026-11-24  2:40 [PATCH] USB: dwc2: shut down the wakeup timer before removing the HCD Yuming Hu
@ 2026-11-24  6:44 ` Greg KH
  0 siblings, 0 replies; 3+ messages in thread
From: Greg KH @ 2026-11-24  6:44 UTC (permalink / raw)
  To: Yuming Hu; +Cc: stable

On Tue, Nov 24, 2026 at 10:40:46AM +0800, Yuming Hu wrote:
> The wakeup timer is armed from hardirq context (WKUPINT, 71 ms) and its
> callback dwc2_wakeup_detected() ends up calling
> usb_hcd_resume_root_hub(hsotg->priv) when the port is suspended.
> 
> dwc2_hcd_remove() invokes usb_remove_hcd() and clears hsotg->priv before
> it reaches dwc2_hcd_release(), where fd772af9512c ("USB: dwc2: shut down
> wakeup timer before freeing HCD state") performs the
> timer_shutdown_sync().  If the timer expires inside that window, or its
> callback is in flight while hsotg->priv is being cleared,
> dwc2_hcd_rem_wakeup() passes the NULL hcd to
> usb_hcd_resume_root_hub(), which dereferences it without a NULL check
> and oopses in softirq context.
> 
> Shut the timer down before usb_remove_hcd(), so that an in-flight
> callback always observes a valid hsotg->priv and any later rearm attempt
> is ignored by the timer core.  The timer_shutdown_sync() call in
> dwc2_hcd_release() is idempotent and keeps covering the probe error
> path.
> 
> Fixes: 7359d482eb4d ("staging: HCD files for the DWC2 driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Yuming Hu <huyuming@kylinos.cn>
> ---
>  drivers/usb/dwc2/hcd.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
> index 2e1927dfa..0d6549832 100644
> --- a/drivers/usb/dwc2/hcd.c
> +++ b/drivers/usb/dwc2/hcd.c
> @@ -5377,6 +5377,14 @@ void dwc2_hcd_remove(struct dwc2_hsotg *hsotg)
>  	if (!IS_ERR_OR_NULL(hsotg->uphy))
>  		otg_set_host(hsotg->uphy->otg, NULL);
>  
> +	/*
> +	 * Shut down the wakeup timer before the HCD is removed: its callback
> +	 * reaches usb_hcd_resume_root_hub(hsotg->priv), which must never see
> +	 * hsotg->priv == NULL.  The call in dwc2_hcd_release() is idempotent
> +	 * and still covers the probe error path.
> +	 */
> +	timer_shutdown_sync(&hsotg->wkp_timer);
> +
>  	usb_remove_hcd(hcd);
>  	hsotg->priv = NULL;
>  
> -- 
> 2.25.1
> 
> 

<formletter>

This is not the correct way to submit patches for inclusion in the
stable kernel tree.  Please read:
    https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

</formletter>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-24  6:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24  2:40 [PATCH] USB: dwc2: shut down the wakeup timer before removing the HCD Yuming Hu
2026-11-24  6:44 ` Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2026-11-24  2:45 Yuming Hu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox