All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] regmap: debugfs: Fix a boot time crash with early regmap init
@ 2013-10-24  9:07 Tero Kristo
  2013-10-24  9:18 ` Mark Brown
  0 siblings, 1 reply; 3+ messages in thread
From: Tero Kristo @ 2013-10-24  9:07 UTC (permalink / raw)
  To: broonie, linux-kernel

If called early enough, regmap_debugfs_init causes a crash, if the
fs subsystem does not have its mount cache created yet. Even if this
would work, the root node for the regmap debugfs is still missing,
thus postpone the regmap_debugfs_init in this case until the root
node is created. A special regmap_debugfs_early list is created for
this purpose which is parsed later in the boot.

Signed-off-by: Tero Kristo <t-kristo@ti.com>
---
 drivers/base/regmap/regmap-debugfs.c |   28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c
index de11eca..e2d8f03 100644
--- a/drivers/base/regmap/regmap-debugfs.c
+++ b/drivers/base/regmap/regmap-debugfs.c
@@ -15,10 +15,18 @@
 #include <linux/debugfs.h>
 #include <linux/uaccess.h>
 #include <linux/device.h>
+#include <linux/list.h>
 
 #include "internal.h"
 
+struct regmap_debugfs_node {
+	struct regmap *map;
+	const char *name;
+	struct list_head link;
+};
+
 static struct dentry *regmap_debugfs_root;
+static LIST_HEAD(regmap_debugfs_early);
 
 /* Calculate the length of a fixed format  */
 static size_t regmap_calc_reg_len(int max_val, char *buf, size_t buf_size)
@@ -465,6 +473,18 @@ void regmap_debugfs_init(struct regmap *map, const char *name)
 	struct rb_node *next;
 	struct regmap_range_node *range_node;
 
+	/* If we don't have the debugfs root yet, postpone init */
+	if (!regmap_debugfs_root) {
+		struct regmap_debugfs_node *node;
+		node = kzalloc(sizeof(*node), GFP_KERNEL);
+		if (!node)
+			return;
+		node->map = map;
+		node->name = name;
+		list_add(&node->link, &regmap_debugfs_early);
+		return;
+	}
+
 	INIT_LIST_HEAD(&map->debugfs_off_cache);
 	mutex_init(&map->cache_lock);
 
@@ -528,9 +548,17 @@ void regmap_debugfs_exit(struct regmap *map)
 
 void regmap_debugfs_initcall(void)
 {
+	struct regmap_debugfs_node *node, *tmp;
+
 	regmap_debugfs_root = debugfs_create_dir("regmap", NULL);
 	if (!regmap_debugfs_root) {
 		pr_warn("regmap: Failed to create debugfs root\n");
 		return;
 	}
+
+	list_for_each_entry_safe(node, tmp, &regmap_debugfs_early, link) {
+		regmap_debugfs_init(node->map, node->name);
+		list_del(&node->link);
+		kfree(node);
+	}
 }
-- 
1.7.9.5


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

* Re: [PATCH] regmap: debugfs: Fix a boot time crash with early regmap init
  2013-10-24  9:07 [PATCH] regmap: debugfs: Fix a boot time crash with early regmap init Tero Kristo
@ 2013-10-24  9:18 ` Mark Brown
  2013-10-24 12:03   ` Tero Kristo
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Brown @ 2013-10-24  9:18 UTC (permalink / raw)
  To: Tero Kristo; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 695 bytes --]

On Thu, Oct 24, 2013 at 12:07:48PM +0300, Tero Kristo wrote:

> +	if (!regmap_debugfs_root) {
> +		struct regmap_debugfs_node *node;
> +		node = kzalloc(sizeof(*node), GFP_KERNEL);
> +		if (!node)
> +			return;
> +		node->map = map;
> +		node->name = name;
> +		list_add(&node->link, &regmap_debugfs_early);
> +		return;
> +	}
> +

init is somewhat parallel so I'd be happier if we locked the list to
make sure that we don't corrupt the list.

We also need something to handle removal of items from the list if the
regmap is destroyed prior to the initcall running (for example in error
handling cases), otherwise we could end up creating debugfs files
pointing at devices that no longer exist.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [PATCH] regmap: debugfs: Fix a boot time crash with early regmap init
  2013-10-24  9:18 ` Mark Brown
@ 2013-10-24 12:03   ` Tero Kristo
  0 siblings, 0 replies; 3+ messages in thread
From: Tero Kristo @ 2013-10-24 12:03 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-kernel

On 10/24/2013 12:18 PM, Mark Brown wrote:
> On Thu, Oct 24, 2013 at 12:07:48PM +0300, Tero Kristo wrote:
>
>> +	if (!regmap_debugfs_root) {
>> +		struct regmap_debugfs_node *node;
>> +		node = kzalloc(sizeof(*node), GFP_KERNEL);
>> +		if (!node)
>> +			return;
>> +		node->map = map;
>> +		node->name = name;
>> +		list_add(&node->link, &regmap_debugfs_early);
>> +		return;
>> +	}
>> +
>
> init is somewhat parallel so I'd be happier if we locked the list to
> make sure that we don't corrupt the list.

Ok, I added a mutex for protection (later registration might take some 
time so didn't want to use spinlock.)

> We also need something to handle removal of items from the list if the
> regmap is destroyed prior to the initcall running (for example in error
> handling cases), otherwise we could end up creating debugfs files
> pointing at devices that no longer exist.

Added cleanup for the list in the regmap_debugfs_exit() call. Sending v2 
shortly.

-Tero

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

end of thread, other threads:[~2013-10-24 12:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-24  9:07 [PATCH] regmap: debugfs: Fix a boot time crash with early regmap init Tero Kristo
2013-10-24  9:18 ` Mark Brown
2013-10-24 12:03   ` Tero Kristo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.