Skip to contentSkip to conversation

usb: common: change usb_debug_root as static variable

RFC PATCH In review Chunfeng Yun 3 participants 4 messages Nov 1, 2019 – Nov 5, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 usb: common: change usb_debug_root as static variable

Try to avoid using extern global variable, and provide two functions for the usage cases

---
NOTE:
Prepared but not send out patches for drivers using usb_debug_root,
because I'm not sure whether this patch is needed, and many drivers will be modified.

---
 drivers/usb/common/common.c | 16 ++++++++++++++--
 include/linux/usb.h         |  5 ++++-
 2 files changed, 18 insertions(+), 3 deletions(-)
drivers/usb/common/common.c +14 -2
index 1433260d99b4..639ee6d243a2 100644
@@ -293,8 +293,20 @@ struct device *usb_of_get_companion_dev(struct device *dev)
 EXPORT_SYMBOL_GPL(usb_of_get_companion_dev);
 #endif
 
-struct dentry *usb_debug_root;
-EXPORT_SYMBOL_GPL(usb_debug_root);
+static struct dentry *usb_debug_root;
+
+struct dentry *usb_debugfs_create_dir(const char *name)
+{
+	return debugfs_create_dir(name, usb_debug_root);
+}
+EXPORT_SYMBOL_GPL(usb_debugfs_create_dir);
+
+struct dentry *usb_debugfs_create_file(const char *name, umode_t mode,
+			void *data, const struct file_operations *fops)
+{
+	return debugfs_create_file(name, mode, usb_debug_root, data, fops);
+}
+EXPORT_SYMBOL_GPL(usb_debugfs_create_file);
 
 static int __init usb_common_init(void)
 {
include/linux/usb.h +4 -1
index e656e7b4b1e4..ad96e0aa0127 100644
@@ -2001,7 +2001,10 @@ extern void usb_register_notify(struct notifier_block *nb);
 extern void usb_unregister_notify(struct notifier_block *nb);
 
 /* debugfs stuff */
-extern struct dentry *usb_debug_root;
+extern struct dentry *usb_debugfs_create_dir(const char *name);
+extern struct dentry *
+usb_debugfs_create_file(const char *name, umode_t mode, void *data,
+			const struct file_operations *fops);
 
 /* LED triggers */
 enum usb_led_event {
Signature · 1 line
2.23.0
#1 lore raw
Quoted 2 lines · Chunfeng Yun

Try to avoid using extern global variable, and provide two functions for the usage cases

That is 3 different things all in one patch, not generally considered a good thing at all.

Also, who is going to use these new functions? Why are they needed?

Quoted 16 lines

---
NOTE:
Prepared but not send out patches for drivers using usb_debug_root,
because I'm not sure whether this patch is needed, and many drivers will be modified.

---
 drivers/usb/common/common.c | 16 ++++++++++++++--
 include/linux/usb.h         |  5 ++++-
 2 files changed, 18 insertions(+), 3 deletions(-)
drivers/usb/common/common.c +0 -0
index 1433260d99b4..639ee6d243a2 100644

drivers/usb/common/common.c struct device *usb_of_get_companion_dev(struct device *dev) · line 296

Quoted 6 lines
drivers/usb/common/common.c +1 -2
@@ -293,8 +293,20 @@ struct device *usb_of_get_companion_dev(struct device *dev)
 EXPORT_SYMBOL_GPL(usb_of_get_companion_dev);
 #endif
 
-struct dentry *usb_debug_root;
-EXPORT_SYMBOL_GPL(usb_debug_root);
+static struct dentry *usb_debug_root;

Doesn't this break things as-is? You can't do that in a single patch either :(

drivers/usb/common/common.c struct device *usb_of_get_companion_dev(struct device *dev) · line 307

Quoted 11 lines
drivers/usb/common/common.c +11 -0
+
+struct dentry *usb_debugfs_create_dir(const char *name)
+{
+	return debugfs_create_dir(name, usb_debug_root);
+}
+EXPORT_SYMBOL_GPL(usb_debugfs_create_dir);
+
+struct dentry *usb_debugfs_create_file(const char *name, umode_t mode,
+			void *data, const struct file_operations *fops)
+{
+	return debugfs_create_file(name, mode, usb_debug_root, data, fops);

I doubt many people want to create a file in the usb "root" debugfs directory, right? They _should_ be just creating a new subdirectory in there instead.

thanks,

greg k-h

#2 lore raw
Quoted 9 lines · Greg Kroah-Hartman
Quoted 2 lines · Chunfeng Yun

Try to avoid using extern global variable, and provide two functions for the usage cases

That is 3 different things all in one patch, not generally considered a good thing at all.

Also, who is going to use these new functions? Why are they needed?

After remove global variable usb_debug_root, the drivers using usb_debug_root to create directory or files will use these new APIs instead.

Quoted 20 lines
Quoted 20 lines

---
NOTE:
Prepared but not send out patches for drivers using usb_debug_root,
because I'm not sure whether this patch is needed, and many drivers will be modified.

---
 drivers/usb/common/common.c | 16 ++++++++++++++--
 include/linux/usb.h         |  5 ++++-
 2 files changed, 18 insertions(+), 3 deletions(-)
drivers/usb/common/common.c +0 -0
index 1433260d99b4..639ee6d243a2 100644
@@ -293,8 +293,20 @@ struct device *usb_of_get_companion_dev(struct device *dev)
 EXPORT_SYMBOL_GPL(usb_of_get_companion_dev);
 #endif
 
Quoted 5 lines

drivers/usb/common/common.c struct device *usb_of_get_companion_dev(struct device *dev) · line 296

Quoted 3 lines
drivers/usb/common/common.c +1 -2
-struct dentry *usb_debug_root;
-EXPORT_SYMBOL_GPL(usb_debug_root);
+static struct dentry *usb_debug_root;

Doesn't this break things as-is?

Yes, it will, I didn't send out other patches for the drivers using usb_debug_root.

Quoted 2 lines

You can't do that in a single patch
either :(

When I make usb_debug_root as static variable, two APIs need be added due to other driver use it to create directory or file.

Quoted 16 lines

drivers/usb/common/common.c struct device *usb_of_get_companion_dev(struct device *dev) · line 307

Quoted 12 lines
drivers/usb/common/common.c +11 -0
+
+struct dentry *usb_debugfs_create_dir(const char *name)
+{
+	return debugfs_create_dir(name, usb_debug_root);
+}
+EXPORT_SYMBOL_GPL(usb_debugfs_create_dir);
+
+struct dentry *usb_debugfs_create_file(const char *name, umode_t mode,
+			void *data, const struct file_operations *fops)
+{
+	return debugfs_create_file(name, mode, usb_debug_root, data, fops);

I doubt many people want to create a file in the usb "root" debugfs directory, right? They _should_ be just creating a new subdirectory in there instead.

Currently only three .c files creates a file under usb 'root' debugfs directory.

Quoted 4 lines

thanks,

greg k-h

#3 lore raw
In reply to Chunfeng Yun
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi Chunfeng,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on usb/usb-testing]
[also build test ERROR on v5.4-rc5 next-20191031]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Chunfeng-Yun/usb-common-change-usb_debug_root-as-static-variable/20191102-164343
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing
config: i386-defconfig (attached as .config)
compiler: gcc-7 (Debian 7.4.0-14) 7.4.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

drivers/usb/core/usb.c: In function 'usb_debugfs_init':

>> drivers/usb/core/usb.c:970:58: error: 'usb_debug_root' undeclared (first use in this function); did you mean 'usb_debugfs_init'?

usb_devices_root = debugfs_create_file("devices", 0444, usb_debug_root,
^~~~~~~~~~~~~~
usb_debugfs_init
drivers/usb/core/usb.c:970:58: note: each undeclared identifier is reported only once for each function it appears in
--
drivers/usb/host/ohci-hcd.c: In function 'ohci_hcd_mod_init':

>> drivers/usb/host/ohci-hcd.c:1282:47: error: 'usb_debug_root' undeclared (first use in this function); did you mean 'ohci_debug_root'?
     ohci_debug_root = debugfs_create_dir("ohci", usb_debug_root);
                                                  ^~~~~~~~~~~~~~
                                                  ohci_debug_root
   drivers/usb/host/ohci-hcd.c:1282:47: note: each undeclared identifier is reported only once for each function it appears in
--
   drivers/usb/host/xhci-debugfs.c: In function 'xhci_debugfs_create_root':
>> drivers/usb/host/xhci-debugfs.c:604:49: error: 'usb_debug_root' undeclared (first use in this function); did you mean 'xhci_debugfs_root'?
     xhci_debugfs_root = debugfs_create_dir("xhci", usb_debug_root);
                                                    ^~~~~~~~~~~~~~
                                                    xhci_debugfs_root
   drivers/usb/host/xhci-debugfs.c:604:49: note: each undeclared identifier is reported only once for each function it appears in
--
   drivers/usb/mon/mon_text.c: In function 'mon_text_init':
>> drivers/usb/mon/mon_text.c:766:41: error: 'usb_debug_root' undeclared (first use in this function); did you mean 'ctl_table_root'?
     mon_dir = debugfs_create_dir("usbmon", usb_debug_root);
                                            ^~~~~~~~~~~~~~
                                            ctl_table_root

drivers/usb/mon/mon_text.c:766:41: note: each undeclared identifier is reported only once for each function it appears in

vim +970 drivers/usb/core/usb.c

00048b8bde5a6c Greg Kroah-Hartman 2009-04-24  967  
b708692dda1edf Greg Kroah-Hartman 2018-05-29  968  static void usb_debugfs_init(void)
00048b8bde5a6c Greg Kroah-Hartman 2009-04-24  969  {
812086d362a1d5 Greg Kroah-Hartman 2019-06-05 @970  	usb_devices_root = debugfs_create_file("devices", 0444, usb_debug_root,
812086d362a1d5 Greg Kroah-Hartman 2019-06-05  971  					       NULL, &usbfs_devices_fops);
00048b8bde5a6c Greg Kroah-Hartman 2009-04-24  972  }

00048b8bde5a6c Greg Kroah-Hartman 2009-04-24 973

:::::: The code at line 970 was first introduced by commit
:::::: 812086d362a1d589d2b2e10957254ac13e83522b USB: move usb debugfs directory creation to the usb common core

:::::: TO: Greg Kroah-Hartman <[email protected]> :::::: CC: Greg Kroah-Hartman <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation