powercap: fix memory leak in intel_rapl_common
PATCH 1/1 powercap: fix memory leak in intel_rapl_common
The err_cleanup path in rapl_package_register_powercap() function doesn't free rp->domains before returning when child domain registration fails. Also, there is a missing the cleanup for the parent package power zone which was successfully registered earlier.
When registration of child domains fails, now the previously registered package domain (parent zone) is being unregistered. This makes both parent and child powercap zones are properly unregistered before returning the error.
Also, fix the rp->power_zone dangling pointer issue by setting it to NULL.
--- drivers/powercap/intel_rapl_common.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/powercap/intel_rapl_common.c +7 -0
@@ -1406,6 +1406,13 @@ static int rapl_package_register_powercap(struct rapl_package *rp) &rd->power_zone); } +/* Also unregister the package domain if it was registered */ +if (rp->power_zone) { +powercap_unregister_zone (rp->priv->control_type, + rp->power_zone); + rp->power_zone =NULL ; + } +return ret; }
Signature · 1 line
2.43.0
Rafael J. Wysocki
maintainerQuoted 8 lines · Sumeet Pawnikar
The
err_cleanuppath inrapl_package_register_powercap()function doesn't freerp->domainsbefore returning when child domain registration fails. Also, there is a missing the cleanup for the parent package power zone which was successfully registered earlier.When registration of child domains fails, now the previously registered package domain (parent zone) is being unregistered.
I'm not sure if this is desirable.
The package domain may be still functional without children AFAICS.
Quoted 29 lines
This makes both parent and child powercap zones are properly unregistered before returning the error.
Also, fix therp->power_zonedangling pointer issue by setting it to NULL.Signed-off-by Sumeet Pawnikar <[email protected]>--- drivers/powercap/intel_rapl_common.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/powercap/intel_rapl_common.c +7
-1@@ -1406,6 +1406,13 @@ static int rapl_package_register_powercap(struct rapl_package *rp) &rd->power_zone); } +/* Also unregister the package domain if it was registered */ +if (rp->power_zone) { +powercap_unregister_zone (rp->priv->control_type, + rp->power_zone); + rp->power_zone =NULL ; + } +return ret; } --