Message ID | 20221028084919.21654-1-gengcixi@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp710943wru; Fri, 28 Oct 2022 02:06:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5xiCKm+o5iZFghMzA+GVcDGEEeh88bzIQI3wIYPy5p30iPNVeqYtEIKigdMF1FIWKUXnj7 X-Received: by 2002:a17:906:7621:b0:750:c4a3:8fcd with SMTP id c1-20020a170906762100b00750c4a38fcdmr48021354ejn.180.1666947959876; Fri, 28 Oct 2022 02:05:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666947959; cv=none; d=google.com; s=arc-20160816; b=B7txWGcZKtmp1Tg9XpvXbKbGhlCtFNso1qM1FqPmH1qOO7cwc1mEIM4sm0177WCMCu 7P8ZxptACvQ/RqMWcH7Wxx9KF2axUMMZQzJT/znwmD3mLmfShYsgVHgZvhElf71Z5brp uAXhwmn1McW6LMOY09ljgHqrH2TkoKqtU0mZyZXNsjYttjqkECGomV708zx1q6TWZzBR hJiQsDM/602YNqdG5TLexVQ+whgFe0pirW+zEnr9KIQEDqRXXc2vyThbSfWT/puayPoH 3QbCVeaDnyZkraAIzjt632Zvpg6FU+h14XkvftYbx5BPnqKxBqtJz00bhxyK1fyOAALM 3crA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=g+W6HdSggedVNAmKo44TRVUJtR5I0fDVO41SU1t933A=; b=ORSw9X651ZkOsDZMyquaKjTvmJ6Uc7k6L27HC7GiLdLwdJv32ZNqTSN+iX7+9DcdCW 6UzJOfI594XV8YSBI0vQ9vRvejA2GmDUj/5D9wB5ox8lktjY9Xfd60W51Gv/aJEQSebo YtHylss0YgwNEAeDLszeGGc4LZEzxfzfzHR8ZIdXiyUVInMErD3QcgUcaow+6igBS4DM g0REWp+W+KWtkjyBk2sQ059WjN9xBI9VGBVlyCTHvI8wMAx14H2F7BIZhbKWFTnCnxIb AHnpCqc6V1fLbgyb6fzMccGvpLW3n6Vj4uUCYqAO1qkD5QWKu3tYwMWUD0CtUjPXNf6B PqIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZlFVufaS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mp3-20020a1709071b0300b0073083c63edcsi3921145ejc.306.2022.10.28.02.05.35; Fri, 28 Oct 2022 02:05:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZlFVufaS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230024AbiJ1Itb (ORCPT <rfc822;chrisfriedt@gmail.com> + 99 others); Fri, 28 Oct 2022 04:49:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229531AbiJ1Ita (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 28 Oct 2022 04:49:30 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A18E51BB56F; Fri, 28 Oct 2022 01:49:24 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id t10-20020a17090a4e4a00b0020af4bcae10so3916999pjl.3; Fri, 28 Oct 2022 01:49:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=g+W6HdSggedVNAmKo44TRVUJtR5I0fDVO41SU1t933A=; b=ZlFVufaSjqP/ASYTdwQb9tl7oyw9vZS35rJU/RjqitL7RCi8kuSG7Jsrqd7MSTvNcX h3ODQ0RIBU5a3GQmXSBE83vhrGXPf0qDoO8w8r5a4vICkq+wuJJfzluwzlwMCDaPR8aQ BORQ5MPT+9zEns0XulJEZByS0a/2phk6veX5vW5zl7062SMAcvbR4bngRMKvVpl5YK4y JU7ZjK2/u9SxXAov5rUdsZdKo56RQQbO6hKFbwJ3kTr6PriLeFlvBgvcZzq+N2+kU1zM I/Fs6vN9ApNugZylu8UBaKsPFYe0uRMZ9SdnpcbLB3fiFUxWcZzsh/Nqak85Sil3Qpj8 flOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=g+W6HdSggedVNAmKo44TRVUJtR5I0fDVO41SU1t933A=; b=phj7gkc/ZQ8Zx4z7vcrGamTU1DaqYLMObyZjmL+v9j0iArEU/a0Ga1D0OYXL39XyCu z/9NBd7WSyByWAueD2xJHdb4DEBv6CdkRCT3BkIebR43RZHsQm26JJZh2NdEtlYskJ6N Al/+UZNcIxO/nHEZQU/FoFTquOjNM7fo/0+llkJkGBg3QggaqoSCfA+CBNLFPckIfmwR Ts/TuoJMnzl7av3aLpMyCUbQEaw1PgbUnd65E2gpY1M0UtFEjBQPuk8yRAvieVmBmTZj 6psDY71WzKbnz6R31N8OrNVWlz+UaWdQiaLMp/inVRPkH3kqOdHc1dT69uzUjeNHPLGT INXw== X-Gm-Message-State: ACrzQf0F2H3mngJCxJckc3G+Juz7wqw4o01ADcAK1Dg40fmoC/T1lxIH XN70tjgKv9kgQosrYhgmB1I= X-Received: by 2002:a17:90b:3646:b0:213:812c:7c62 with SMTP id nh6-20020a17090b364600b00213812c7c62mr5646050pjb.194.1666946964032; Fri, 28 Oct 2022 01:49:24 -0700 (PDT) Received: from localhost ([60.27.159.185]) by smtp.gmail.com with ESMTPSA id y6-20020a626406000000b0056bc1a41209sm2401584pfb.33.2022.10.28.01.49.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Oct 2022 01:49:23 -0700 (PDT) From: Cixi Geng <gengcixi@gmail.com> To: Thinh.Nguyen@synopsys.com, gregkh@linuxfoundation.org, bruce.chen@unisoc.com Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] usb: dwc3: Fix dentry leak in dwc3_gadget_free_endpoints Date: Fri, 28 Oct 2022 16:49:19 +0800 Message-Id: <20221028084919.21654-1-gengcixi@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747921624261197409?= X-GMAIL-MSGID: =?utf-8?q?1747921624261197409?= |
Series |
usb: dwc3: Fix dentry leak in dwc3_gadget_free_endpoints
|
|
Commit Message
Cixi Geng
Oct. 28, 2022, 8:49 a.m. UTC
From: Bruce Chen <bruce.chen@unisoc.com> When using debugfs_remove_recursive leaks a dentry with a hotplug stress test, the phone runs out of memory. Thus fix the issue by using the newly created debugfs_lookup_and_remove(). Signed-off-by: Bruce Chen <bruce.chen@unisoc.com> Signed-off-by: Cixi Geng <cixi.geng1@unisoc.com> --- drivers/usb/dwc3/core.h | 1 + drivers/usb/dwc3/debugfs.c | 3 ++- drivers/usb/dwc3/gadget.c | 4 +--- 3 files changed, 4 insertions(+), 4 deletions(-)
Comments
On Fri, Oct 28, 2022 at 04:49:19PM +0800, Cixi Geng wrote: > From: Bruce Chen <bruce.chen@unisoc.com> > > When using debugfs_remove_recursive leaks a dentry with > a hotplug stress test, the phone runs out of memory. > > Thus fix the issue by using the newly created debugfs_lookup_and_remove(). > > Signed-off-by: Bruce Chen <bruce.chen@unisoc.com> > Signed-off-by: Cixi Geng <cixi.geng1@unisoc.com> > --- > drivers/usb/dwc3/core.h | 1 + > drivers/usb/dwc3/debugfs.c | 3 ++- > drivers/usb/dwc3/gadget.c | 4 +--- > 3 files changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h > index 8f9959ba9fd4..ba3ecaa7f06c 100644 > --- a/drivers/usb/dwc3/core.h > +++ b/drivers/usb/dwc3/core.h > @@ -1261,6 +1261,7 @@ struct dwc3 { > u8 num_eps; > > struct dwc3_hwparams hwparams; > + struct dentry *root; You forgot to document this new variable. And name it a bit better? > struct debugfs_regset32 *regset; > > u32 dbg_lsp_select; > diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c > index f2b7675c7f62..b9af4a81f51d 100644 > --- a/drivers/usb/dwc3/debugfs.c > +++ b/drivers/usb/dwc3/debugfs.c > @@ -911,6 +911,7 @@ void dwc3_debugfs_init(struct dwc3 *dwc) > dwc->regset->base = dwc->regs - DWC3_GLOBALS_REGS_START; > > root = debugfs_create_dir(dev_name(dwc->dev), usb_debug_root); > + dwc->root = root; > debugfs_create_regset32("regdump", 0444, root, dwc->regset); > debugfs_create_file("lsp_dump", 0644, root, dwc, &dwc3_lsp_fops); > > @@ -929,6 +930,6 @@ void dwc3_debugfs_init(struct dwc3 *dwc) > > void dwc3_debugfs_exit(struct dwc3 *dwc) > { > - debugfs_remove(debugfs_lookup(dev_name(dwc->dev), usb_debug_root)); > + debugfs_remove(dwc->root); > kfree(dwc->regset); > } > diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c > index 079cd333632e..6d6c188fcbea 100644 > --- a/drivers/usb/dwc3/gadget.c > +++ b/drivers/usb/dwc3/gadget.c > @@ -3172,9 +3172,7 @@ static void dwc3_gadget_free_endpoints(struct dwc3 *dwc) > list_del(&dep->endpoint.ep_list); > } > > - debugfs_remove_recursive(debugfs_lookup(dep->name, > - debugfs_lookup(dev_name(dep->dwc->dev), > - usb_debug_root))); > + debugfs_lookup_and_remove(dep->name, dwc->root); > kfree(dep); > } > } > -- > 2.34.1 > I don't think this is the full fix. Below is a patch that I've had in a tree that I need to push out (along with the other 33 debugfs_lookup patches) that should resolve this for this driver in a more complete way. Can you try this version instead? thanks, greg k-h --------------------- From 49b893792579af1bea46c5004759cb35475c4fca Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Date: Fri, 2 Sep 2022 16:41:39 +0200 Subject: [PATCH 06/34] USB: dwc3: debugfs_lookup() fix Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> --- drivers/usb/dwc3/core.h | 2 ++ drivers/usb/dwc3/debug.h | 3 +++ drivers/usb/dwc3/debugfs.c | 19 ++++++++----------- drivers/usb/dwc3/gadget.c | 4 +--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 8f9959ba9fd4..582ebd9cf9c2 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -1117,6 +1117,7 @@ struct dwc3_scratchpad_array { * address. * @num_ep_resized: carries the current number endpoints which have had its tx * fifo resized. + * @debug_root: root debugfs directory for this device to put its files in. */ struct dwc3 { struct work_struct drd_work; @@ -1332,6 +1333,7 @@ struct dwc3 { int max_cfg_eps; int last_fifo_depth; int num_ep_resized; + struct dentry *debug_root; }; #define INCRX_BURST_MODE 0 diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h index 48b44b88dc25..8bb2c9e3b9ac 100644 --- a/drivers/usb/dwc3/debug.h +++ b/drivers/usb/dwc3/debug.h @@ -414,11 +414,14 @@ static inline const char *dwc3_gadget_generic_cmd_status_string(int status) #ifdef CONFIG_DEBUG_FS extern void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep); +extern void dwc3_debugfs_remove_endpoint_dir(struct dwc3_ep *dep); extern void dwc3_debugfs_init(struct dwc3 *d); extern void dwc3_debugfs_exit(struct dwc3 *d); #else static inline void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep) { } +static inline void dwc3_debugfs_remove_endpoint_dir(struct dwc3_ep *dep) +{ } static inline void dwc3_debugfs_init(struct dwc3 *d) { } static inline void dwc3_debugfs_exit(struct dwc3 *d) diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c index f2b7675c7f62..850df0e6bcab 100644 --- a/drivers/usb/dwc3/debugfs.c +++ b/drivers/usb/dwc3/debugfs.c @@ -873,27 +873,23 @@ static const struct dwc3_ep_file_map dwc3_ep_file_map[] = { { "GDBGEPINFO", &dwc3_ep_info_register_fops, }, }; -static void dwc3_debugfs_create_endpoint_files(struct dwc3_ep *dep, - struct dentry *parent) +void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep) { + struct dentry *dir; int i; + dir = debugfs_create_dir(dep->name, dep->dwc->debug_root); for (i = 0; i < ARRAY_SIZE(dwc3_ep_file_map); i++) { const struct file_operations *fops = dwc3_ep_file_map[i].fops; const char *name = dwc3_ep_file_map[i].name; - debugfs_create_file(name, 0444, parent, dep, fops); + debugfs_create_file(name, 0444, dir, dep, fops); } } -void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep) +void dwc3_debugfs_remove_endpoint_dir(struct dwc3_ep *dep) { - struct dentry *dir; - struct dentry *root; - - root = debugfs_lookup(dev_name(dep->dwc->dev), usb_debug_root); - dir = debugfs_create_dir(dep->name, root); - dwc3_debugfs_create_endpoint_files(dep, dir); + debugfs_lookup_and_remove(dep->name, dep->dwc->debug_root); } void dwc3_debugfs_init(struct dwc3 *dwc) @@ -911,6 +907,7 @@ void dwc3_debugfs_init(struct dwc3 *dwc) dwc->regset->base = dwc->regs - DWC3_GLOBALS_REGS_START; root = debugfs_create_dir(dev_name(dwc->dev), usb_debug_root); + dwc->debug_root = root; debugfs_create_regset32("regdump", 0444, root, dwc->regset); debugfs_create_file("lsp_dump", 0644, root, dwc, &dwc3_lsp_fops); @@ -929,6 +926,6 @@ void dwc3_debugfs_init(struct dwc3 *dwc) void dwc3_debugfs_exit(struct dwc3 *dwc) { - debugfs_remove(debugfs_lookup(dev_name(dwc->dev), usb_debug_root)); + debugfs_lookup_and_remove(dev_name(dwc->dev), usb_debug_root); kfree(dwc->regset); } diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 079cd333632e..404bb7ee61a8 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -3172,9 +3172,7 @@ static void dwc3_gadget_free_endpoints(struct dwc3 *dwc) list_del(&dep->endpoint.ep_list); } - debugfs_remove_recursive(debugfs_lookup(dep->name, - debugfs_lookup(dev_name(dep->dwc->dev), - usb_debug_root))); + dwc3_debugfs_remove_endpoint_dir(dep); kfree(dep); } }
Greg KH <gregkh@linuxfoundation.org> 于2022年10月28日周五 17:13写道: > > On Fri, Oct 28, 2022 at 04:49:19PM +0800, Cixi Geng wrote: > > From: Bruce Chen <bruce.chen@unisoc.com> > > > > When using debugfs_remove_recursive leaks a dentry with > > a hotplug stress test, the phone runs out of memory. > > > > Thus fix the issue by using the newly created debugfs_lookup_and_remove(). > > > > Signed-off-by: Bruce Chen <bruce.chen@unisoc.com> > > Signed-off-by: Cixi Geng <cixi.geng1@unisoc.com> > > --- > > drivers/usb/dwc3/core.h | 1 + > > drivers/usb/dwc3/debugfs.c | 3 ++- > > drivers/usb/dwc3/gadget.c | 4 +--- > > 3 files changed, 4 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h > > index 8f9959ba9fd4..ba3ecaa7f06c 100644 > > --- a/drivers/usb/dwc3/core.h > > +++ b/drivers/usb/dwc3/core.h > > @@ -1261,6 +1261,7 @@ struct dwc3 { > > u8 num_eps; > > > > struct dwc3_hwparams hwparams; > > + struct dentry *root; > > You forgot to document this new variable. > > And name it a bit better? > > > struct debugfs_regset32 *regset; > > > > u32 dbg_lsp_select; > > diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c > > index f2b7675c7f62..b9af4a81f51d 100644 > > --- a/drivers/usb/dwc3/debugfs.c > > +++ b/drivers/usb/dwc3/debugfs.c > > @@ -911,6 +911,7 @@ void dwc3_debugfs_init(struct dwc3 *dwc) > > dwc->regset->base = dwc->regs - DWC3_GLOBALS_REGS_START; > > > > root = debugfs_create_dir(dev_name(dwc->dev), usb_debug_root); > > + dwc->root = root; > > debugfs_create_regset32("regdump", 0444, root, dwc->regset); > > debugfs_create_file("lsp_dump", 0644, root, dwc, &dwc3_lsp_fops); > > > > @@ -929,6 +930,6 @@ void dwc3_debugfs_init(struct dwc3 *dwc) > > > > void dwc3_debugfs_exit(struct dwc3 *dwc) > > { > > - debugfs_remove(debugfs_lookup(dev_name(dwc->dev), usb_debug_root)); > > + debugfs_remove(dwc->root); > > kfree(dwc->regset); > > } > > diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c > > index 079cd333632e..6d6c188fcbea 100644 > > --- a/drivers/usb/dwc3/gadget.c > > +++ b/drivers/usb/dwc3/gadget.c > > @@ -3172,9 +3172,7 @@ static void dwc3_gadget_free_endpoints(struct dwc3 *dwc) > > list_del(&dep->endpoint.ep_list); > > } > > > > - debugfs_remove_recursive(debugfs_lookup(dep->name, > > - debugfs_lookup(dev_name(dep->dwc->dev), > > - usb_debug_root))); > > + debugfs_lookup_and_remove(dep->name, dwc->root); > > kfree(dep); > > } > > } > > -- > > 2.34.1 > > > > I don't think this is the full fix. > > Below is a patch that I've had in a tree that I need to push out (along > with the other 33 debugfs_lookup patches) that should resolve this for > this driver in a more complete way. > > Can you try this version instead? We test OK by using the following patch. thanks. Best Regards Cixi Geng > > thanks, > > greg k-h > > --------------------- > > > From 49b893792579af1bea46c5004759cb35475c4fca Mon Sep 17 00:00:00 2001 > From: Greg Kroah-Hartman <gregkh@linuxfoundation.org> > Date: Fri, 2 Sep 2022 16:41:39 +0200 > Subject: [PATCH 06/34] USB: dwc3: debugfs_lookup() fix > > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> > --- > drivers/usb/dwc3/core.h | 2 ++ > drivers/usb/dwc3/debug.h | 3 +++ > drivers/usb/dwc3/debugfs.c | 19 ++++++++----------- > drivers/usb/dwc3/gadget.c | 4 +--- > 4 files changed, 14 insertions(+), 14 deletions(-) > > diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h > index 8f9959ba9fd4..582ebd9cf9c2 100644 > --- a/drivers/usb/dwc3/core.h > +++ b/drivers/usb/dwc3/core.h > @@ -1117,6 +1117,7 @@ struct dwc3_scratchpad_array { > * address. > * @num_ep_resized: carries the current number endpoints which have had its tx > * fifo resized. > + * @debug_root: root debugfs directory for this device to put its files in. > */ > struct dwc3 { > struct work_struct drd_work; > @@ -1332,6 +1333,7 @@ struct dwc3 { > int max_cfg_eps; > int last_fifo_depth; > int num_ep_resized; > + struct dentry *debug_root; > }; > > #define INCRX_BURST_MODE 0 > diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h > index 48b44b88dc25..8bb2c9e3b9ac 100644 > --- a/drivers/usb/dwc3/debug.h > +++ b/drivers/usb/dwc3/debug.h > @@ -414,11 +414,14 @@ static inline const char *dwc3_gadget_generic_cmd_status_string(int status) > > #ifdef CONFIG_DEBUG_FS > extern void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep); > +extern void dwc3_debugfs_remove_endpoint_dir(struct dwc3_ep *dep); > extern void dwc3_debugfs_init(struct dwc3 *d); > extern void dwc3_debugfs_exit(struct dwc3 *d); > #else > static inline void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep) > { } > +static inline void dwc3_debugfs_remove_endpoint_dir(struct dwc3_ep *dep) > +{ } > static inline void dwc3_debugfs_init(struct dwc3 *d) > { } > static inline void dwc3_debugfs_exit(struct dwc3 *d) > diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c > index f2b7675c7f62..850df0e6bcab 100644 > --- a/drivers/usb/dwc3/debugfs.c > +++ b/drivers/usb/dwc3/debugfs.c > @@ -873,27 +873,23 @@ static const struct dwc3_ep_file_map dwc3_ep_file_map[] = { > { "GDBGEPINFO", &dwc3_ep_info_register_fops, }, > }; > > -static void dwc3_debugfs_create_endpoint_files(struct dwc3_ep *dep, > - struct dentry *parent) > +void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep) > { > + struct dentry *dir; > int i; > > + dir = debugfs_create_dir(dep->name, dep->dwc->debug_root); > for (i = 0; i < ARRAY_SIZE(dwc3_ep_file_map); i++) { > const struct file_operations *fops = dwc3_ep_file_map[i].fops; > const char *name = dwc3_ep_file_map[i].name; > > - debugfs_create_file(name, 0444, parent, dep, fops); > + debugfs_create_file(name, 0444, dir, dep, fops); > } > } > > -void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep) > +void dwc3_debugfs_remove_endpoint_dir(struct dwc3_ep *dep) > { > - struct dentry *dir; > - struct dentry *root; > - > - root = debugfs_lookup(dev_name(dep->dwc->dev), usb_debug_root); > - dir = debugfs_create_dir(dep->name, root); > - dwc3_debugfs_create_endpoint_files(dep, dir); > + debugfs_lookup_and_remove(dep->name, dep->dwc->debug_root); > } > > void dwc3_debugfs_init(struct dwc3 *dwc) > @@ -911,6 +907,7 @@ void dwc3_debugfs_init(struct dwc3 *dwc) > dwc->regset->base = dwc->regs - DWC3_GLOBALS_REGS_START; > > root = debugfs_create_dir(dev_name(dwc->dev), usb_debug_root); > + dwc->debug_root = root; > debugfs_create_regset32("regdump", 0444, root, dwc->regset); > debugfs_create_file("lsp_dump", 0644, root, dwc, &dwc3_lsp_fops); > > @@ -929,6 +926,6 @@ void dwc3_debugfs_init(struct dwc3 *dwc) > > void dwc3_debugfs_exit(struct dwc3 *dwc) > { > - debugfs_remove(debugfs_lookup(dev_name(dwc->dev), usb_debug_root)); > + debugfs_lookup_and_remove(dev_name(dwc->dev), usb_debug_root); > kfree(dwc->regset); > } > diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c > index 079cd333632e..404bb7ee61a8 100644 > --- a/drivers/usb/dwc3/gadget.c > +++ b/drivers/usb/dwc3/gadget.c > @@ -3172,9 +3172,7 @@ static void dwc3_gadget_free_endpoints(struct dwc3 *dwc) > list_del(&dep->endpoint.ep_list); > } > > - debugfs_remove_recursive(debugfs_lookup(dep->name, > - debugfs_lookup(dev_name(dep->dwc->dev), > - usb_debug_root))); > + dwc3_debugfs_remove_endpoint_dir(dep); > kfree(dep); > } > } > -- > 2.38.1 >
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 8f9959ba9fd4..ba3ecaa7f06c 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -1261,6 +1261,7 @@ struct dwc3 { u8 num_eps; struct dwc3_hwparams hwparams; + struct dentry *root; struct debugfs_regset32 *regset; u32 dbg_lsp_select; diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c index f2b7675c7f62..b9af4a81f51d 100644 --- a/drivers/usb/dwc3/debugfs.c +++ b/drivers/usb/dwc3/debugfs.c @@ -911,6 +911,7 @@ void dwc3_debugfs_init(struct dwc3 *dwc) dwc->regset->base = dwc->regs - DWC3_GLOBALS_REGS_START; root = debugfs_create_dir(dev_name(dwc->dev), usb_debug_root); + dwc->root = root; debugfs_create_regset32("regdump", 0444, root, dwc->regset); debugfs_create_file("lsp_dump", 0644, root, dwc, &dwc3_lsp_fops); @@ -929,6 +930,6 @@ void dwc3_debugfs_init(struct dwc3 *dwc) void dwc3_debugfs_exit(struct dwc3 *dwc) { - debugfs_remove(debugfs_lookup(dev_name(dwc->dev), usb_debug_root)); + debugfs_remove(dwc->root); kfree(dwc->regset); } diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 079cd333632e..6d6c188fcbea 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -3172,9 +3172,7 @@ static void dwc3_gadget_free_endpoints(struct dwc3 *dwc) list_del(&dep->endpoint.ep_list); } - debugfs_remove_recursive(debugfs_lookup(dep->name, - debugfs_lookup(dev_name(dep->dwc->dev), - usb_debug_root))); + debugfs_lookup_and_remove(dep->name, dwc->root); kfree(dep); } }