diff options
author | Daniel Lezcano <daniel.lezcano@linaro.org> | 2022-01-31 00:02:06 +0300 |
---|---|---|
committer | Daniel Lezcano <daniel.lezcano@linaro.org> | 2022-02-23 21:45:40 +0300 |
commit | c404c64d64bc31bebe8a2015103671f7cd282731 (patch) | |
tree | 905535b2150200d7b5b2e361ea035caf6de52e87 /drivers/powercap | |
parent | 690de0b4013f6f35bc9fced12746b9f396c471ae (diff) | |
download | linux-c404c64d64bc31bebe8a2015103671f7cd282731.tar.xz |
powercap/dtpm: Destroy hierarchy function
The hierarchy creation function exits but without a destroy hierarchy
function. Due to that, the modules creating the hierarchy can not be
unloaded properly because they don't have an exit callback.
Provide the dtpm_destroy_hierarchy() function to remove the previously
created hierarchy.
The function relies on all the release mechanisms implemented by the
underlying powercap framework.
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Link: https://lore.kernel.org/r/20220130210210.549877-4-daniel.lezcano@linaro.org
Diffstat (limited to 'drivers/powercap')
-rw-r--r-- | drivers/powercap/dtpm.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/drivers/powercap/dtpm.c b/drivers/powercap/dtpm.c index 7bddd25a6767..d9d74f981118 100644 --- a/drivers/powercap/dtpm.c +++ b/drivers/powercap/dtpm.c @@ -617,3 +617,46 @@ out_unlock: return ret; } EXPORT_SYMBOL_GPL(dtpm_create_hierarchy); + +static void __dtpm_destroy_hierarchy(struct dtpm *dtpm) +{ + struct dtpm *child, *aux; + + list_for_each_entry_safe(child, aux, &dtpm->children, sibling) + __dtpm_destroy_hierarchy(child); + + /* + * At this point, we know all children were removed from the + * recursive call before + */ + dtpm_unregister(dtpm); +} + +void dtpm_destroy_hierarchy(void) +{ + int i; + + mutex_lock(&dtpm_lock); + + if (!pct) + goto out_unlock; + + __dtpm_destroy_hierarchy(root); + + + for (i = 0; i < ARRAY_SIZE(dtpm_subsys); i++) { + + if (!dtpm_subsys[i]->exit) + continue; + + dtpm_subsys[i]->exit(); + } + + powercap_unregister_control_type(pct); + + pct = NULL; + +out_unlock: + mutex_unlock(&dtpm_lock); +} +EXPORT_SYMBOL_GPL(dtpm_destroy_hierarchy); |