From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752564AbdK3MtL (ORCPT ); Thu, 30 Nov 2017 07:49:11 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:55050 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751783AbdK3MtJ (ORCPT ); Thu, 30 Nov 2017 07:49:09 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20171130124907euoutp01efe400599725252b3ae80e92a0d2884b~73fW58oUW2212022120euoutp01O X-AuditID: cbfec7f5-f79d06d0000031c7-96-5a1ffe427d8a From: Maciej Purski To: Greg Kroah-Hartman Cc: Marek Szyprowski , Russell King , Bartlomiej Zolnierkiewicz , linux-kernel@vger.kernel.org, Maciej Purski Subject: [PATCH v4] component: add debugfs support Date: Thu, 30 Nov 2017 13:48:32 +0100 Message-id: <1512046112-9474-1-git-send-email-m.purski@samsung.com> X-Mailer: git-send-email 2.7.4 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrKIsWRmVeSWpSXmKPExsWy7djPc7pO/+SjDKa1qVlsnLGe1aJ58Xo2 i8u75rBZLHh5i8Vi7ZG77BaX+icyObB5XL52kdlj/9w17B59W1YxenzeJBfAEsVlk5Kak1mW WqRvl8CV8ej1YZaCL4oVP9f2MDUwdsl0MXJySAiYSOx9vZENwhaTuHBvPZDNxSEksJRR4ubU 3ewQzmdGiXM7tzLBdMye8w6qahmjxIF7XxkhnP+MEqcbmoAcDg42AS2JNe3xIA0iAsYS/Wdn gU1iFrjFKPH0+gNGkISwgJHE6r372EFsFgFViUkLOsFsXgFnic7OXVDb5CRunutkBmmWEHjK KrFsXxdUwkXie1c3C4QtLPHq+BZ2CFtG4vJkmHi1xMWvu6Ceq5FovL0BqsZa4vOkLcwgNrMA n8SkbdOZQY6WEOCV6GgTgjA9JOZvjoWodpTY+OQKO0hYSCBW4tv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sBAIAAA== X-CMS-MailID: 20171130124906eucas1p2a671ee7d62ddebe9fde3a5def2d97f44 X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20171130124906eucas1p2a671ee7d62ddebe9fde3a5def2d97f44 X-RootMTR: 20171130124906eucas1p2a671ee7d62ddebe9fde3a5def2d97f44 References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently there is no information in any vfs about which devices a master component consists of, what makes debugging hard if one of the component devices fails to register. Add 'device_component' directory to debugfs. Create a new file for each component master, when it has been added. Remove it on a master deletion. Show a list of devices required by the given master and their status (registered or not). This provides an easy way to check, which device has failed to register if the given master device is not available in the system. Signed-off-by: Maciej Purski --- Changes in v4: - fix and expand commit message - inline no-op functions Changes in v3: - get rid of useless check - change directory name to "device_component" Changes in v2: - use seq_printf() instead of seq_puts() when printing headers - move whole debugfs code to the file beginning in order to avoid forward declarations or using multiple ifdefs --- drivers/base/component.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/drivers/base/component.c b/drivers/base/component.c index 89b032f..5adbfb8 100644 --- a/drivers/base/component.c +++ b/drivers/base/component.c @@ -17,6 +17,7 @@ #include #include #include +#include struct component; @@ -41,6 +42,7 @@ struct master { const struct component_master_ops *ops; struct device *dev; struct component_match *match; + struct dentry *dentry; }; struct component { @@ -56,6 +58,80 @@ static DEFINE_MUTEX(component_mutex); static LIST_HEAD(component_list); static LIST_HEAD(masters); +#ifdef CONFIG_DEBUG_FS + +static struct dentry *component_debugfs_dir; + +static int component_devices_show(struct seq_file *s, void *data) +{ + struct master *m = s->private; + struct component_match *match = m->match; + size_t i; + + mutex_lock(&component_mutex); + seq_printf(s, "%-40s %20s\n", "master name", "status"); + seq_puts(s, "-------------------------------------------------------------\n"); + seq_printf(s, "%-40s %20s\n\n", + dev_name(m->dev), m->bound ? "bound" : "not bound"); + + seq_printf(s, "%-40s %20s\n", "device name", "status"); + seq_puts(s, "-------------------------------------------------------------\n"); + for (i = 0; i < match->num; i++) { + struct device *d = (struct device *)match->compare[i].data; + + seq_printf(s, "%-40s %20s\n", dev_name(d), + match->compare[i].component ? + "registered" : "not registered"); + } + mutex_unlock(&component_mutex); + + return 0; +} + +static int component_devices_open(struct inode *inode, struct file *file) +{ + return single_open(file, component_devices_show, inode->i_private); +} + +static const struct file_operations component_devices_fops = { + .open = component_devices_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static int __init component_debug_init(void) +{ + component_debugfs_dir = debugfs_create_dir("device_component", NULL); + + return 0; +} + +core_initcall(component_debug_init); + +static void component_master_debugfs_add(struct master *m) +{ + m->dentry = debugfs_create_file(dev_name(m->dev), 0444, + component_debugfs_dir, + m, &component_devices_fops); +} + +static void component_master_debugfs_del(struct master *m) +{ + debugfs_remove(m->dentry); + m->dentry = NULL; +} + +#else + +static inline void component_master_debugfs_add(struct master *m) +{ } + +static inline void component_master_debugfs_del(struct master *m) +{ } + +#endif + static struct master *__master_find(struct device *dev, const struct component_master_ops *ops) { @@ -290,6 +366,7 @@ static void free_master(struct master *master) struct component_match *match = master->match; int i; + component_master_debugfs_del(master); list_del(&master->node); if (match) { @@ -323,6 +400,7 @@ int component_master_add_with_match(struct device *dev, master->ops = ops; master->match = match; + component_master_debugfs_add(master); /* Add to the list of available masters. */ mutex_lock(&component_mutex); list_add(&master->node, &masters); -- 2.7.4