From: Huang Wei <huangwei@kylinos.cn>
To: Minas Harutyunyan <hminas@synopsys.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
Huang Wei <huangwei@kylinos.cn>, kakapapa2 <kakapapa2@gmail.com>
Subject: [PATCH] usb: dwc2: debugfs: fix memory leak of hsotg->regset
Date: Fri, 7 Aug 2026 18:04:00 +0800 [thread overview]
Message-ID: <20260807100400.3179625-1-huangwei@kylinos.cn> (raw)
hsotg->regset is allocated in dwc2_debugfs_init() using devm_kzalloc()
but is never explicitly freed. While devres would eventually reclaim
the memory, the regset is logically owned by the debugfs lifetime:
dwc2_debugfs_exit() only removes the debugfs directory and leaves
hsotg->regset dangling.
Switch to kzalloc() and free it explicitly in dwc2_debugfs_exit(),
mirroring the equivalent fix already applied to dwc3 in commit
e6bdf8195b4a ("usb: dwc3: fix memory leak of dwc->regset"). Also set
the pointer to NULL after freeing to avoid a stale dangling pointer.
Reported-by: kakapapa2 <kakapapa2@gmail.com>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=219977
Signed-off-by: Huang Wei <huangwei@kylinos.cn>
---
drivers/usb/dwc2/debugfs.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/dwc2/debugfs.c b/drivers/usb/dwc2/debugfs.c
index 3116ac72747f..2ecbf6523aaa 100644
--- a/drivers/usb/dwc2/debugfs.c
+++ b/drivers/usb/dwc2/debugfs.c
@@ -9,6 +9,7 @@
#include <linux/spinlock.h>
#include <linux/debugfs.h>
#include <linux/seq_file.h>
+#include <linux/slab.h>
#include <linux/uaccess.h>
#include "core.h"
@@ -787,8 +788,7 @@ int dwc2_debugfs_init(struct dwc2_hsotg *hsotg)
/* Add gadget debugfs nodes */
dwc2_hsotg_create_debug(hsotg);
- hsotg->regset = devm_kzalloc(hsotg->dev, sizeof(*hsotg->regset),
- GFP_KERNEL);
+ hsotg->regset = kzalloc_obj(*hsotg->regset, GFP_KERNEL);
if (!hsotg->regset) {
ret = -ENOMEM;
goto err;
@@ -810,4 +810,6 @@ void dwc2_debugfs_exit(struct dwc2_hsotg *hsotg)
{
debugfs_remove_recursive(hsotg->debug_root);
hsotg->debug_root = NULL;
+ kfree(hsotg->regset);
+ hsotg->regset = NULL;
}
--
2.25.1
next reply other threads:[~2026-08-07 10:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 10:04 Huang Wei [this message]
2026-09-02 9:05 ` [PATCH] usb: dwc2: debugfs: fix memory leak of hsotg->regset Huang Wei
2026-09-02 9:25 ` Greg Kroah-Hartman
2026-09-03 6:44 ` Huang Wei
2026-09-05 1:00 ` Thinh Nguyen
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=20260807100400.3179625-1-huangwei@kylinos.cn \
--to=huangwei@kylinos.cn \
--cc=gregkh@linuxfoundation.org \
--cc=hminas@synopsys.com \
--cc=kakapapa2@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@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