mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] component: add debugfs support
       [not found] <CGME20171115110441eucas1p2555810a1e10e270fd944c2c031d92305@eucas1p2.samsung.com>
@ 2017-11-15 11:04 ` Maciej Purski
  2017-11-15 11:12   ` Russell King - ARM Linux
  0 siblings, 1 reply; 2+ messages in thread
From: Maciej Purski @ 2017-11-15 11:04 UTC (permalink / raw)
  To: linux-kernel; +Cc: Greg Kroah-Hartman, Russell King, Maciej Purski

Add 'component' directory to debugfs. Create a new file for each master,
when a master is added. Remove it on a master deletion.

Show a list of devices matched with master and indicate if
master's components were successfully added and if the whole master is
bound.

Signed-off-by: Maciej Purski <m.purski@samsung.com>
---
 drivers/base/component.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 86 insertions(+)

diff --git a/drivers/base/component.c b/drivers/base/component.c
index 89b032f..7a55888 100644
--- a/drivers/base/component.c
+++ b/drivers/base/component.c
@@ -17,6 +17,7 @@
 #include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/slab.h>
+#include <linux/debugfs.h>
 
 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,9 @@ static DEFINE_MUTEX(component_mutex);
 static LIST_HEAD(component_list);
 static LIST_HEAD(masters);
 
+static void component_master_debugfs_add(struct master *m);
+static void component_master_debugfs_del(struct master *m);
+
 static struct master *__master_find(struct device *dev,
 	const struct component_master_ops *ops)
 {
@@ -290,6 +295,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 +329,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);
@@ -527,4 +534,83 @@ void component_del(struct device *dev, const struct component_ops *ops)
 }
 EXPORT_SYMBOL_GPL(component_del);
 
+#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_puts(s, "master name                                            status\n");
+	seq_puts(s, "-------------------------------------------------------------\n");
+	seq_printf(s, "%-40s %20s\n\n",
+		   dev_name(m->dev), m->bound ? "bound" : "not bound");
+
+	seq_puts(s, "device name                                            status\n");
+	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("component", NULL);
+
+	if (!component_debugfs_dir)
+		return -ENOMEM;
+
+	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 void component_master_debugfs_add(struct master *m)
+{
+}
+
+static void component_master_debugfs_del(struct master *m)
+{
+}
+
+#endif
+
 MODULE_LICENSE("GPL v2");
-- 
2.7.4

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] component: add debugfs support
  2017-11-15 11:04 ` [PATCH] component: add debugfs support Maciej Purski
@ 2017-11-15 11:12   ` Russell King - ARM Linux
  0 siblings, 0 replies; 2+ messages in thread
From: Russell King - ARM Linux @ 2017-11-15 11:12 UTC (permalink / raw)
  To: Maciej Purski; +Cc: linux-kernel, Greg Kroah-Hartman

On Wed, Nov 15, 2017 at 12:04:26PM +0100, Maciej Purski wrote:
> +static void component_master_debugfs_add(struct master *m);
> +static void component_master_debugfs_del(struct master *m);

Please avoid forward declarations.

> +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_puts(s, "master name                                            status\n");

Would:

	seq_printf(s, "%-40s %20s\n", "master name", "status");

be better - it becomes more obvious what is intended (that is for the
headings to line up with the data below.)

> +	seq_puts(s, "-------------------------------------------------------------\n");
> +	seq_printf(s, "%-40s %20s\n\n",
> +		   dev_name(m->dev), m->bound ? "bound" : "not bound");
> +
> +	seq_puts(s, "device name                                            status\n");

Ditto.

-- 
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 8.8Mbps down 630kbps up
According to speedtest.net: 8.21Mbps down 510kbps up

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-11-15 11:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20171115110441eucas1p2555810a1e10e270fd944c2c031d92305@eucas1p2.samsung.com>
2017-11-15 11:04 ` [PATCH] component: add debugfs support Maciej Purski
2017-11-15 11:12   ` Russell King - ARM Linux

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®