Commit 77385688 authored by Ulf Hansson's avatar Ulf Hansson

PM: domains: Fix alloc/free in dev_pm_domain_attach|detach_list()

The dev_pm_domain_attach|detach_list() functions are not resource managed,
hence they should not use devm_* helpers to manage allocation/freeing of
data. Let's fix this by converting to the traditional alloc/free functions.

Fixes: 161e16a5 ("PM: domains: Add helper functions to attach/detach multiple PM domains")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
Acked-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Link: https://lore.kernel.org/r/20241002122232.194245-3-ulf.hansson@linaro.org
parent fa36b4bc
...@@ -195,6 +195,7 @@ int dev_pm_domain_attach_list(struct device *dev, ...@@ -195,6 +195,7 @@ int dev_pm_domain_attach_list(struct device *dev,
struct device *pd_dev = NULL; struct device *pd_dev = NULL;
int ret, i, num_pds = 0; int ret, i, num_pds = 0;
bool by_id = true; bool by_id = true;
size_t size;
u32 pd_flags = data ? data->pd_flags : 0; u32 pd_flags = data ? data->pd_flags : 0;
u32 link_flags = pd_flags & PD_FLAG_NO_DEV_LINK ? 0 : u32 link_flags = pd_flags & PD_FLAG_NO_DEV_LINK ? 0 :
DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME; DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME;
...@@ -217,19 +218,17 @@ int dev_pm_domain_attach_list(struct device *dev, ...@@ -217,19 +218,17 @@ int dev_pm_domain_attach_list(struct device *dev,
if (num_pds <= 0) if (num_pds <= 0)
return 0; return 0;
pds = devm_kzalloc(dev, sizeof(*pds), GFP_KERNEL); pds = kzalloc(sizeof(*pds), GFP_KERNEL);
if (!pds) if (!pds)
return -ENOMEM; return -ENOMEM;
pds->pd_devs = devm_kcalloc(dev, num_pds, sizeof(*pds->pd_devs), size = sizeof(*pds->pd_devs) + sizeof(*pds->pd_links);
GFP_KERNEL); pds->pd_devs = kcalloc(num_pds, size, GFP_KERNEL);
if (!pds->pd_devs) if (!pds->pd_devs) {
return -ENOMEM; ret = -ENOMEM;
goto free_pds;
pds->pd_links = devm_kcalloc(dev, num_pds, sizeof(*pds->pd_links), }
GFP_KERNEL); pds->pd_links = (void *)(pds->pd_devs + num_pds);
if (!pds->pd_links)
return -ENOMEM;
if (link_flags && pd_flags & PD_FLAG_DEV_LINK_ON) if (link_flags && pd_flags & PD_FLAG_DEV_LINK_ON)
link_flags |= DL_FLAG_RPM_ACTIVE; link_flags |= DL_FLAG_RPM_ACTIVE;
...@@ -272,6 +271,9 @@ int dev_pm_domain_attach_list(struct device *dev, ...@@ -272,6 +271,9 @@ int dev_pm_domain_attach_list(struct device *dev,
device_link_del(pds->pd_links[i]); device_link_del(pds->pd_links[i]);
dev_pm_domain_detach(pds->pd_devs[i], true); dev_pm_domain_detach(pds->pd_devs[i], true);
} }
kfree(pds->pd_devs);
free_pds:
kfree(pds);
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(dev_pm_domain_attach_list); EXPORT_SYMBOL_GPL(dev_pm_domain_attach_list);
...@@ -363,6 +365,9 @@ void dev_pm_domain_detach_list(struct dev_pm_domain_list *list) ...@@ -363,6 +365,9 @@ void dev_pm_domain_detach_list(struct dev_pm_domain_list *list)
device_link_del(list->pd_links[i]); device_link_del(list->pd_links[i]);
dev_pm_domain_detach(list->pd_devs[i], true); dev_pm_domain_detach(list->pd_devs[i], true);
} }
kfree(list->pd_devs);
kfree(list);
} }
EXPORT_SYMBOL_GPL(dev_pm_domain_detach_list); EXPORT_SYMBOL_GPL(dev_pm_domain_detach_list);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment