Skip to contentSkip to conversation

Bluetooth: Add debugfs option to enable runtime debug statements

RFC Superseded Marcel Holtmann 3 participants 5 messages Jan 27, 2020 – Jan 31, 2020 1 message not in the archive

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Marcel Holtmann

author maintainer
#0 lore raw

RFC 1/1 Bluetooth: Add debugfs option to enable runtime debug statements

---
 include/net/bluetooth/bluetooth.h | 10 ++++-
 net/bluetooth/Kconfig             |  4 ++
 net/bluetooth/af_bluetooth.c      |  2 +
 net/bluetooth/lib.c               | 69 +++++++++++++++++++++++++++++++
 4 files changed, 84 insertions(+), 1 deletion(-)
include/net/bluetooth/bluetooth.h +9 -1
index e42bb8e03c09..d32d1f401efb 100644
@@ -129,6 +129,8 @@ void bt_warn(const char *fmt, ...);
 __printf(1, 2)
 void bt_err(const char *fmt, ...);
 __printf(1, 2)
+void bt_dbg(const char *fmt, ...);
+__printf(1, 2)
 void bt_warn_ratelimited(const char *fmt, ...);
 __printf(1, 2)
 void bt_err_ratelimited(const char *fmt, ...);
@@ -136,7 +138,11 @@ void bt_err_ratelimited(const char *fmt, ...);
 #define BT_INFO(fmt, ...)	bt_info(fmt "\n", ##__VA_ARGS__)
 #define BT_WARN(fmt, ...)	bt_warn(fmt "\n", ##__VA_ARGS__)
 #define BT_ERR(fmt, ...)	bt_err(fmt "\n", ##__VA_ARGS__)
-#define BT_DBG(fmt, ...)	pr_debug(fmt "\n", ##__VA_ARGS__)
+#if IS_ENABLED(CONFIG_BT_DEBUGFS_OPTION)
+#define BT_DBG(fmt, ...)	bt_dbg(fmt "\n", ##__VA_ARGS__)
+#else
+#define BT_DBG(fmt, ...)	pr_debug(mt "\n", ##__VA_ARGS__)
+#endif
 
 #define bt_dev_info(hdev, fmt, ...)				\
 	BT_INFO("%s: " fmt, (hdev)->name, ##__VA_ARGS__)
@@ -393,6 +399,8 @@ void bt_procfs_cleanup(struct net *net, const char *name);
 
 extern struct dentry *bt_debugfs;
 
+void bt_lib_debugfs_init(void);
+
 int l2cap_init(void);
 void l2cap_exit(void);
 
net/bluetooth/Kconfig +4 -0
index 165148c7c4ce..64833640bf3d 100644
@@ -128,4 +128,8 @@ config BT_DEBUGFS
 	  Provide extensive information about internal Bluetooth states
 	  in debugfs.
 
+config BT_DEBUGFS_OPTION
+	bool
+	default y if BT_DEBUGFS && !DYNAMIC_DEBUG
+
 source "drivers/bluetooth/Kconfig"
net/bluetooth/af_bluetooth.c +2 -0
index 3fd124927d4d..fa0cd665f32a 100644
@@ -731,6 +731,8 @@ static int __init bt_init(void)
 
 	bt_debugfs = debugfs_create_dir("bluetooth", NULL);
 
+	bt_lib_debugfs_init();
+
 	bt_leds_init();
 
 	err = bt_sysfs_init();
net/bluetooth/lib.c +69 -0

87 lines not on this page · raw message

Signature · 1 line
2.24.1
#2 lore raw
In reply to a message not in the archive

Resending in plain text... Sorry, old dog, new tricks... (or is it the opposite? :))

Quoted 178 lines · Alain Michaud

Hi Marcel,

Just a quick ack from me.

It looks good for me, but I'd like to get feedback from our team which has implemented the earlier proposal. The team however in Taipei aren't due back in from holiday until next week, so it may take some time before we get back to you.

Thanks,
Alain

Quoted 167 lines · Marcel Holtmann
---
 include/net/bluetooth/bluetooth.h | 10 ++++-
 net/bluetooth/Kconfig             |  4 ++
 net/bluetooth/af_bluetooth.c      |  2 +
 net/bluetooth/lib.c               | 69 +++++++++++++++++++++++++++++++
 4 files changed, 84 insertions(+), 1 deletion(-)
include/net/bluetooth/bluetooth.h +9 -1
index e42bb8e03c09..d32d1f401efb 100644
@@ -129,6 +129,8 @@ void bt_warn(const char *fmt, ...);
 __printf(1, 2)
 void bt_err(const char *fmt, ...);
 __printf(1, 2)
+void bt_dbg(const char *fmt, ...);
+__printf(1, 2)
 void bt_warn_ratelimited(const char *fmt, ...);
 __printf(1, 2)
 void bt_err_ratelimited(const char *fmt, ...);
@@ -136,7 +138,11 @@ void bt_err_ratelimited(const char *fmt, ...);
 #define BT_INFO(fmt, ...)      bt_info(fmt "\n", ##__VA_ARGS__)
 #define BT_WARN(fmt, ...)      bt_warn(fmt "\n", ##__VA_ARGS__)
 #define BT_ERR(fmt, ...)       bt_err(fmt "\n", ##__VA_ARGS__)
-#define BT_DBG(fmt, ...)       pr_debug(fmt "\n", ##__VA_ARGS__)
+#if IS_ENABLED(CONFIG_BT_DEBUGFS_OPTION)
+#define BT_DBG(fmt, ...)       bt_dbg(fmt "\n", ##__VA_ARGS__)
+#else
+#define BT_DBG(fmt, ...)       pr_debug(mt "\n", ##__VA_ARGS__)
+#endif
 
 #define bt_dev_info(hdev, fmt, ...)                            \
        BT_INFO("%s: " fmt, (hdev)->name, ##__VA_ARGS__)
@@ -393,6 +399,8 @@ void bt_procfs_cleanup(struct net *net, const char *name);
 
 extern struct dentry *bt_debugfs;
 
+void bt_lib_debugfs_init(void);
+
 int l2cap_init(void);
 void l2cap_exit(void);
 
net/bluetooth/Kconfig +4 -0
index 165148c7c4ce..64833640bf3d 100644
@@ -128,4 +128,8 @@ config BT_DEBUGFS
          Provide extensive information about internal Bluetooth states
          in debugfs.
 
+config BT_DEBUGFS_OPTION
+       bool
+       default y if BT_DEBUGFS && !DYNAMIC_DEBUG
+
 source "drivers/bluetooth/Kconfig"
net/bluetooth/af_bluetooth.c +2 -0
index 3fd124927d4d..fa0cd665f32a 100644
@@ -731,6 +731,8 @@ static int __init bt_init(void)
 
        bt_debugfs = debugfs_create_dir("bluetooth", NULL);
 
+       bt_lib_debugfs_init();
+
        bt_leds_init();
 
        err = bt_sysfs_init();
net/bluetooth/lib.c +69 -1
index c09e0a3a0ed9..28cfc3fd8fbe 100644
@@ -27,6 +27,7 @@
 #define pr_fmt(fmt) "Bluetooth: " fmt
 
 #include <linux/export.h>
+#include <linux/debugfs.h>
 
 #include <net/bluetooth/bluetooth.h>
 
@@ -135,6 +136,55 @@ int bt_to_errno(__u16 code)
 }
 EXPORT_SYMBOL(bt_to_errno);
 
+#ifdef CONFIG_BT_DEBUGFS_OPTION
+static bool debug_enable;
+
+static ssize_t debug_enable_read(struct file *file, char __user *user_buf,
+                                size_t count, loff_t *ppos)
+{
+       char buf[3];
+
+       buf[0] = debug_enable ? 'Y': 'N';
+       buf[1] = '\n';
+       buf[2] = '\0';
+       return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
+}
+
+static ssize_t debug_enable_write(struct file *file,
+                                 const char __user *user_buf,
+                                 size_t count, loff_t *ppos)
+{
+       bool enable;
+       int err;
+
+       err = kstrtobool_from_user(user_buf, count, &enable);
+       if (err)
+               return err;
+
+       if (enable == debug_enable)
+               return -EALREADY;
+
+       debug_enable = enable;
+
+       return count;
+}
+
+static const struct file_operations debug_enable_fops = {
+       .open           = simple_open,
+       .read           = debug_enable_read,
+       .write          = debug_enable_write,
+       .llseek         = default_llseek,
+};
+
+void bt_lib_debugfs_init(void)
+{
+       debugfs_create_file("debug_enable", 0644, bt_debugfs, NULL,
+                           &debug_enable_fops);
+}
+#else
+void bt_lib_debugfs_init(void);
+#endif
+
 void bt_info(const char *format, ...)
 {
        struct va_format vaf;
@@ -183,6 +233,25 @@ void bt_err(const char *format, ...)
 }
 EXPORT_SYMBOL(bt_err);
 
+void bt_dbg(const char *format, ...)
+{
+       struct va_format vaf;
+       va_list args;
+
+       if (likely(!debug_enable))
+               return;
+
+       va_start(args, format);
+
+       vaf.fmt = format;
+       vaf.va = &args;
+
+       printk(KERN_DEBUG pr_fmt("%pV"), &vaf);
+
+       va_end(args);
+}
+EXPORT_SYMBOL(bt_dbg);
+
 void bt_warn_ratelimited(const char *format, ...)
 {
        struct va_format vaf;
--

2.24.1

#3 lore raw
In reply to Marcel Holtmann

Adding +Archie Pusaka for comments.

Thanks,
Alain

Quoted 167 lines · Marcel Holtmann
---
 include/net/bluetooth/bluetooth.h | 10 ++++-
 net/bluetooth/Kconfig             |  4 ++
 net/bluetooth/af_bluetooth.c      |  2 +
 net/bluetooth/lib.c               | 69 +++++++++++++++++++++++++++++++
 4 files changed, 84 insertions(+), 1 deletion(-)
include/net/bluetooth/bluetooth.h +9 -1
index e42bb8e03c09..d32d1f401efb 100644
@@ -129,6 +129,8 @@ void bt_warn(const char *fmt, ...);
 __printf(1, 2)
 void bt_err(const char *fmt, ...);
 __printf(1, 2)
+void bt_dbg(const char *fmt, ...);
+__printf(1, 2)
 void bt_warn_ratelimited(const char *fmt, ...);
 __printf(1, 2)
 void bt_err_ratelimited(const char *fmt, ...);
@@ -136,7 +138,11 @@ void bt_err_ratelimited(const char *fmt, ...);
 #define BT_INFO(fmt, ...)      bt_info(fmt "\n", ##__VA_ARGS__)
 #define BT_WARN(fmt, ...)      bt_warn(fmt "\n", ##__VA_ARGS__)
 #define BT_ERR(fmt, ...)       bt_err(fmt "\n", ##__VA_ARGS__)
-#define BT_DBG(fmt, ...)       pr_debug(fmt "\n", ##__VA_ARGS__)
+#if IS_ENABLED(CONFIG_BT_DEBUGFS_OPTION)
+#define BT_DBG(fmt, ...)       bt_dbg(fmt "\n", ##__VA_ARGS__)
+#else
+#define BT_DBG(fmt, ...)       pr_debug(mt "\n", ##__VA_ARGS__)
+#endif
 
 #define bt_dev_info(hdev, fmt, ...)                            \
        BT_INFO("%s: " fmt, (hdev)->name, ##__VA_ARGS__)
@@ -393,6 +399,8 @@ void bt_procfs_cleanup(struct net *net, const char *name);
 
 extern struct dentry *bt_debugfs;
 
+void bt_lib_debugfs_init(void);
+
 int l2cap_init(void);
 void l2cap_exit(void);
 
net/bluetooth/Kconfig +4 -0
index 165148c7c4ce..64833640bf3d 100644
@@ -128,4 +128,8 @@ config BT_DEBUGFS
          Provide extensive information about internal Bluetooth states
          in debugfs.
 
+config BT_DEBUGFS_OPTION
+       bool
+       default y if BT_DEBUGFS && !DYNAMIC_DEBUG
+
 source "drivers/bluetooth/Kconfig"
net/bluetooth/af_bluetooth.c +2 -0
index 3fd124927d4d..fa0cd665f32a 100644
@@ -731,6 +731,8 @@ static int __init bt_init(void)
 
        bt_debugfs = debugfs_create_dir("bluetooth", NULL);
 
+       bt_lib_debugfs_init();
+
        bt_leds_init();
 
        err = bt_sysfs_init();
net/bluetooth/lib.c +69 -1
index c09e0a3a0ed9..28cfc3fd8fbe 100644
@@ -27,6 +27,7 @@
 #define pr_fmt(fmt) "Bluetooth: " fmt
 
 #include <linux/export.h>
+#include <linux/debugfs.h>
 
 #include <net/bluetooth/bluetooth.h>
 
@@ -135,6 +136,55 @@ int bt_to_errno(__u16 code)
 }
 EXPORT_SYMBOL(bt_to_errno);
 
+#ifdef CONFIG_BT_DEBUGFS_OPTION
+static bool debug_enable;
+
+static ssize_t debug_enable_read(struct file *file, char __user *user_buf,
+                                size_t count, loff_t *ppos)
+{
+       char buf[3];
+
+       buf[0] = debug_enable ? 'Y': 'N';
+       buf[1] = '\n';
+       buf[2] = '\0';
+       return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
+}
+
+static ssize_t debug_enable_write(struct file *file,
+                                 const char __user *user_buf,
+                                 size_t count, loff_t *ppos)
+{
+       bool enable;
+       int err;
+
+       err = kstrtobool_from_user(user_buf, count, &enable);
+       if (err)
+               return err;
+
+       if (enable == debug_enable)
+               return -EALREADY;
+
+       debug_enable = enable;
+
+       return count;
+}
+
+static const struct file_operations debug_enable_fops = {
+       .open           = simple_open,
+       .read           = debug_enable_read,
+       .write          = debug_enable_write,
+       .llseek         = default_llseek,
+};
+
+void bt_lib_debugfs_init(void)
+{
+       debugfs_create_file("debug_enable", 0644, bt_debugfs, NULL,
+                           &debug_enable_fops);
+}
+#else
+void bt_lib_debugfs_init(void);
+#endif
+
 void bt_info(const char *format, ...)
 {
        struct va_format vaf;
@@ -183,6 +233,25 @@ void bt_err(const char *format, ...)
 }
 EXPORT_SYMBOL(bt_err);
 
+void bt_dbg(const char *format, ...)
+{
+       struct va_format vaf;
+       va_list args;
+
+       if (likely(!debug_enable))
+               return;
+
+       va_start(args, format);
+
+       vaf.fmt = format;
+       vaf.va = &args;
+
+       printk(KERN_DEBUG pr_fmt("%pV"), &vaf);
+
+       va_end(args);
+}
+EXPORT_SYMBOL(bt_dbg);
+
 void bt_warn_ratelimited(const char *format, ...)
 {
        struct va_format vaf;
--

2.24.1

#4 lore raw

Hi Marcel,

Thanks for the fantastic patch! My comments inline.

Quoted 23 lines
---
 include/net/bluetooth/bluetooth.h | 10 ++++-
 net/bluetooth/Kconfig             |  4 ++
 net/bluetooth/af_bluetooth.c      |  2 +
 net/bluetooth/lib.c               | 69 +++++++++++++++++++++++++++++++
 4 files changed, 84 insertions(+), 1 deletion(-)
include/net/bluetooth/bluetooth.h +2 -0
index e42bb8e03c09..d32d1f401efb 100644
@@ -129,6 +129,8 @@ void bt_warn(const char *fmt, ...);
 __printf(1, 2)
 void bt_err(const char *fmt, ...);
 __printf(1, 2)
+void bt_dbg(const char *fmt, ...);
+__printf(1, 2)
 void bt_warn_ratelimited(const char *fmt, ...);
 __printf(1, 2)
 void bt_err_ratelimited(const char *fmt, ...);

include/net/bluetooth/bluetooth.h void bt_err_ratelimited(const char *fmt, ...); · line 144

Quoted 8 lines
include/net/bluetooth/bluetooth.h +4 -1
@@ -136,7 +138,11 @@ void bt_err_ratelimited(const char *fmt, ...);
 #define BT_INFO(fmt, ...)      bt_info(fmt "\n", ##__VA_ARGS__)
 #define BT_WARN(fmt, ...)      bt_warn(fmt "\n", ##__VA_ARGS__)
 #define BT_ERR(fmt, ...)       bt_err(fmt "\n", ##__VA_ARGS__)
-#define BT_DBG(fmt, ...)       pr_debug(fmt "\n", ##__VA_ARGS__)
+#if IS_ENABLED(CONFIG_BT_DEBUGFS_OPTION)
+#define BT_DBG(fmt, ...)       bt_dbg(fmt "\n", ##__VA_ARGS__)
+#else
+#define BT_DBG(fmt, ...)       pr_debug(mt "\n", ##__VA_ARGS__)

Should be fmt instead of mt.

Quoted 18 lines
include/net/bluetooth/bluetooth.h +3 -0
+#endif
 
 #define bt_dev_info(hdev, fmt, ...)                            \
        BT_INFO("%s: " fmt, (hdev)->name, ##__VA_ARGS__)
@@ -393,6 +399,8 @@ void bt_procfs_cleanup(struct net *net, const char *name);
 
 extern struct dentry *bt_debugfs;
 
+void bt_lib_debugfs_init(void);
+
 int l2cap_init(void);
 void l2cap_exit(void);
 
net/bluetooth/Kconfig +0 -0
index 165148c7c4ce..64833640bf3d 100644

net/bluetooth/Kconfig config BT_DEBUGFS · line 133

Quoted 6 lines
net/bluetooth/Kconfig +3 -0
@@ -128,4 +128,8 @@ config BT_DEBUGFS
          Provide extensive information about internal Bluetooth states
          in debugfs.
 
+config BT_DEBUGFS_OPTION
+       bool
+       default y if BT_DEBUGFS && !DYNAMIC_DEBUG

If I understand it correctly, setting BT_DEBUGFS_OPTION to true will cause all of the BT_DBG logs to be loaded into the resulting build. Prior to the introduction of this config setting, the logs by default are discarded from the build. Therefore, by introducing this option, there will be an increase in the size of the build.

Shouldn't this option defaults to false instead?

Quoted 68 lines
net/bluetooth/Kconfig +1 -0
+
 source "drivers/bluetooth/Kconfig"
net/bluetooth/af_bluetooth.c +2 -0
index 3fd124927d4d..fa0cd665f32a 100644
@@ -731,6 +731,8 @@ static int __init bt_init(void)
 
        bt_debugfs = debugfs_create_dir("bluetooth", NULL);
 
+       bt_lib_debugfs_init();
+
        bt_leds_init();
 
        err = bt_sysfs_init();
net/bluetooth/lib.c +38 -0
index c09e0a3a0ed9..28cfc3fd8fbe 100644
@@ -27,6 +27,7 @@
 #define pr_fmt(fmt) "Bluetooth: " fmt
 
 #include <linux/export.h>
+#include <linux/debugfs.h>
 
 #include <net/bluetooth/bluetooth.h>
 
@@ -135,6 +136,55 @@ int bt_to_errno(__u16 code)
 }
 EXPORT_SYMBOL(bt_to_errno);
 
+#ifdef CONFIG_BT_DEBUGFS_OPTION
+static bool debug_enable;
+
+static ssize_t debug_enable_read(struct file *file, char __user *user_buf,
+                                size_t count, loff_t *ppos)
+{
+       char buf[3];
+
+       buf[0] = debug_enable ? 'Y': 'N';
+       buf[1] = '\n';
+       buf[2] = '\0';
+       return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
+}
+
+static ssize_t debug_enable_write(struct file *file,
+                                 const char __user *user_buf,
+                                 size_t count, loff_t *ppos)
+{
+       bool enable;
+       int err;
+
+       err = kstrtobool_from_user(user_buf, count, &enable);
+       if (err)
+               return err;
+
+       if (enable == debug_enable)
+               return -EALREADY;
+
+       debug_enable = enable;
+
+       return count;
+}
+
+static const struct file_operations debug_enable_fops = {
+       .open           = simple_open,
+       .read           = debug_enable_read,
+       .write          = debug_enable_write,

net/bluetooth/lib.c int bt_to_errno(__u16 code) · line 185

Quoted 10 lines
net/bluetooth/lib.c +10 -0
+       .llseek         = default_llseek,
+};
+
+void bt_lib_debugfs_init(void)
+{
+       debugfs_create_file("debug_enable", 0644, bt_debugfs, NULL,
+                           &debug_enable_fops);
+}
+#else
+void bt_lib_debugfs_init(void);

Should be the empty function
bt_lib_debugfs_init(void)
{
}

Quoted 32 lines
net/bluetooth/lib.c +21 -1
+#endif
+
 void bt_info(const char *format, ...)
 {
        struct va_format vaf;
@@ -183,6 +233,25 @@ void bt_err(const char *format, ...)
 }
 EXPORT_SYMBOL(bt_err);
 
+void bt_dbg(const char *format, ...)
+{
+       struct va_format vaf;
+       va_list args;
+
+       if (likely(!debug_enable))
+               return;
+
+       va_start(args, format);
+
+       vaf.fmt = format;
+       vaf.va = &args;
+
+       printk(KERN_DEBUG pr_fmt("%pV"), &vaf);
+
+       va_end(args);
+}
+EXPORT_SYMBOL(bt_dbg);
+
 void bt_warn_ratelimited(const char *format, ...)
 {
        struct va_format vaf;
--
Quoted 2 lines

2.24.1

Thanks,
Archie

author maintainer
#5 lore raw

Hi Archie,

Quoted 27 lines

Thanks for the fantastic patch! My comments inline.

Quoted 25 lines

---

include/net/bluetooth/bluetooth.h | 10 ++++-
net/bluetooth/Kconfig             |  4 ++
net/bluetooth/af_bluetooth.c      |  2 +
net/bluetooth/lib.c               | 69 +++++++++++++++++++++++++++++++
4 files changed, 84 insertions(+), 1 deletion(-)
include/net/bluetooth/bluetooth.h +2 -0
index e42bb8e03c09..d32d1f401efb 100644
@@ -129,6 +129,8 @@ void bt_warn(const char *fmt, ...);
 __printf(1, 2)
 void bt_err(const char *fmt, ...);
 __printf(1, 2)
+void bt_dbg(const char *fmt, ...);
+__printf(1, 2)
 void bt_warn_ratelimited(const char *fmt, ...);
 __printf(1, 2)
 void bt_err_ratelimited(const char *fmt, ...);
@@ -136,7 +138,11 @@ void bt_err_ratelimited(const char *fmt, ...);
 #define BT_INFO(fmt, ...)      bt_info(fmt "\n", ##__VA_ARGS__)
 #define BT_WARN(fmt, ...)      bt_warn(fmt "\n", ##__VA_ARGS__)
Quoted 8 lines

include/net/bluetooth/bluetooth.h void bt_err_ratelimited(const char *fmt, ...); · line 144

Quoted 6 lines
include/net/bluetooth/bluetooth.h +4 -1
 #define BT_ERR(fmt, ...)       bt_err(fmt "\n", ##__VA_ARGS__)
-#define BT_DBG(fmt, ...)       pr_debug(fmt "\n", ##__VA_ARGS__)
+#if IS_ENABLED(CONFIG_BT_DEBUGFS_OPTION)
+#define BT_DBG(fmt, ...)       bt_dbg(fmt "\n", ##__VA_ARGS__)
+#else
+#define BT_DBG(fmt, ...)       pr_debug(mt "\n", ##__VA_ARGS__)

Should be fmt instead of mt.

Indeed.

Quoted 32 lines
Quoted 19 lines
include/net/bluetooth/bluetooth.h +3 -0
+#endif
 
 #define bt_dev_info(hdev, fmt, ...)                            \
       BT_INFO("%s: " fmt, (hdev)->name, ##__VA_ARGS__)
@@ -393,6 +399,8 @@ void bt_procfs_cleanup(struct net *net, const char *name);
 
 extern struct dentry *bt_debugfs;
 
+void bt_lib_debugfs_init(void);
+
 int l2cap_init(void);
 void l2cap_exit(void);
 
net/bluetooth/Kconfig +0 -0
index 165148c7c4ce..64833640bf3d 100644

net/bluetooth/Kconfig config BT_DEBUGFS · line 133

Quoted 6 lines
net/bluetooth/Kconfig +3 -0
@@ -128,4 +128,8 @@ config BT_DEBUGFS
         Provide extensive information about internal Bluetooth states
         in debugfs.
 
+config BT_DEBUGFS_OPTION
+       bool
+       default y if BT_DEBUGFS && !DYNAMIC_DEBUG

If I understand it correctly, setting BT_DEBUGFS_OPTION to true will cause all of the BT_DBG logs to be loaded into the resulting build. Prior to the introduction of this config setting, the logs by default are discarded from the build. Therefore, by introducing this option, there will be an increase in the size of the build.

Quoted 1 line

Shouldn't this option defaults to false instead?

It defaults to y only if you a) selected BT_DEBUGFS and b) have disabled DYNAMIC_DEBUG. Otherwise it is off and defaults back to using pr_debug. Which is in case of disabled DYNAMIC_DEBUG results in disabled debug statement.

So it is not worth than with dynamic debug. We could tweak the bt_dbg part a bit to reduce the overhead, but it is not as bad. However what we can add is an extra comment in the BT_DEBUGFS help text to mention that case with DYNAMIC_DEBUG disabled.

Quoted 75 lines
Quoted 75 lines
net/bluetooth/Kconfig +1 -0
+

source "drivers/bluetooth/Kconfig"

net/bluetooth/af_bluetooth.c +2 -0
index 3fd124927d4d..fa0cd665f32a 100644
@@ -731,6 +731,8 @@ static int __init bt_init(void)
 
       bt_debugfs = debugfs_create_dir("bluetooth", NULL);
 
+       bt_lib_debugfs_init();
+
       bt_leds_init();
 
       err = bt_sysfs_init();
net/bluetooth/lib.c +45 -0
index c09e0a3a0ed9..28cfc3fd8fbe 100644
@@ -27,6 +27,7 @@
 #define pr_fmt(fmt) "Bluetooth: " fmt
 
 #include <linux/export.h>
+#include <linux/debugfs.h>
 
 #include <net/bluetooth/bluetooth.h>
 
@@ -135,6 +136,55 @@ int bt_to_errno(__u16 code)
 }
 EXPORT_SYMBOL(bt_to_errno);
 
+#ifdef CONFIG_BT_DEBUGFS_OPTION
+static bool debug_enable;
+
+static ssize_t debug_enable_read(struct file *file, char __user *user_buf,
+                                size_t count, loff_t *ppos)
+{
+       char buf[3];
+
+       buf[0] = debug_enable ? 'Y': 'N';
+       buf[1] = '\n';
+       buf[2] = '\0';
+       return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
+}
+
+static ssize_t debug_enable_write(struct file *file,
+                                 const char __user *user_buf,
+                                 size_t count, loff_t *ppos)
+{
+       bool enable;
+       int err;
+
+       err = kstrtobool_from_user(user_buf, count, &enable);
+       if (err)
+               return err;
+
+       if (enable == debug_enable)
+               return -EALREADY;
+
+       debug_enable = enable;
+
+       return count;
+}
+
+static const struct file_operations debug_enable_fops = {
+       .open           = simple_open,
+       .read           = debug_enable_read,
+       .write          = debug_enable_write,
+       .llseek         = default_llseek,
+};
+
+void bt_lib_debugfs_init(void)
+{
+       debugfs_create_file("debug_enable", 0644, bt_debugfs, NULL,
+                           &debug_enable_fops);
Quoted 9 lines

net/bluetooth/lib.c int bt_to_errno(__u16 code) · line 185

Quoted 3 lines
net/bluetooth/lib.c +3 -0
+}
+#else
+void bt_lib_debugfs_init(void);

Should be the empty function
bt_lib_debugfs_init(void)
{
}

Correct. I screwed this up.

Regards

Marcel