diff mbox series

[1/3] usb: typec: tcpm: Use usb_debug_root as root for our debugfs entry

Message ID 20190815191815.755606-1-hdegoede@redhat.com (mailing list archive)
State Superseded
Headers show
Series [1/3] usb: typec: tcpm: Use usb_debug_root as root for our debugfs entry | expand

Commit Message

Hans de Goede Aug. 15, 2019, 7:18 p.m. UTC
Use usb_debug_root as root for our debugfs entry instead of creating our
own subdirectory under the debugfs root.

Another patch in this series will make the same change to the fusb302
driver, which also uses dev_name() (on the same device) for the debugfs
entry name. So we also prefix dev_name() with "tcpm-" here to avoid a
name conflict.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/usb/typec/tcpm/tcpm.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)

Comments

Guenter Roeck Aug. 15, 2019, 7:46 p.m. UTC | #1
On Thu, Aug 15, 2019 at 09:18:13PM +0200, Hans de Goede wrote:
> Use usb_debug_root as root for our debugfs entry instead of creating our
> own subdirectory under the debugfs root.
> 
> Another patch in this series will make the same change to the fusb302
> driver, which also uses dev_name() (on the same device) for the debugfs
> entry name. So we also prefix dev_name() with "tcpm-" here to avoid a
> name conflict.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  drivers/usb/typec/tcpm/tcpm.c | 17 +++++------------
>  1 file changed, 5 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 15abe1d9958f..5241d17c3399 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -19,6 +19,7 @@
>  #include <linux/seq_file.h>
>  #include <linux/slab.h>
>  #include <linux/spinlock.h>
> +#include <linux/usb.h>
>  #include <linux/usb/pd.h>
>  #include <linux/usb/pd_ado.h>
>  #include <linux/usb/pd_bdo.h>
> @@ -571,17 +572,13 @@ static int tcpm_debug_show(struct seq_file *s, void *v)
>  }
>  DEFINE_SHOW_ATTRIBUTE(tcpm_debug);
>  
> -static struct dentry *rootdir;
> -
>  static void tcpm_debugfs_init(struct tcpm_port *port)
>  {
> -	mutex_init(&port->logbuffer_lock);
> -	/* /sys/kernel/debug/tcpm/usbcX */
> -	if (!rootdir)
> -		rootdir = debugfs_create_dir("tcpm", NULL);
> +	char name[NAME_MAX];
>  
> -	port->dentry = debugfs_create_file(dev_name(port->dev),
> -					   S_IFREG | 0444, rootdir,
> +	mutex_init(&port->logbuffer_lock);
> +	snprintf(name, NAME_MAX, "tcpm-%s", dev_name(port->dev));
> +	port->dentry = debugfs_create_file(name, S_IFREG | 0444, usb_debug_root,
>  					   port, &tcpm_debug_fops);
>  }
>  
> @@ -597,10 +594,6 @@ static void tcpm_debugfs_exit(struct tcpm_port *port)
>  	mutex_unlock(&port->logbuffer_lock);
>  
>  	debugfs_remove(port->dentry);
> -	if (list_empty(&rootdir->d_subdirs)) {
> -		debugfs_remove(rootdir);
> -		rootdir = NULL;
> -	}
>  }
>  
>  #else
> -- 
> 2.23.0.rc2
>
Heikki Krogerus Aug. 16, 2019, 7:55 a.m. UTC | #2
On Thu, Aug 15, 2019 at 09:18:13PM +0200, Hans de Goede wrote:
> Use usb_debug_root as root for our debugfs entry instead of creating our
> own subdirectory under the debugfs root.
> 
> Another patch in this series will make the same change to the fusb302
> driver, which also uses dev_name() (on the same device) for the debugfs
> entry name. So we also prefix dev_name() with "tcpm-" here to avoid a
> name conflict.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/tcpm/tcpm.c | 17 +++++------------
>  1 file changed, 5 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 15abe1d9958f..5241d17c3399 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -19,6 +19,7 @@
>  #include <linux/seq_file.h>
>  #include <linux/slab.h>
>  #include <linux/spinlock.h>
> +#include <linux/usb.h>
>  #include <linux/usb/pd.h>
>  #include <linux/usb/pd_ado.h>
>  #include <linux/usb/pd_bdo.h>
> @@ -571,17 +572,13 @@ static int tcpm_debug_show(struct seq_file *s, void *v)
>  }
>  DEFINE_SHOW_ATTRIBUTE(tcpm_debug);
>  
> -static struct dentry *rootdir;
> -
>  static void tcpm_debugfs_init(struct tcpm_port *port)
>  {
> -	mutex_init(&port->logbuffer_lock);
> -	/* /sys/kernel/debug/tcpm/usbcX */
> -	if (!rootdir)
> -		rootdir = debugfs_create_dir("tcpm", NULL);
> +	char name[NAME_MAX];
>  
> -	port->dentry = debugfs_create_file(dev_name(port->dev),
> -					   S_IFREG | 0444, rootdir,
> +	mutex_init(&port->logbuffer_lock);
> +	snprintf(name, NAME_MAX, "tcpm-%s", dev_name(port->dev));
> +	port->dentry = debugfs_create_file(name, S_IFREG | 0444, usb_debug_root,
>  					   port, &tcpm_debug_fops);
>  }
>  
> @@ -597,10 +594,6 @@ static void tcpm_debugfs_exit(struct tcpm_port *port)
>  	mutex_unlock(&port->logbuffer_lock);
>  
>  	debugfs_remove(port->dentry);
> -	if (list_empty(&rootdir->d_subdirs)) {
> -		debugfs_remove(rootdir);
> -		rootdir = NULL;
> -	}
>  }

I guess one option here as well would be to still group the entries
under the "tcpm" directry, but just place that under the
usb_debug_root directory.

thanks,
diff mbox series

Patch

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 15abe1d9958f..5241d17c3399 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -19,6 +19,7 @@ 
 #include <linux/seq_file.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
+#include <linux/usb.h>
 #include <linux/usb/pd.h>
 #include <linux/usb/pd_ado.h>
 #include <linux/usb/pd_bdo.h>
@@ -571,17 +572,13 @@  static int tcpm_debug_show(struct seq_file *s, void *v)
 }
 DEFINE_SHOW_ATTRIBUTE(tcpm_debug);
 
-static struct dentry *rootdir;
-
 static void tcpm_debugfs_init(struct tcpm_port *port)
 {
-	mutex_init(&port->logbuffer_lock);
-	/* /sys/kernel/debug/tcpm/usbcX */
-	if (!rootdir)
-		rootdir = debugfs_create_dir("tcpm", NULL);
+	char name[NAME_MAX];
 
-	port->dentry = debugfs_create_file(dev_name(port->dev),
-					   S_IFREG | 0444, rootdir,
+	mutex_init(&port->logbuffer_lock);
+	snprintf(name, NAME_MAX, "tcpm-%s", dev_name(port->dev));
+	port->dentry = debugfs_create_file(name, S_IFREG | 0444, usb_debug_root,
 					   port, &tcpm_debug_fops);
 }
 
@@ -597,10 +594,6 @@  static void tcpm_debugfs_exit(struct tcpm_port *port)
 	mutex_unlock(&port->logbuffer_lock);
 
 	debugfs_remove(port->dentry);
-	if (list_empty(&rootdir->d_subdirs)) {
-		debugfs_remove(rootdir);
-		rootdir = NULL;
-	}
 }
 
 #else