Skip to content

Commit bfb1d99

Browse files
Kuen-Han Tsaigregkh
authored andcommitted
usb: gadget: Store endpoint pointer in usb_request
Gadget function drivers often have goto-based error handling in their bind paths, which can be bug-prone. Refactoring these paths to use __free() scope-based cleanup is desirable, but currently blocked. The blocker is that usb_ep_free_request(ep, req) requires two parameters, while the __free() mechanism can only pass a pointer to the request itself. Store an endpoint pointer in the struct usb_request. The pointer is populated centrally in usb_ep_alloc_request() on every successful allocation, making the request object self-contained. Signed-off-by: Kuen-Han Tsai <khtsai@google.com> Link: https://lore.kernel.org/r/20250916-ready-v1-1-4997bf277548@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Link: https://lore.kernel.org/r/20250916-ready-v1-1-4997bf277548@google.com
1 parent 1b237f1 commit bfb1d99

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

drivers/usb/gadget/udc/core.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ struct usb_request *usb_ep_alloc_request(struct usb_ep *ep,
194194

195195
req = ep->ops->alloc_request(ep, gfp_flags);
196196

197+
if (req)
198+
req->ep = ep;
199+
197200
trace_usb_ep_alloc_request(ep, req, req ? 0 : -ENOMEM);
198201

199202
return req;

include/linux/usb/gadget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct usb_ep;
3232

3333
/**
3434
* struct usb_request - describes one i/o request
35+
* @ep: The associated endpoint set by usb_ep_alloc_request().
3536
* @buf: Buffer used for data. Always provide this; some controllers
3637
* only use PIO, or don't use DMA for some endpoints.
3738
* @dma: DMA address corresponding to 'buf'. If you don't set this
@@ -98,6 +99,7 @@ struct usb_ep;
9899
*/
99100

100101
struct usb_request {
102+
struct usb_ep *ep;
101103
void *buf;
102104
unsigned length;
103105
dma_addr_t dma;

0 commit comments

Comments
 (0)