2022-01-07 16:33:39

by Fabio Estevam

[permalink] [raw]
Subject: [PATCH v3] regmap: Call regmap_debugfs_exit() prior to _init()

From: Fabio Estevam <[email protected]>

Since commit cffa4b2122f5 ("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: cffa4b2122f5 ("regmap: debugfs: Fix a memory leak when calling regmap_attach_dev")
Suggested-by: Mark Brown <[email protected]>
Signed-off-by: Fabio Estevam <[email protected]>
---
Changes since v2:
- Use regmap_debugfs_exit() as suggested by Mark.

drivers/base/regmap/regmap.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 21a0c2562ec0..f7811641ed5a 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -647,6 +647,7 @@ int regmap_attach_dev(struct device *dev, struct regmap *map,
if (ret)
return ret;

+ regmap_debugfs_exit(map);
regmap_debugfs_init(map);

/* Add a devres resource for dev_get_regmap() */
--
2.25.1



2022-01-07 18:25:18

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v3] regmap: Call regmap_debugfs_exit() prior to _init()

On Fri, 7 Jan 2022 13:33:07 -0300, Fabio Estevam wrote:
> From: Fabio Estevam <[email protected]>
>
> Since commit cffa4b2122f5 ("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!
>
> [...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git for-next

Thanks!

[1/1] regmap: Call regmap_debugfs_exit() prior to _init()
commit: 530792efa6cb86f5612ff093333fec735793b582

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark