regmap: debugfs: potentially duplicate the name string of the config
Subsystems (2)
PATCH 1/1 regmap: debugfs: potentially duplicate the name string of the config
In function regmap_debugfs_init the name of the regmap_config is assigned in a node of regmap_debugfs_early_list to be used later after regmap is initialized. It is unknown how and when the name is allocated and freed. Therefore the name should be copied to the node using 'kstrdup_const'. This fixes an error
"debugfs: Directory 'dummy-' with parent 'regmap' already present!" where the name was freed in function of_syscon_register before it was accessed.
--- drivers/base/regmap/regmap-debugfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/base/regmap/regmap-debugfs.c +3 -1
@@ -569,7 +569,7 @@ void regmap_debugfs_init(struct regmap *map, const char *name)if (!node)return ; node->map = map; - node->name = name; + node->name =kstrdup_const (name,GFP_KERNEL );mutex_lock (®map_debugfs_early_lock);list_add (&node->link, ®map_debugfs_early_list);mutex_unlock (®map_debugfs_early_lock);
@@ -664,6 +664,7 @@ void regmap_debugfs_exit(struct regmap *map) link) {if (node->map == map) {list_del (&node->link); +kfree_const (node->name);kfree (node); } }
@@ -681,6 +682,7 @@ void regmap_debugfs_initcall(void)list_for_each_entry_safe (node, tmp, ®map_debugfs_early_list, link) {regmap_debugfs_init (node->map, node->name);list_del (&node->link); +kfree_const (node->name);kfree (node); }mutex_unlock (®map_debugfs_early_lock);
Signature · 1 line
2.17.1
Mark Brown
maintainerQuoted 4 lines · Dafna Hirschfeld
In function
regmap_debugfs_initthe name of theregmap_configis assigned in a node ofregmap_debugfs_early_listto be used later after regmap is initialized. It is unknown how and when the name is allocated and freed. Therefore the name should be copied to the node using 'kstrdup_const'.
It does not follow that the name should be copied, it equally follows (and is expected by the API given that the common case is that the name is a static string assigned at build time) that the caller should not free the string while the regmap is active.
Quoted 4 lines
This fixes an error
"debugfs: Directory 'dummy-' with parent 'regmap' already present!" where the name was freed in functionof_syscon_registerbefore it was accessed.
Fix the caller. It is *very* much unclear to me why a syscon would be assigning a name for a regmap it creates in the first place.
Hi, thank you for the fast review,
Am 08.09.20 um 17:35 schrieb Mark Brown:
Quoted 10 lines · Dafna Hirschfeld
Quoted 4 lines
In function
regmap_debugfs_initthe name of theregmap_configis assigned in a node ofregmap_debugfs_early_listto be used later after regmap is initialized. It is unknown how and when the name is allocated and freed. Therefore the name should be copied to the node using 'kstrdup_const'.It does not follow that the name should be copied, it equally follows (and is expected by the API given that the common case is that the name is a static string assigned at build time) that the caller should not free the string while the regmap is active.
I see that the same copy is already done in function __regmap_init in drivers/base/regmap/regmap.c added in patch 8253bb3f82554 "regmap: potentially duplicate the name string stored in regmap" so I thought I'll do the same.
Quoted 8 lines
Quoted 5 lines
This fixes an error
"debugfs: Directory 'dummy-' with parent 'regmap' already present!" where the name was freed in functionof_syscon_registerbefore it was accessed.Fix the caller. It is *very* much unclear to me why a syscon would be assigning a name for a regmap it creates in the first place.
I'll have a deeper look.
Thanks,
Dafna
Quoted 1 line
Mark Brown
maintainerQuoted 10 lines · Dafna Hirschfeld
Am 08.09.20 um 17:35 schrieb Mark Brown:
Quoted 4 lines
It does not follow that the name should be copied, it equally follows (and is expected by the API given that the common case is that the name is a static string assigned at build time) that the caller should not free the string while the regmap is active.
I see that the same copy is already done in function
__regmap_initindrivers/base/regmap/regmap.cadded in patch8253bb3f82554"regmap: potentially duplicate the name string stored in regmap" so I thought I'll do the same.
Hrm, right. In that case why not just use that copy we've already taken?
Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
This fixes an error
"debugfs: Directory 'dummy-' with parent 'regmap' already present!" where the name was freed in functionof_syscon_registerbefore it was accessed.Fix the caller. It is *very* much unclear to me why a syscon would be assigning a name for a regmap it creates in the first place.
I'll have a deeper look.
Whatever happens that caller looks like it shouldn't be creating an additional name unless I'm missing something about the context.