From: Kuen-Han Tsai <khtsai@google.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
David Brownell <dbrownell@users.sourceforge.net>,
Nam Cao <namcao@linutronix.de>,
Zack Rusin <zack.rusin@broadcom.com>,
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
Prashanth K <prashanth.k@oss.qualcomm.com>,
Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
John Keeping <jkeeping@inmusicbrands.com>,
Roy Luo <royluo@google.com>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
Kuen-Han Tsai <khtsai@google.com>
Subject: [PATCH 1/6] usb: gadget: Store endpoint pointer in usb_request
Date: Tue, 16 Sep 2025 16:21:32 +0800 [thread overview]
Message-ID: <20250916-ready-v1-1-4997bf277548@google.com> (raw)
In-Reply-To: <20250916-ready-v1-0-4997bf277548@google.com>
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>
---
drivers/usb/gadget/udc/core.c | 3 +++
include/linux/usb/gadget.h | 2 ++
2 files changed, 5 insertions(+)
diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
index d709e24c1fd4228c47f877d097faf987975ac392..e3d63b8fa0f4c17c6d59ab9d2f2c529e98f20d45 100644
--- a/drivers/usb/gadget/udc/core.c
+++ b/drivers/usb/gadget/udc/core.c
@@ -194,6 +194,9 @@ struct usb_request *usb_ep_alloc_request(struct usb_ep *ep,
req = ep->ops->alloc_request(ep, gfp_flags);
+ if (req)
+ req->ep = ep;
+
trace_usb_ep_alloc_request(ep, req, req ? 0 : -ENOMEM);
return req;
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 0f28c5512fcb6ccd7a854ae8a66c21aec194c3c7..0f20794760887314d81a070755c8908c6ac4ed90 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -32,6 +32,7 @@ struct usb_ep;
/**
* struct usb_request - describes one i/o request
+ * @ep: The associated endpoint set by usb_ep_alloc_request().
* @buf: Buffer used for data. Always provide this; some controllers
* only use PIO, or don't use DMA for some endpoints.
* @dma: DMA address corresponding to 'buf'. If you don't set this
@@ -98,6 +99,7 @@ struct usb_ep;
*/
struct usb_request {
+ struct usb_ep *ep;
void *buf;
unsigned length;
dma_addr_t dma;
--
2.51.0.384.g4c02a37b29-goog
next prev parent reply other threads:[~2025-09-16 8:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-16 8:21 [PATCH 0/6] usb: gadget: Refactor function drivers to use __free() cleanup Kuen-Han Tsai
2025-09-16 8:21 ` Kuen-Han Tsai [this message]
2025-09-16 8:21 ` [PATCH 2/6] usb: gadget: Introduce free_usb_request helper Kuen-Han Tsai
2025-09-16 8:21 ` [PATCH 3/6] usb: gadget: f_ncm: Refactor bind path to use __free() Kuen-Han Tsai
2025-09-16 8:21 ` [PATCH 4/6] usb: gadget: f_acm: " Kuen-Han Tsai
2025-09-16 8:21 ` [PATCH 5/6] usb: gadget: f_ecm: " Kuen-Han Tsai
2025-09-16 8:21 ` [PATCH 6/6] usb: gadget: f_rndis: " Kuen-Han Tsai
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=20250916-ready-v1-1-4997bf277548@google.com \
--to=khtsai@google.com \
--cc=Thinh.Nguyen@synopsys.com \
--cc=dbrownell@users.sourceforge.net \
--cc=gregkh@linuxfoundation.org \
--cc=jkeeping@inmusicbrands.com \
--cc=krzysztof.kozlowski@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=namcao@linutronix.de \
--cc=prashanth.k@oss.qualcomm.com \
--cc=royluo@google.com \
--cc=zack.rusin@broadcom.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®