]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
regmap: fix potential memory leak of regmap_bus
authorAbdun Nihaal <abdun.nihaal@gmail.com>
Thu, 26 Jun 2025 17:28:21 +0000 (22:58 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 1 Aug 2025 08:47:28 +0000 (09:47 +0100)
commit0915f1856c48d7181ee8a501d8797f2764bc999f
tree0dc212d74a610127521a7a39f212f82febfc02f5
parent881f3066fd8dfb91a1cdb8dbee142ab45e08fcfc
regmap: fix potential memory leak of regmap_bus

[ Upstream commit c871c199accb39d0f4cb941ad0dccabfc21e9214 ]

When __regmap_init() is called from __regmap_init_i2c() and
__regmap_init_spi() (and their devm versions), the bus argument
obtained from regmap_get_i2c_bus() and regmap_get_spi_bus(), may be
allocated using kmemdup() to support quirks. In those cases, the
bus->free_on_exit field is set to true.

However, inside __regmap_init(), buf is not freed on any error path.
This could lead to a memory leak of regmap_bus when __regmap_init()
fails. Fix that by freeing bus on error path when free_on_exit is set.

Fixes: ea030ca68819 ("regmap-i2c: Set regmap max raw r/w from quirks")
Signed-off-by: Abdun Nihaal <abdun.nihaal@gmail.com>
Link: https://patch.msgid.link/20250626172823.18725-1-abdun.nihaal@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/base/regmap/regmap.c