Received: by 2002:a25:ab0e:0:0:0:0:0 with SMTP id u14csp1021727ybi; Tue, 28 Jan 2020 17:06:47 -0800 (PST) X-Google-Smtp-Source: APXvYqwfFMYAO0Ls3KdLY9ig+JuQU18Wa3ktOKACrjqXet5bD35gdjEmSuIXmazTRZtG944p7P50 X-Received: by 2002:aca:1a17:: with SMTP id a23mr4620560oia.84.1580260007322; Tue, 28 Jan 2020 17:06:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580260007; cv=none; d=google.com; s=arc-20160816; b=Mb+wkZXgCQVNIo2e/hCPqOh02JUfxYgbCUsNyKXyhOJLJc4oNGh+pZjqPXv0CiAnyN CpkUwHcPlTsPFL/YxCN7cElIxvjRr7nKj8/XsgG3pG0Xwcj7YWxZe6R/hhbuByhQBBdt yEKyCRsuD1EcvHHYCeB17VaCOS2SFBfUO0VIRQtsJazWSSZj5mOGGPk65AI9U4ftfp1i kJja/qR40URA7kdppL2nRaC6+jgNWE8T5AbQzhpfwkffPpc0tkDK5stoXZiJ1wA3ttg+ JGj4LfgRhmciJLbaWcPCTup+dAACAsHisH8W9p57+13EwHdiIhErH86q7k+cDqQOUdYx mnnQ== 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=4SzeRN4tb4Oag8moFSgx4wSvDhrlGrkBPGrQoZ+aJug=; b=0oa4hD6yNhd932NZaXVV8eFvL8wHamwcvwRCiUsArdzL1Y63XasdM/MVrFS6LzKb1H 8r1OdKVVPSexGkl2TsMHxGPef16HP22+D2MKqCscTWaFQGzIuA4tAYZyF8Q9soRUYEnH R5bm0HkJarTA27hvOSWPcGu4ySIfeLC6BEoM5PZpSEi4aBNAmt7Fi8Xon6gSrTvjxGUq NtN00KRT9mwtFELo4KVl0zhEZJ+Pdm16k/sxC11FVypRVkl0nkMQ6oq34M4nhIbGsUKr 9HIcbb9E4wrBZwVh1TSrRF3QKhc7Tptw5yrwJPeDy38Kgo8rh3Qb8/0OGXsAcNhi6ZGq 2PmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=fsxp2EYI; 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 w2si250610otq.31.2020.01.28.17.06.19; Tue, 28 Jan 2020 17:06:47 -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=fsxp2EYI; 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 S1726546AbgA2AvJ (ORCPT + 99 others); Tue, 28 Jan 2020 19:51:09 -0500 Received: from mail-lj1-f174.google.com ([209.85.208.174]:41036 "EHLO mail-lj1-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726383AbgA2AvJ (ORCPT ); Tue, 28 Jan 2020 19:51:09 -0500 Received: by mail-lj1-f174.google.com with SMTP id h23so16652235ljc.8 for ; Tue, 28 Jan 2020 16:51:07 -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=4SzeRN4tb4Oag8moFSgx4wSvDhrlGrkBPGrQoZ+aJug=; b=fsxp2EYICztXBGUeivluOm+Jh6Xcz8sw3Yw+YnrQuvJPRrnWpKs29/mlkxftYCVCFV meFf7h+5W9dimflgnp1BCN6R3IICMVR+/Yja1+BwKXoERrg118L6UhpaSvizvQE4NjIf 343WjhWHLgqpSYsSld4zNJjg7SvWfQKNN+rSRd8qG+iRnX61ZX1ldAg5TcpKXy8CPv3m 9FudjxKV0wlyYofUyeL3c8jyJpN8SMFfTWsvUrS/M9G8vSBRUS9hwH418wOVoQIy/D6a uqGosNj3Dfc2l2pM5/kKmRKooHSFXhwo/gKqWtPRUxG1CGE1HbDJ7HyezYQ6ulFrIs2T qSew== 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=4SzeRN4tb4Oag8moFSgx4wSvDhrlGrkBPGrQoZ+aJug=; b=olBeaWWUEZJKvZXtMbVMVC1xqpow2os/QESS0w96//oXziodNzLrewTj5VYOMO5zK5 mrYSIFCmAn3FY4zAvy8GkBpBs/CFqh6voHmPhUDZlEYwW3zvgPkwLlUKZx9nEdKlrT2Y S9RioyNwWNCiuAz5mELu7oZDL9opeJNQFp5hPdKgXmcyK9s33S7/4ELvl5/Aoiq04ogE cFv/J89BosBpxXYGyqx3soHCieGOHjlrbKdKDC+5xY7pMUB6mLRPOwQz1wNMaRKe2cz6 9cNNTACJclpe2peaaJDb3o5oCsIASHXTwPHGPp9sKvUWrrdYtpWz99cPVGBRfZcj6Izn 5Xyg== X-Gm-Message-State: APjAAAWCZgiI4NkQFUrv9c9oIDHjYEqGGWAA+ye14fhfS5hCROK207Bh 5AIMajaE57hLy4LJj47eFs5n2j+sMoHpJBUEKLphji6yGoI= X-Received: by 2002:a2e:9e03:: with SMTP id e3mr14867557ljk.186.1580259066682; Tue, 28 Jan 2020 16:51:06 -0800 (PST) MIME-Version: 1.0 References: <20200127164943.220776-1-marcel@holtmann.org> In-Reply-To: From: Alain Michaud Date: Tue, 28 Jan 2020 19:50:54 -0500 Message-ID: Subject: Re: [RFC] Bluetooth: Add debugfs option to enable runtime debug statements To: Marcel Holtmann Cc: 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 Resending in plain text... Sorry, old dog, new tricks... (or is it the opposite? :)) On Tue, Jan 28, 2020 at 7:48 PM Alain Michaud wrote: > > 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 > > On Mon, Jan 27, 2020 at 11:49 AM Marcel Holtmann wrote: >> >> 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__) >> +#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 >> + >> 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); >> +#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 >>