summaryrefslogtreecommitdiff
path: root/drivers/base
diff options
context:
space:
mode:
authorAbdun Nihaal <abdun.nihaal@gmail.com>2025-06-26 22:58:21 +0530
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-08-15 12:04:46 +0200
commitf6a7ab60b636970ed3689f720a34c70a3f6126a2 (patch)
tree413f8ead3238e792e6d9a9999fd78ce0903e69e3 /drivers/base
parent816227506ab6a08f3b7b2e6467e7f0ba626f3653 (diff)
downloadlinux-f6a7ab60b636970ed3689f720a34c70a3f6126a2.tar.gz
linux-f6a7ab60b636970ed3689f720a34c70a3f6126a2.tar.bz2
linux-f6a7ab60b636970ed3689f720a34c70a3f6126a2.zip
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>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/regmap/regmap.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index f0e314abcafc..168532931c86 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -1266,6 +1266,8 @@ err_name:
err_map:
kfree(map);
err:
+ if (bus && bus->free_on_exit)
+ kfree(bus);
return ERR_PTR(ret);
}
EXPORT_SYMBOL_GPL(__regmap_init);