Skip to content

Commit 0159ec6

Browse files
jonhunterrafaeljw
authored andcommitted
PM / Domains: Verify the PM domain is present when adding a provider
When a PM domain provider is added, there is currently no way to tell if any PM domains associated with the provider are present. Naturally, the PM domain provider should not be registered if the PM domains have not been added. Nonetheless, verify that the PM domain(s) associated with a provider are present when registering the PM domain provider. This change adds a dependency on the function pm_genpd_present() when CONFIG_PM_GENERIC_DOMAINS_OF is enabled and so ensure this function is available when CONFIG_PM_GENERIC_DOMAINS_OF selected. Signed-off-by: Jon Hunter <[email protected]> Acked-by: Ulf Hansson <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 892ebdc commit 0159ec6

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

drivers/base/power/domain.c

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ static int __init genpd_poweroff_unused(void)
586586
}
587587
late_initcall(genpd_poweroff_unused);
588588

589-
#ifdef CONFIG_PM_SLEEP
589+
#if defined(CONFIG_PM_SLEEP) || defined(CONFIG_PM_GENERIC_DOMAINS_OF)
590590

591591
/**
592592
* pm_genpd_present - Check if the given PM domain has been initialized.
@@ -606,6 +606,10 @@ static bool pm_genpd_present(const struct generic_pm_domain *genpd)
606606
return false;
607607
}
608608

609+
#endif
610+
611+
#ifdef CONFIG_PM_SLEEP
612+
609613
static bool genpd_dev_active_wakeup(struct generic_pm_domain *genpd,
610614
struct device *dev)
611615
{
@@ -1453,7 +1457,19 @@ static int genpd_add_provider(struct device_node *np, genpd_xlate_t xlate,
14531457
int of_genpd_add_provider_simple(struct device_node *np,
14541458
struct generic_pm_domain *genpd)
14551459
{
1456-
return genpd_add_provider(np, genpd_xlate_simple, genpd);
1460+
int ret = -EINVAL;
1461+
1462+
if (!np || !genpd)
1463+
return -EINVAL;
1464+
1465+
mutex_lock(&gpd_list_lock);
1466+
1467+
if (pm_genpd_present(genpd))
1468+
ret = genpd_add_provider(np, genpd_xlate_simple, genpd);
1469+
1470+
mutex_unlock(&gpd_list_lock);
1471+
1472+
return ret;
14571473
}
14581474
EXPORT_SYMBOL_GPL(of_genpd_add_provider_simple);
14591475

@@ -1465,7 +1481,26 @@ EXPORT_SYMBOL_GPL(of_genpd_add_provider_simple);
14651481
int of_genpd_add_provider_onecell(struct device_node *np,
14661482
struct genpd_onecell_data *data)
14671483
{
1468-
return genpd_add_provider(np, genpd_xlate_onecell, data);
1484+
unsigned int i;
1485+
int ret;
1486+
1487+
if (!np || !data)
1488+
return -EINVAL;
1489+
1490+
mutex_lock(&gpd_list_lock);
1491+
1492+
for (i = 0; i < data->num_domains; i++) {
1493+
if (!pm_genpd_present(data->domains[i])) {
1494+
mutex_unlock(&gpd_list_lock);
1495+
return -EINVAL;
1496+
}
1497+
}
1498+
1499+
ret = genpd_add_provider(np, genpd_xlate_onecell, data);
1500+
1501+
mutex_unlock(&gpd_list_lock);
1502+
1503+
return ret;
14691504
}
14701505
EXPORT_SYMBOL_GPL(of_genpd_add_provider_onecell);
14711506

0 commit comments

Comments
 (0)