All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] USB: dwc3: remove debugfs root dentry storage
@ 2021-06-09  9:39 Greg Kroah-Hartman
  2021-06-09 18:47 ` Jack Pham
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2021-06-09  9:39 UTC (permalink / raw)
  To: linux-usb
  Cc: linux-kernel, Greg Kroah-Hartman, Felipe Balbi, Jack Pham, Peter Chen

There is no need to keep around the debugfs "root" directory for the
dwc3 device.  Instead, look it up anytime we need to find it.  This will
help when callers get out-of-order and we had the potential to have a
"stale" pointer around for the root dentry, as has happened in the past.

Cc: Felipe Balbi <balbi@kernel.org>
Cc: Jack Pham <jackp@codeaurora.org>
Cc: Peter Chen <peter.chen@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/usb/dwc3/core.h    | 2 --
 drivers/usb/dwc3/debugfs.c | 8 ++++----
 drivers/usb/dwc3/gadget.c  | 4 +++-
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index c5d5760cdf53..dccdf13b5f9e 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -1013,7 +1013,6 @@ struct dwc3_scratchpad_array {
  * @link_state: link state
  * @speed: device speed (super, high, full, low)
  * @hwparams: copy of hwparams registers
- * @root: debugfs root folder pointer
  * @regset: debugfs pointer to regdump file
  * @dbg_lsp_select: current debug lsp mux register selection
  * @test_mode: true when we're entering a USB test mode
@@ -1222,7 +1221,6 @@ 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 5dbbe53269d3..f2b7675c7f62 100644
--- a/drivers/usb/dwc3/debugfs.c
+++ b/drivers/usb/dwc3/debugfs.c
@@ -889,8 +889,10 @@ static void dwc3_debugfs_create_endpoint_files(struct dwc3_ep *dep,
 void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep)
 {
 	struct dentry		*dir;
+	struct dentry		*root;
 
-	dir = debugfs_create_dir(dep->name, dep->dwc->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);
 }
 
@@ -909,8 +911,6 @@ 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 +929,6 @@ void dwc3_debugfs_init(struct dwc3 *dwc)
 
 void dwc3_debugfs_exit(struct dwc3 *dwc)
 {
-	debugfs_remove_recursive(dwc->root);
+	debugfs_remove(debugfs_lookup(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 7cc99b6d0bfe..026a2ad0fc80 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2799,7 +2799,9 @@ static void dwc3_gadget_free_endpoints(struct dwc3 *dwc)
 			list_del(&dep->endpoint.ep_list);
 		}
 
-		debugfs_remove_recursive(debugfs_lookup(dep->name, dwc->root));
+		debugfs_remove_recursive(debugfs_lookup(dep->name,
+				debugfs_lookup(dev_name(dep->dwc->dev),
+					       usb_debug_root)));
 		kfree(dep);
 	}
 }
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] USB: dwc3: remove debugfs root dentry storage
  2021-06-09  9:39 [PATCH] USB: dwc3: remove debugfs root dentry storage Greg Kroah-Hartman
@ 2021-06-09 18:47 ` Jack Pham
  2021-06-09 18:59   ` Greg Kroah-Hartman
  2021-06-10  1:14 ` Peter Chen
  2021-06-10  9:28 ` Felipe Balbi
  2 siblings, 1 reply; 5+ messages in thread
From: Jack Pham @ 2021-06-09 18:47 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, Felipe Balbi, Peter Chen

On Wed, Jun 09, 2021 at 11:39:24AM +0200, Greg Kroah-Hartman wrote:
> There is no need to keep around the debugfs "root" directory for the
> dwc3 device.  Instead, look it up anytime we need to find it.  This will
> help when callers get out-of-order and we had the potential to have a
> "stale" pointer around for the root dentry, as has happened in the past.
> 
> Cc: Felipe Balbi <balbi@kernel.org>
> Cc: Jack Pham <jackp@codeaurora.org>
> Cc: Peter Chen <peter.chen@kernel.org>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
>  drivers/usb/dwc3/core.h    | 2 --
>  drivers/usb/dwc3/debugfs.c | 8 ++++----
>  drivers/usb/dwc3/gadget.c  | 4 +++-
>  3 files changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> index c5d5760cdf53..dccdf13b5f9e 100644
> --- a/drivers/usb/dwc3/core.h
> +++ b/drivers/usb/dwc3/core.h
> @@ -1013,7 +1013,6 @@ struct dwc3_scratchpad_array {
>   * @link_state: link state
>   * @speed: device speed (super, high, full, low)
>   * @hwparams: copy of hwparams registers
> - * @root: debugfs root folder pointer
>   * @regset: debugfs pointer to regdump file
>   * @dbg_lsp_select: current debug lsp mux register selection
>   * @test_mode: true when we're entering a USB test mode
> @@ -1222,7 +1221,6 @@ 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 5dbbe53269d3..f2b7675c7f62 100644
> --- a/drivers/usb/dwc3/debugfs.c
> +++ b/drivers/usb/dwc3/debugfs.c
> @@ -889,8 +889,10 @@ static void dwc3_debugfs_create_endpoint_files(struct dwc3_ep *dep,
>  void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep)
>  {
>  	struct dentry		*dir;
> +	struct dentry		*root;
>  
> -	dir = debugfs_create_dir(dep->name, dep->dwc->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);
>  }
>  
> @@ -909,8 +911,6 @@ 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 +929,6 @@ void dwc3_debugfs_init(struct dwc3 *dwc)
>  
>  void dwc3_debugfs_exit(struct dwc3 *dwc)
>  {
> -	debugfs_remove_recursive(dwc->root);
> +	debugfs_remove(debugfs_lookup(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 7cc99b6d0bfe..026a2ad0fc80 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -2799,7 +2799,9 @@ static void dwc3_gadget_free_endpoints(struct dwc3 *dwc)
>  			list_del(&dep->endpoint.ep_list);
>  		}
>  
> -		debugfs_remove_recursive(debugfs_lookup(dep->name, dwc->root));
> +		debugfs_remove_recursive(debugfs_lookup(dep->name,
> +				debugfs_lookup(dev_name(dep->dwc->dev),
> +					       usb_debug_root)));

Nested calls to debugfs_lookup() :). But it does work, and similarly
avoids the out-of-order debugfs removal issue as well even without
Peter's fix.

Tested-by: Jack Pham <jackp@codeaurora.org>

Thanks
Jack
-- 
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] USB: dwc3: remove debugfs root dentry storage
  2021-06-09 18:47 ` Jack Pham
@ 2021-06-09 18:59   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2021-06-09 18:59 UTC (permalink / raw)
  To: Jack Pham; +Cc: linux-usb, linux-kernel, Felipe Balbi, Peter Chen

On Wed, Jun 09, 2021 at 11:47:15AM -0700, Jack Pham wrote:
> On Wed, Jun 09, 2021 at 11:39:24AM +0200, Greg Kroah-Hartman wrote:
> > There is no need to keep around the debugfs "root" directory for the
> > dwc3 device.  Instead, look it up anytime we need to find it.  This will
> > help when callers get out-of-order and we had the potential to have a
> > "stale" pointer around for the root dentry, as has happened in the past.
> > 
> > Cc: Felipe Balbi <balbi@kernel.org>
> > Cc: Jack Pham <jackp@codeaurora.org>
> > Cc: Peter Chen <peter.chen@kernel.org>
> > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > ---
> >  drivers/usb/dwc3/core.h    | 2 --
> >  drivers/usb/dwc3/debugfs.c | 8 ++++----
> >  drivers/usb/dwc3/gadget.c  | 4 +++-
> >  3 files changed, 7 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> > index c5d5760cdf53..dccdf13b5f9e 100644
> > --- a/drivers/usb/dwc3/core.h
> > +++ b/drivers/usb/dwc3/core.h
> > @@ -1013,7 +1013,6 @@ struct dwc3_scratchpad_array {
> >   * @link_state: link state
> >   * @speed: device speed (super, high, full, low)
> >   * @hwparams: copy of hwparams registers
> > - * @root: debugfs root folder pointer
> >   * @regset: debugfs pointer to regdump file
> >   * @dbg_lsp_select: current debug lsp mux register selection
> >   * @test_mode: true when we're entering a USB test mode
> > @@ -1222,7 +1221,6 @@ 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 5dbbe53269d3..f2b7675c7f62 100644
> > --- a/drivers/usb/dwc3/debugfs.c
> > +++ b/drivers/usb/dwc3/debugfs.c
> > @@ -889,8 +889,10 @@ static void dwc3_debugfs_create_endpoint_files(struct dwc3_ep *dep,
> >  void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep)
> >  {
> >  	struct dentry		*dir;
> > +	struct dentry		*root;
> >  
> > -	dir = debugfs_create_dir(dep->name, dep->dwc->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);
> >  }
> >  
> > @@ -909,8 +911,6 @@ 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 +929,6 @@ void dwc3_debugfs_init(struct dwc3 *dwc)
> >  
> >  void dwc3_debugfs_exit(struct dwc3 *dwc)
> >  {
> > -	debugfs_remove_recursive(dwc->root);
> > +	debugfs_remove(debugfs_lookup(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 7cc99b6d0bfe..026a2ad0fc80 100644
> > --- a/drivers/usb/dwc3/gadget.c
> > +++ b/drivers/usb/dwc3/gadget.c
> > @@ -2799,7 +2799,9 @@ static void dwc3_gadget_free_endpoints(struct dwc3 *dwc)
> >  			list_del(&dep->endpoint.ep_list);
> >  		}
> >  
> > -		debugfs_remove_recursive(debugfs_lookup(dep->name, dwc->root));
> > +		debugfs_remove_recursive(debugfs_lookup(dep->name,
> > +				debugfs_lookup(dev_name(dep->dwc->dev),
> > +					       usb_debug_root)));
> 
> Nested calls to debugfs_lookup() :). But it does work, and similarly
> avoids the out-of-order debugfs removal issue as well even without
> Peter's fix.

Yeah, it's funny, but it's safer than trying to store a pointer around :)

> Tested-by: Jack Pham <jackp@codeaurora.org>

Many thanks for testing.

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] USB: dwc3: remove debugfs root dentry storage
  2021-06-09  9:39 [PATCH] USB: dwc3: remove debugfs root dentry storage Greg Kroah-Hartman
  2021-06-09 18:47 ` Jack Pham
@ 2021-06-10  1:14 ` Peter Chen
  2021-06-10  9:28 ` Felipe Balbi
  2 siblings, 0 replies; 5+ messages in thread
From: Peter Chen @ 2021-06-10  1:14 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, Felipe Balbi, Jack Pham

On 21-06-09 11:39:24, Greg Kroah-Hartman wrote:
> There is no need to keep around the debugfs "root" directory for the
> dwc3 device.  Instead, look it up anytime we need to find it.  This will
> help when callers get out-of-order and we had the potential to have a
> "stale" pointer around for the root dentry, as has happened in the past.
> 
> Cc: Felipe Balbi <balbi@kernel.org>
> Cc: Jack Pham <jackp@codeaurora.org>
> Cc: Peter Chen <peter.chen@kernel.org>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Reviewed-by: Peter Chen <peter.chen@kernel.org>
> ---
>  drivers/usb/dwc3/core.h    | 2 --
>  drivers/usb/dwc3/debugfs.c | 8 ++++----
>  drivers/usb/dwc3/gadget.c  | 4 +++-
>  3 files changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> index c5d5760cdf53..dccdf13b5f9e 100644
> --- a/drivers/usb/dwc3/core.h
> +++ b/drivers/usb/dwc3/core.h
> @@ -1013,7 +1013,6 @@ struct dwc3_scratchpad_array {
>   * @link_state: link state
>   * @speed: device speed (super, high, full, low)
>   * @hwparams: copy of hwparams registers
> - * @root: debugfs root folder pointer
>   * @regset: debugfs pointer to regdump file
>   * @dbg_lsp_select: current debug lsp mux register selection
>   * @test_mode: true when we're entering a USB test mode
> @@ -1222,7 +1221,6 @@ 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 5dbbe53269d3..f2b7675c7f62 100644
> --- a/drivers/usb/dwc3/debugfs.c
> +++ b/drivers/usb/dwc3/debugfs.c
> @@ -889,8 +889,10 @@ static void dwc3_debugfs_create_endpoint_files(struct dwc3_ep *dep,
>  void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep)
>  {
>  	struct dentry		*dir;
> +	struct dentry		*root;
>  
> -	dir = debugfs_create_dir(dep->name, dep->dwc->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);
>  }
>  
> @@ -909,8 +911,6 @@ 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 +929,6 @@ void dwc3_debugfs_init(struct dwc3 *dwc)
>  
>  void dwc3_debugfs_exit(struct dwc3 *dwc)
>  {
> -	debugfs_remove_recursive(dwc->root);
> +	debugfs_remove(debugfs_lookup(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 7cc99b6d0bfe..026a2ad0fc80 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -2799,7 +2799,9 @@ static void dwc3_gadget_free_endpoints(struct dwc3 *dwc)
>  			list_del(&dep->endpoint.ep_list);
>  		}
>  
> -		debugfs_remove_recursive(debugfs_lookup(dep->name, dwc->root));
> +		debugfs_remove_recursive(debugfs_lookup(dep->name,
> +				debugfs_lookup(dev_name(dep->dwc->dev),
> +					       usb_debug_root)));
>  		kfree(dep);
>  	}
>  }
> -- 
> 2.32.0
> 

-- 

Thanks,
Peter Chen


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] USB: dwc3: remove debugfs root dentry storage
  2021-06-09  9:39 [PATCH] USB: dwc3: remove debugfs root dentry storage Greg Kroah-Hartman
  2021-06-09 18:47 ` Jack Pham
  2021-06-10  1:14 ` Peter Chen
@ 2021-06-10  9:28 ` Felipe Balbi
  2 siblings, 0 replies; 5+ messages in thread
From: Felipe Balbi @ 2021-06-10  9:28 UTC (permalink / raw)
  To: Greg Kroah-Hartman, linux-usb
  Cc: linux-kernel, Greg Kroah-Hartman, Jack Pham, Peter Chen

[-- Attachment #1: Type: text/plain, Size: 605 bytes --]

Greg Kroah-Hartman <gregkh@linuxfoundation.org> writes:

> There is no need to keep around the debugfs "root" directory for the
> dwc3 device.  Instead, look it up anytime we need to find it.  This will
> help when callers get out-of-order and we had the potential to have a
> "stale" pointer around for the root dentry, as has happened in the past.
>
> Cc: Felipe Balbi <balbi@kernel.org>
> Cc: Jack Pham <jackp@codeaurora.org>
> Cc: Peter Chen <peter.chen@kernel.org>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Acked-by: Felipe Balbi <balbi@kernel.org>

-- 
balbi

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 511 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-06-10  9:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-09  9:39 [PATCH] USB: dwc3: remove debugfs root dentry storage Greg Kroah-Hartman
2021-06-09 18:47 ` Jack Pham
2021-06-09 18:59   ` Greg Kroah-Hartman
2021-06-10  1:14 ` Peter Chen
2021-06-10  9:28 ` Felipe Balbi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.