]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
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)
committerMark Brown <broonie@kernel.org>
Sun, 29 Jun 2025 21:10:36 +0000 (22:10 +0100)
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>
drivers/base/regmap/regmap.c

index f2843f814675151354a4deb3248b2cf1443b82af..1f3f782a04ba23a96e2b8af40cdc35b20a7bfee4 100644 (file)
@@ -1173,6 +1173,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);