From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Kuen-Han Tsai <khtsai@google.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.6.y 2/3] usb: gadget: Introduce free_usb_request helper
Date: Fri, 17 Oct 2025 20:41:51 -0400 [thread overview]
Message-ID: <20251018004152.92074-2-sashal@kernel.org> (raw)
In-Reply-To: <20251018004152.92074-1-sashal@kernel.org>
From: Kuen-Han Tsai <khtsai@google.com>
[ Upstream commit 201c53c687f2b55a7cc6d9f4000af4797860174b ]
Introduce the free_usb_request() function that frees both the request's
buffer and the request itself.
This function serves as the cleanup callback for DEFINE_FREE() to enable
automatic, scope-based cleanup for usb_request pointers.
Signed-off-by: Kuen-Han Tsai <khtsai@google.com>
Link: https://lore.kernel.org/r/20250916-ready-v1-2-4997bf277548@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://lore.kernel.org/r/20250916-ready-v1-2-4997bf277548@google.com
Stable-dep-of: 47b2116e54b4 ("usb: gadget: f_acm: Refactor bind path to use __free()")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
include/linux/usb/gadget.h | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 7bd39747026e4..aa831e16c3d39 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -15,6 +15,7 @@
#ifndef __LINUX_USB_GADGET_H
#define __LINUX_USB_GADGET_H
+#include <linux/cleanup.h>
#include <linux/configfs.h>
#include <linux/device.h>
#include <linux/errno.h>
@@ -291,6 +292,28 @@ static inline void usb_ep_fifo_flush(struct usb_ep *ep)
/*-------------------------------------------------------------------------*/
+/**
+ * free_usb_request - frees a usb_request object and its buffer
+ * @req: the request being freed
+ *
+ * This helper function frees both the request's buffer and the request object
+ * itself by calling usb_ep_free_request(). Its signature is designed to be used
+ * with DEFINE_FREE() to enable automatic, scope-based cleanup for usb_request
+ * pointers.
+ */
+static inline void free_usb_request(struct usb_request *req)
+{
+ if (!req)
+ return;
+
+ kfree(req->buf);
+ usb_ep_free_request(req->ep, req);
+}
+
+DEFINE_FREE(free_usb_request, struct usb_request *, free_usb_request(_T))
+
+/*-------------------------------------------------------------------------*/
+
struct usb_dcd_config_params {
__u8 bU1devExitLat; /* U1 Device exit Latency */
#define USB_DEFAULT_U1_DEV_EXIT_LAT 0x01 /* Less then 1 microsec */
--
2.51.0
next prev parent reply other threads:[~2025-10-18 0:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-16 9:26 FAILED: patch "[PATCH] usb: gadget: f_acm: Refactor bind path to use __free()" failed to apply to 6.6-stable tree gregkh
2025-10-18 0:41 ` [PATCH 6.6.y 1/3] usb: gadget: Store endpoint pointer in usb_request Sasha Levin
2025-10-18 0:41 ` Sasha Levin [this message]
2025-10-18 0:41 ` [PATCH 6.6.y 3/3] usb: gadget: f_acm: Refactor bind path to use __free() Sasha Levin
-- strict thread matches above, loose matches on Subject: below --
2025-10-16 9:26 FAILED: patch "[PATCH] usb: gadget: f_ecm: Refactor bind path to use __free()" failed to apply to 6.6-stable tree gregkh
2025-10-18 1:02 ` [PATCH 6.6.y 1/3] usb: gadget: Store endpoint pointer in usb_request Sasha Levin
2025-10-18 1:02 ` [PATCH 6.6.y 2/3] usb: gadget: Introduce free_usb_request helper Sasha Levin
2025-10-16 9:26 FAILED: patch "[PATCH] usb: gadget: f_rndis: Refactor bind path to use __free()" failed to apply to 6.6-stable tree gregkh
2025-10-18 2:18 ` [PATCH 6.6.y 1/3] usb: gadget: Store endpoint pointer in usb_request Sasha Levin
2025-10-18 2:18 ` [PATCH 6.6.y 2/3] usb: gadget: Introduce free_usb_request helper Sasha Levin
2025-10-16 9:26 FAILED: patch "[PATCH] usb: gadget: f_ncm: Refactor bind path to use __free()" failed to apply to 6.6-stable tree gregkh
2025-10-18 0:41 ` [PATCH 6.6.y 1/3] usb: gadget: Store endpoint pointer in usb_request Sasha Levin
2025-10-18 0:41 ` [PATCH 6.6.y 2/3] usb: gadget: Introduce free_usb_request helper Sasha Levin
2025-10-16 9:19 FAILED: patch "[PATCH] usb: gadget: f_acm: Refactor bind path to use __free()" failed to apply to 6.6-stable tree gregkh
2025-10-18 0:52 ` [PATCH 6.6.y 1/3] usb: gadget: Store endpoint pointer in usb_request Sasha Levin
2025-10-18 0:52 ` [PATCH 6.6.y 2/3] usb: gadget: Introduce free_usb_request helper Sasha Levin
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=20251018004152.92074-2-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=khtsai@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox