Skip to content

Commit c871c19

Browse files
nifeybroonie
authored andcommitted
regmap: fix potential memory leak of regmap_bus
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: ea030ca ("regmap-i2c: Set regmap max raw r/w from quirks") Signed-off-by: Abdun Nihaal <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent d0b3b7b commit c871c19

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/base/regmap/regmap.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,8 @@ struct regmap *__regmap_init(struct device *dev,
11731173
err_map:
11741174
kfree(map);
11751175
err:
1176+
if (bus && bus->free_on_exit)
1177+
kfree(bus);
11761178
return ERR_PTR(ret);
11771179
}
11781180
EXPORT_SYMBOL_GPL(__regmap_init);

0 commit comments

Comments
 (0)