All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: Re: [PATCH] usb: dwc3: gadget: cancel NoStream work before endpoint teardown
Date: Fri, 7 Aug 2026 22:12:13 +0000	[thread overview]
Message-ID: <anZW8H1kQfwXW2Ix@vbox> (raw)
In-Reply-To: <20260807182318.3736662-1-radhey.shyam.pandey@amd.com>

On Fri, Aug 07, 2026, Radhey Shyam Pandey wrote:
> DEPEVT_STREAM_NOSTREAM schedules dwc3_nostream_work() with a 100 ms delay.
> Neither dwc3_gadget_ep_disable() nor dwc3_gadget_free_endpoints() cancel
> this work before freeing struct dwc3_ep, so the handler may run after
> kfree(dep) during DRD/OTG role switch teardown.
> 
> To fix it cancel the delayed work synchronously in both paths before
> disable or free the endpoint.
> 
> Assisted-by: claude-mythos-preview-high
> Fixes: dcfe437492e2 ("usb: dwc3: gadget: Reinitiate stream for all host NoStream behavior")
> Cc: stable@vger.kernel.org
> Signed-off-by: Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>
> ---
>  drivers/usb/dwc3/gadget.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index fa0f16ffafef..ddf1e262e2aa 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -1175,6 +1175,8 @@ static int dwc3_gadget_ep_disable(struct usb_ep *ep)
>  					dep->name))
>  		return 0;
>  
> +	cancel_delayed_work_sync(&dep->nostream_work);
> +

We may not sleep during dwc3_gadget_ep_disable() and we shouldn't call
*_sync() here.

>  	spin_lock_irqsave(&dwc->lock, flags);
>  	ret = __dwc3_gadget_ep_disable(dep);
>  	spin_unlock_irqrestore(&dwc->lock, flags);
> @@ -3508,6 +3510,7 @@ static void dwc3_gadget_free_endpoints(struct dwc3 *dwc)
>  		}
>  
>  		dwc3_debugfs_remove_endpoint_dir(dep);
> +		cancel_delayed_work_sync(&dep->nostream_work);

Just this here is sufficient.

>  		kfree(dep);
>  	}
>  }
> 
> base-commit: 6b8c8af514d739d0335f5579b585e02babe8a727
> -- 
> 2.44.4
> 

Pei Xiao already submitted a patch for this:
https://lore.kernel.org/linux-usb/331d1d5133496d2b4184e05f8848adb06930a138.1785893865.git.xiaopei01@kylinos.cn/T/#u

BR,
Thinh

  reply	other threads:[~2026-08-07 22:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-07 18:23 [PATCH] usb: dwc3: gadget: cancel NoStream work before endpoint teardown Radhey Shyam Pandey
2026-08-07 22:12 ` Thinh Nguyen [this message]
2026-08-08 11:07   ` Pandey, Radhey Shyam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=anZW8H1kQfwXW2Ix@vbox \
    --to=thinh.nguyen@synopsys.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=radhey.shyam.pandey@amd.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.