From: Peter Korsgaard <peter@korsgaard.com>
To: linux-usb@vger.kernel.org, julian@jusst.de,
gregkh@linuxfoundation.org,
Pavel Hofman <pavel.hofman@ivitera.com>
Cc: Peter Korsgaard <peter@korsgaard.com>, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] usb: gadget: f_uac2: fix memory leak in UAC2_RATE_ATTRIBUTE store
Date: Tue, 9 Jun 2026 11:19:55 +0200 [thread overview]
Message-ID: <20260609091957.2716984-1-peter@korsgaard.com> (raw)
strsep() clobbers the passed pointer, so we need a separate variable to be
able to correctly kfree() the memory at the end.
Detected by kmemleak:
unreferenced object 0xffffff80038f9098 (size 8):
comm "audio.hook", pid 323, jiffies 4294896085
hex dump (first 8 bytes):
34 38 30 30 30 0a 00 cc 48000...
backtrace (crc 503efa75):
kmemleak_alloc+0x30/0x40
__kmalloc_node_track_caller_noprof+0x240/0x3d0
kstrdup+0x44/0x90
f_uac2_opts_c_srate_store+0x13c/0x200
configfs_write_iter+0x238/0x360
vfs_write+0x4a4/0xd00
ksys_write+0xf4/0x1e0
__arm64_sys_write+0x68/0xa0
invoke_syscall.constprop.0+0xa4/0x260
do_el0_svc+0xc0/0x1c0
el0_svc+0x20/0x60
el0t_64_sync_handler+0x118/0x130
el0t_64_sync+0x14c/0x150
Fixes: a7339e4f5788 ("usb: gadget: f_uac2: Support multiple sampling rates")
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
---
drivers/usb/gadget/function/f_uac2.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c
index 897787d0803c1..0c2a8afccbb69 100644
--- a/drivers/usb/gadget/function/f_uac2.c
+++ b/drivers/usb/gadget/function/f_uac2.c
@@ -2012,7 +2012,7 @@ static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \
const char *page, size_t len) \
{ \
struct f_uac2_opts *opts = to_f_uac2_opts(item); \
- char *split_page = NULL; \
+ char *p, *split_page = NULL; \
int ret = -EINVAL; \
char *token; \
u32 num; \
@@ -2026,8 +2026,8 @@ static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \
\
i = 0; \
memset(opts->name##s, 0x00, sizeof(opts->name##s)); \
- split_page = kstrdup(page, GFP_KERNEL); \
- while ((token = strsep(&split_page, ",")) != NULL) { \
+ split_page = p = kstrdup(page, GFP_KERNEL); \
+ while ((token = strsep(&p, ",")) != NULL) { \
ret = kstrtou32(token, 0, &num); \
if (ret) \
goto end; \
--
2.47.3
next reply other threads:[~2026-06-09 9:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-09 9:19 Peter Korsgaard [this message]
2026-06-09 9:19 ` [PATCH 2/2] usb: gadget: f_uac1: fix memory leak in UAC1_RATE_ATTRIBUTE store Peter Korsgaard
2026-06-14 9:39 ` [PATCH 1/2] usb: gadget: f_uac2: fix memory leak in UAC2_RATE_ATTRIBUTE store Peter Korsgaard
2026-06-15 10:52 ` Ming Qing
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=20260609091957.2716984-1-peter@korsgaard.com \
--to=peter@korsgaard.com \
--cc=gregkh@linuxfoundation.org \
--cc=julian@jusst.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=pavel.hofman@ivitera.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