* [PATCH] power: supply: fix memory leaks (v2)
@ 2020-05-02 23:33 wu000273
2020-05-03 0:21 ` Sebastian Reichel
0 siblings, 1 reply; 2+ messages in thread
From: wu000273 @ 2020-05-02 23:33 UTC (permalink / raw)
To: sre; +Cc: linux-pm, linux-kernel, kjlu, wu000273
From: Qiushi Wu <wu000273@umn.edu>
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.
v2:
- Prevent introducing double-free.
- Added fixes tag
Fixes: e67d4dfc9ff19 ("power: supply: Add HWMON compatibility layer")
Signed-off-by: Qiushi Wu <wu000273@umn.edu>
---
drivers/power/supply/power_supply_hwmon.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/power/supply/power_supply_hwmon.c b/drivers/power/supply/power_supply_hwmon.c
index 75cf861ba492..7c8296ea0c34 100644
--- a/drivers/power/supply/power_supply_hwmon.c
+++ b/drivers/power/supply/power_supply_hwmon.c
@@ -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;
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] power: supply: fix memory leaks (v2)
2020-05-02 23:33 [PATCH] power: supply: fix memory leaks (v2) wu000273
@ 2020-05-03 0:21 ` Sebastian Reichel
0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Reichel @ 2020-05-03 0:21 UTC (permalink / raw)
To: wu000273; +Cc: linux-pm, linux-kernel, kjlu
[-- Attachment #1: Type: text/plain, Size: 1490 bytes --]
Hi,
On Sat, May 02, 2020 at 06:33:38PM -0500, wu000273@umn.edu wrote:
> From: Qiushi Wu <wu000273@umn.edu>
>
> 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.
>
> v2:
> - Prevent introducing double-free.
> - Added fixes tag
>
> Fixes: e67d4dfc9ff19 ("power: supply: Add HWMON compatibility layer")
> Signed-off-by: Qiushi Wu <wu000273@umn.edu>
> ---
Thanks, queued to power-supply's for-next branch.
Notes for next time:
* I fixed up the subject, please read how to properly send a v2
* I removed the changelog, it should be below the ---
-- Sebastian
> drivers/power/supply/power_supply_hwmon.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/power/supply/power_supply_hwmon.c b/drivers/power/supply/power_supply_hwmon.c
> index 75cf861ba492..7c8296ea0c34 100644
> --- a/drivers/power/supply/power_supply_hwmon.c
> +++ b/drivers/power/supply/power_supply_hwmon.c
> @@ -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;
> --
> 2.17.1
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-05-03 0:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-02 23:33 [PATCH] power: supply: fix memory leaks (v2) wu000273
2020-05-03 0:21 ` Sebastian Reichel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).