]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
regmap: ram: fix memory leaks in __regmap_init_ram() on error
authorYuho Choi <dbgh9129@gmail.com>
Thu, 16 Apr 2026 23:56:30 +0000 (19:56 -0400)
committerMark Brown <broonie@kernel.org>
Fri, 17 Apr 2026 11:07:31 +0000 (12:07 +0100)
commit7e555fcae40ab2ba91fd5cd54a5a83096414957f
tree94d64db7807888c6fb2c92a25c1c807e59cf0068
parentbad4bd28abf4d7cb2adcb39cc0de789729d2cd69
regmap: ram: fix memory leaks in __regmap_init_ram() on error

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>
Link: https://patch.msgid.link/20260416235630.78408-1-dbgh9129@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/base/regmap/regmap-ram.c