Skip to content

Commit 7738568

Browse files
committed
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: 161e16a ("PM: domains: Add helper functions to attach/detach multiple PM domains") Cc: [email protected] Signed-off-by: Ulf Hansson <[email protected]> Acked-by: Viresh Kumar <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent fa36b4b commit 7738568

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

drivers/base/power/common.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ int dev_pm_domain_attach_list(struct device *dev,
195195
struct device *pd_dev = NULL;
196196
int ret, i, num_pds = 0;
197197
bool by_id = true;
198+
size_t size;
198199
u32 pd_flags = data ? data->pd_flags : 0;
199200
u32 link_flags = pd_flags & PD_FLAG_NO_DEV_LINK ? 0 :
200201
DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME;
@@ -217,19 +218,17 @@ int dev_pm_domain_attach_list(struct device *dev,
217218
if (num_pds <= 0)
218219
return 0;
219220

220-
pds = devm_kzalloc(dev, sizeof(*pds), GFP_KERNEL);
221+
pds = kzalloc(sizeof(*pds), GFP_KERNEL);
221222
if (!pds)
222223
return -ENOMEM;
223224

224-
pds->pd_devs = devm_kcalloc(dev, num_pds, sizeof(*pds->pd_devs),
225-
GFP_KERNEL);
226-
if (!pds->pd_devs)
227-
return -ENOMEM;
228-
229-
pds->pd_links = devm_kcalloc(dev, num_pds, sizeof(*pds->pd_links),
230-
GFP_KERNEL);
231-
if (!pds->pd_links)
232-
return -ENOMEM;
225+
size = sizeof(*pds->pd_devs) + sizeof(*pds->pd_links);
226+
pds->pd_devs = kcalloc(num_pds, size, GFP_KERNEL);
227+
if (!pds->pd_devs) {
228+
ret = -ENOMEM;
229+
goto free_pds;
230+
}
231+
pds->pd_links = (void *)(pds->pd_devs + num_pds);
233232

234233
if (link_flags && pd_flags & PD_FLAG_DEV_LINK_ON)
235234
link_flags |= DL_FLAG_RPM_ACTIVE;
@@ -272,6 +271,9 @@ int dev_pm_domain_attach_list(struct device *dev,
272271
device_link_del(pds->pd_links[i]);
273272
dev_pm_domain_detach(pds->pd_devs[i], true);
274273
}
274+
kfree(pds->pd_devs);
275+
free_pds:
276+
kfree(pds);
275277
return ret;
276278
}
277279
EXPORT_SYMBOL_GPL(dev_pm_domain_attach_list);
@@ -363,6 +365,9 @@ void dev_pm_domain_detach_list(struct dev_pm_domain_list *list)
363365
device_link_del(list->pd_links[i]);
364366
dev_pm_domain_detach(list->pd_devs[i], true);
365367
}
368+
369+
kfree(list->pd_devs);
370+
kfree(list);
366371
}
367372
EXPORT_SYMBOL_GPL(dev_pm_domain_detach_list);
368373

0 commit comments

Comments
 (0)