Commit 530792ef authored by Fabio Estevam's avatar Fabio Estevam Committed by Mark Brown

regmap: Call regmap_debugfs_exit() prior to _init()

Since commit cffa4b21 ("regmap: debugfs: Fix a memory leak when
calling regmap_attach_dev"), the following debugfs error is seen
on i.MX boards:

debugfs: Directory 'dummy-iomuxc-gpr@20e0000' with parent 'regmap' already present!

In the attempt to fix the memory leak, the above commit added a NULL check
for map->debugfs_name. For the first debufs entry, map->debugfs_name is NULL
and then the new name is allocated via kasprintf().

For the second debugfs entry, map->debugfs_name() is no longer NULL, so
it will keep using the old entry name and the duplicate name error is seen.

Quoting Mark Brown:

"That means that if the device gets freed we'll end up with the old debugfs
file hanging around pointing at nothing.
...
To be more explicit this means we need a call to regmap_debugfs_exit()
which will clean up all the existing debugfs stuff before we loose
references to it."

Call regmap_debugfs_exit() prior to regmap_debugfs_init() to fix
the problem.

Tested on i.MX6Q and i.MX6SX boards.

Fixes: cffa4b21 ("regmap: debugfs: Fix a memory leak when calling regmap_attach_dev")
Suggested-by: default avatarMark Brown <broonie@kernel.org>
Signed-off-by: default avatarFabio Estevam <festevam@denx.de>
Link: https://lore.kernel.org/r/20220107163307.335404-1-festevam@gmail.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 02d6fdec
...@@ -647,6 +647,7 @@ int regmap_attach_dev(struct device *dev, struct regmap *map, ...@@ -647,6 +647,7 @@ int regmap_attach_dev(struct device *dev, struct regmap *map,
if (ret) if (ret)
return ret; return ret;
regmap_debugfs_exit(map);
regmap_debugfs_init(map); regmap_debugfs_init(map);
/* Add a devres resource for dev_get_regmap() */ /* Add a devres resource for dev_get_regmap() */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment