Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp168034ybl; Thu, 30 Jan 2020 19:28:18 -0800 (PST) X-Google-Smtp-Source: APXvYqy+eTpmzZ/iG2LdvyJG8evJk5Mlhp/vEG/0Iiw3KFFRWjemcvFqsfUzQ1OjFUaQI0oU5siy X-Received: by 2002:a05:6808:3ba:: with SMTP id n26mr5229141oie.62.1580441298328; Thu, 30 Jan 2020 19:28:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580441298; cv=none; d=google.com; s=arc-20160816; b=Qj6ksddr3a0hAH+buTd3xK27Oh3pLtYNpraqbcoMHYTMnRDCLHukaASZnwL8G9f11b 6vP+bAX+Tg/lhx5gRpY3xC2jWdnzJRJeAEnVYOfJi+NEIudqcshXIy4DXqGBS7IRNtJR cVIo1cp5X6FWHrgvlhpxrgdj85NmRvz0plttKRXh/jqu1VqbHNnRIo1JfbxSVLu4nJi3 qdONOYuG2cHVoWjnDrzUPjr6OouB7a7Zt4hrLrJ6D5ZxBShet6NRr89ZGczjVNZEhF8p YLk42VKDBseEIO4lVZH6nckURjbmMfBOTUqePAUBRcmKMX59SN7wWF0Hz0sfvws8gFvj 8kGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=nSKruqJ/WQ9CFzLw+y2LqH6OAopvrDrbcN3JTRY3iMs=; b=AqFHEyQKiBtCBPtmnxr4NXfM3bJJjaEBieWtw8gxeNJa8XsuQoBZjn0pHkqO1GALAy dbkzz67ZumqwzwKf7xyVKXKHkS7nz7Eat8sv1o7PuopTTSmp3SoOt246mGpHaWORmwNz YAjBGk0QoY4yElCs9dHieKiON9kvSoYBE3AyFN90vSxmKPOmNFdzqz2s60yXsy4C5WTk 37IvVY2c0uS+Q7UqiM/AiaNAlVRnUgD/kZvF6215W6wRJUYOGPP83LC1jrCLc0+7bbUm n57rRGMnhOss4etnLkFsry/GE/F7xk/VS7djJE7h9SkVuhSoXYlY7sVuPFyHTS6gZzcX jAbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=uTVL0cUA; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o25si4334528otk.28.2020.01.30.19.27.51; Thu, 30 Jan 2020 19:28:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=uTVL0cUA; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727827AbgAaD1u (ORCPT + 99 others); Thu, 30 Jan 2020 22:27:50 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:54760 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727824AbgAaD1u (ORCPT ); Thu, 30 Jan 2020 22:27:50 -0500 Received: by mail-wm1-f65.google.com with SMTP id g1so6238931wmh.4 for ; Thu, 30 Jan 2020 19:27:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=nSKruqJ/WQ9CFzLw+y2LqH6OAopvrDrbcN3JTRY3iMs=; b=uTVL0cUAvTSods/y86qFItSS2bYJuvaUaYZYjpioMSAg02jWuGPERKTw7e6/Thuvbb xKhxENSY6kN5vGOiqr/seLL3R3XyNGrUHdBqDv/EoDeArzysHred1/xC6DcYxcix3PvA Q0uzF1PIP5KvTAZLBtytv+YgS2HD4GasHuFFNf5yojCe5dEeaYUxgQSkn68VUInYtxwG 7ckgLhOuUpyCu2eL2KQIPKCOABwzjs+XK/kZ2ZvQC7OKcgooaTvvJoRKVeS6fuFI282m DMCGmaw1bDrQy/M9gh8IvlrNsaU6Bub1uLOxRdqQNghSZRA4sm5966xj8eP2I9X68y/B bTzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nSKruqJ/WQ9CFzLw+y2LqH6OAopvrDrbcN3JTRY3iMs=; b=mhueBh4bsBDjga6rcGS/yReFm3wtoCagbU9dt46XdvnNQ5/4Gmbvd08YHsJSFZ47RS RaTzYuoObdJkTEyToJKta8aGGhz4leJve3qsNUrpE+PKoZP5bnn5vOn7xSbCCCiwYJ2T MIOCDStrrLH+vFc5qBFuzJbc3OZQX9B+FrNMkolR8P3+PyNeuq2ZmxsJHnCEdx4GqaTM drBGIFyfuc2YjH62mBqbqkgEFvKs+/8vblvrfDJCAJOM10BS0SZJN07S1H51KpVUUOsN nyG+gM5H/VbvhFr8m2sQxUZ2ZQoRH3VaekeNINFQYmIoGgCPfjb0YKk8o0FAEwh1lqqe +LaA== X-Gm-Message-State: APjAAAUy6xhaoGB87gBGllDYHx+Dd79kNA6YEANc3Er3PajiDjjU7ic7 s6PXfPmijxYfhbZSZuFBx+3GXND7IDEkdvvVox4RrA== X-Received: by 2002:a7b:c3c9:: with SMTP id t9mr8895102wmj.18.1580441265943; Thu, 30 Jan 2020 19:27:45 -0800 (PST) MIME-Version: 1.0 References: <20200127164943.220776-1-marcel@holtmann.org> In-Reply-To: From: Archie Pusaka Date: Fri, 31 Jan 2020 11:27:34 +0800 Message-ID: Subject: Re: [RFC] Bluetooth: Add debugfs option to enable runtime debug statements To: Alain Michaud Cc: Marcel Holtmann , BlueZ Content-Type: text/plain; charset="UTF-8" Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Marcel, Thanks for the fantastic patch! My comments inline. > > Signed-off-by: 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(-) > > diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h > index e42bb8e03c09..d32d1f401efb 100644 > --- a/include/net/bluetooth/bluetooth.h > +++ b/include/net/bluetooth/bluetooth.h > @@ -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__) Should be fmt instead of mt. > +#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); > > diff --git a/net/bluetooth/Kconfig b/net/bluetooth/Kconfig > index 165148c7c4ce..64833640bf3d 100644 > --- a/net/bluetooth/Kconfig > +++ b/net/bluetooth/Kconfig > @@ -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? > + > source "drivers/bluetooth/Kconfig" > diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c > index 3fd124927d4d..fa0cd665f32a 100644 > --- a/net/bluetooth/af_bluetooth.c > +++ b/net/bluetooth/af_bluetooth.c > @@ -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(); > diff --git a/net/bluetooth/lib.c b/net/bluetooth/lib.c > index c09e0a3a0ed9..28cfc3fd8fbe 100644 > --- a/net/bluetooth/lib.c > +++ b/net/bluetooth/lib.c > @@ -27,6 +27,7 @@ > #define pr_fmt(fmt) "Bluetooth: " fmt > > #include > +#include > > #include > > @@ -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); Should be the empty function 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 > Thanks, Archie