power: supply: core: fix memory leak in HWMON error path

commit 1d7a7128a2e9e1f137c99b0a44e94d70a77343e3 upstream.

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: [email protected]
Fixes: e67d4dfc9f ("power: supply: Add HWMON compatibility layer")
Signed-off-by: Qiushi Wu <[email protected]>
Signed-off-by: Sebastian Reichel <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
This commit is contained in:
Qiushi Wu 2020-05-02 18:33:38 -05:00 • committed by Greg Kroah-Hartman
commit 8b28e5c35d

View file

@ -304,7 +304,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;