From: Qiushi Wu Date: Sat, 2 May 2020 23:33:38 +0000 (-0500) Subject: power: supply: core: fix memory leak in HWMON error path X-Git-Tag: v5.8-rc1~70^2~64 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1d7a7128a2e9e1f137c99b0a44e94d70a77343e3;p=thirdparty%2Flinux.git power: supply: core: fix memory leak in HWMON error path In function power_supply_add_hwmon_sysfs(), psyhw->props is allocated by bitmap_zalloc(). But this pointer is not deallocated when devm_add_action fail, which lead to a memory leak bug. To fix this, we replace devm_add_action with devm_add_action_or_reset. Cc: stable@kernel.org Fixes: e67d4dfc9ff19 ("power: supply: Add HWMON compatibility layer") Signed-off-by: Qiushi Wu Signed-off-by: Sebastian Reichel --- diff --git a/drivers/power/supply/power_supply_hwmon.c b/drivers/power/supply/power_supply_hwmon.c index f5d538485aaad..7fe4b6b6ddc89 100644 --- a/drivers/power/supply/power_supply_hwmon.c +++ b/drivers/power/supply/power_supply_hwmon.c @@ -358,7 +358,7 @@ int power_supply_add_hwmon_sysfs(struct power_supply *psy) goto error; } - ret = devm_add_action(dev, power_supply_hwmon_bitmap_free, + ret = devm_add_action_or_reset(dev, power_supply_hwmon_bitmap_free, psyhw->props); if (ret) goto error;