* [PATCH v1] regmap: ram: fix memory leaks in __regmap_init_ram() on error
@ 2026-04-16 23:56 Yuho Choi
2026-04-17 11:07 ` Mark Brown
0 siblings, 1 reply; 3+ messages in thread
From: Yuho Choi @ 2026-04-16 23:56 UTC (permalink / raw)
To: Mark Brown, Greg Kroah-Hartman, Rafael J . Wysocki,
Danilo Krummrich
Cc: linux-kernel, driver-core, Yuho Choi
Two allocations in __regmap_init_ram() are not cleaned up on failure.
If the kzalloc_objs() for data->written fails, data->read is returned
with no way for the caller to free it.
If __regmap_init() fails, neither data->read nor data->written is freed
because its error paths do not call bus->free_context() (which is
regmap_ram_free_context() here). Only regmap_exit() does, and that is
never reached on an init failure.
Free the allocated arrays before returning any error.
Fixes: f6352424e37e ("regmap: Add RAM backed register map")
Signed-off-by: Yuho Choi <dbgh9129@gmail.com>
---
drivers/base/regmap/regmap-ram.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/base/regmap/regmap-ram.c b/drivers/base/regmap/regmap-ram.c
index 0272d53fead11..c7356b0d8c832 100644
--- a/drivers/base/regmap/regmap-ram.c
+++ b/drivers/base/regmap/regmap-ram.c
@@ -71,11 +71,17 @@ struct regmap *__regmap_init_ram(struct device *dev,
return ERR_PTR(-ENOMEM);
data->written = kzalloc_objs(bool, config->max_register + 1);
- if (!data->written)
+ if (!data->written) {
+ kfree(data->read);
return ERR_PTR(-ENOMEM);
+ }
map = __regmap_init(dev, ®map_ram, data, config,
lock_key, lock_name);
+ if (IS_ERR(map)) {
+ kfree(data->read);
+ kfree(data->written);
+ }
return map;
}
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v1] regmap: ram: fix memory leaks in __regmap_init_ram() on error
2026-04-16 23:56 [PATCH v1] regmap: ram: fix memory leaks in __regmap_init_ram() on error Yuho Choi
@ 2026-04-17 11:07 ` Mark Brown
2026-04-17 14:50 ` 최유호
0 siblings, 1 reply; 3+ messages in thread
From: Mark Brown @ 2026-04-17 11:07 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rafael J . Wysocki, Danilo Krummrich,
Yuho Choi
Cc: linux-kernel, driver-core
On Thu, 16 Apr 2026 19:56:30 -0400, Yuho Choi wrote:
> regmap: ram: fix memory leaks in __regmap_init_ram() on error
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git for-7.1
Thanks!
[1/1] regmap: ram: fix memory leaks in __regmap_init_ram() on error
https://git.kernel.org/broonie/sound/c/7e555fcae40a
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v1] regmap: ram: fix memory leaks in __regmap_init_ram() on error
2026-04-17 11:07 ` Mark Brown
@ 2026-04-17 14:50 ` 최유호
0 siblings, 0 replies; 3+ messages in thread
From: 최유호 @ 2026-04-17 14:50 UTC (permalink / raw)
To: Mark Brown
Cc: Greg Kroah-Hartman, Rafael J . Wysocki, Danilo Krummrich,
linux-kernel, driver-core, Kim, Taegyu
Dear Mark,
Thanks for applying the patch.
Best regards,
Yuho Choi
On Fri, 17 Apr 2026 at 08:27, Mark Brown <broonie@kernel.org> wrote:
>
> On Thu, 16 Apr 2026 19:56:30 -0400, Yuho Choi wrote:
> > regmap: ram: fix memory leaks in __regmap_init_ram() on error
>
> Applied to
>
> https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git for-7.1
>
> Thanks!
>
> [1/1] regmap: ram: fix memory leaks in __regmap_init_ram() on error
> https://git.kernel.org/broonie/sound/c/7e555fcae40a
>
> 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
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-17 14:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-16 23:56 [PATCH v1] regmap: ram: fix memory leaks in __regmap_init_ram() on error Yuho Choi
2026-04-17 11:07 ` Mark Brown
2026-04-17 14:50 ` 최유호
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox