Skip to content

Commit b6cee65

Browse files
Dikshita Agarwalstorulf
authored andcommitted
PM: domains: add device managed version of dev_pm_domain_attach|detach_list()
Add the devres-enabled version of dev_pm_domain_attach|detach_list. If client drivers use devm_pm_domain_attach_list() to attach the PM domains, devm_pm_domain_detach_list() will be invoked implicitly during remove phase. Signed-off-by: Dikshita Agarwal <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ulf Hansson <[email protected]>
1 parent cfee1b5 commit b6cee65

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

drivers/base/power/common.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,51 @@ int dev_pm_domain_attach_list(struct device *dev,
276276
}
277277
EXPORT_SYMBOL_GPL(dev_pm_domain_attach_list);
278278

279+
/**
280+
* devm_pm_domain_detach_list - devres-enabled version of dev_pm_domain_detach_list.
281+
* @_list: The list of PM domains to detach.
282+
*
283+
* This function reverse the actions from devm_pm_domain_attach_list().
284+
* it will be invoked during the remove phase from drivers implicitly if driver
285+
* uses devm_pm_domain_attach_list() to attach the PM domains.
286+
*/
287+
static void devm_pm_domain_detach_list(void *_list)
288+
{
289+
struct dev_pm_domain_list *list = _list;
290+
291+
dev_pm_domain_detach_list(list);
292+
}
293+
294+
/**
295+
* devm_pm_domain_attach_list - devres-enabled version of dev_pm_domain_attach_list
296+
* @dev: The device used to lookup the PM domains for.
297+
* @data: The data used for attaching to the PM domains.
298+
* @list: An out-parameter with an allocated list of attached PM domains.
299+
*
300+
* NOTE: this will also handle calling devm_pm_domain_detach_list() for
301+
* you during remove phase.
302+
*
303+
* Returns the number of attached PM domains or a negative error code in case of
304+
* a failure.
305+
*/
306+
int devm_pm_domain_attach_list(struct device *dev,
307+
const struct dev_pm_domain_attach_data *data,
308+
struct dev_pm_domain_list **list)
309+
{
310+
int ret, num_pds;
311+
312+
num_pds = dev_pm_domain_attach_list(dev, data, list);
313+
if (num_pds <= 0)
314+
return num_pds;
315+
316+
ret = devm_add_action_or_reset(dev, devm_pm_domain_detach_list, *list);
317+
if (ret)
318+
return ret;
319+
320+
return num_pds;
321+
}
322+
EXPORT_SYMBOL_GPL(devm_pm_domain_attach_list);
323+
279324
/**
280325
* dev_pm_domain_detach - Detach a device from its PM domain.
281326
* @dev: Device to detach.

include/linux/pm_domain.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,9 @@ struct device *dev_pm_domain_attach_by_name(struct device *dev,
476476
int dev_pm_domain_attach_list(struct device *dev,
477477
const struct dev_pm_domain_attach_data *data,
478478
struct dev_pm_domain_list **list);
479+
int devm_pm_domain_attach_list(struct device *dev,
480+
const struct dev_pm_domain_attach_data *data,
481+
struct dev_pm_domain_list **list);
479482
void dev_pm_domain_detach(struct device *dev, bool power_off);
480483
void dev_pm_domain_detach_list(struct dev_pm_domain_list *list);
481484
int dev_pm_domain_start(struct device *dev);
@@ -502,6 +505,14 @@ static inline int dev_pm_domain_attach_list(struct device *dev,
502505
{
503506
return 0;
504507
}
508+
509+
static inline int devm_pm_domain_attach_list(struct device *dev,
510+
const struct dev_pm_domain_attach_data *data,
511+
struct dev_pm_domain_list **list)
512+
{
513+
return 0;
514+
}
515+
505516
static inline void dev_pm_domain_detach(struct device *dev, bool power_off) {}
506517
static inline void dev_pm_domain_detach_list(struct dev_pm_domain_list *list) {}
507518
static inline int dev_pm_domain_start(struct device *dev)

0 commit comments

Comments
 (0)