diff options
author | Ulf Hansson <ulf.hansson@linaro.org> | 2025-07-01 13:47:06 +0200 |
---|---|---|
committer | Ulf Hansson <ulf.hansson@linaro.org> | 2025-07-09 13:28:44 +0200 |
commit | 60fe1ca5bc6ca1971c23e26078e33366de84d53e (patch) | |
tree | 12b76e8aeccfeb4917f6aa36c5a50e14c9ec8e3f | |
parent | b27e9842b89a35fa233f9ca6f7072bd63952accc (diff) |
pmdomain: core: Prevent registering devices before the bus
We must not register a consumer device to the genpd bus, before registering
the bus itself. Even if this doesn't seem to be an issue, let's add a
simple check to make sure we really avoid this from happening.
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Link: https://lore.kernel.org/r/20250701114733.636510-5-ulf.hansson@linaro.org
-rw-r--r-- | drivers/pmdomain/core.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c index 9a66b728fbbf..93d71164fc56 100644 --- a/drivers/pmdomain/core.c +++ b/drivers/pmdomain/core.c @@ -2491,6 +2491,8 @@ struct of_genpd_provider { static LIST_HEAD(of_genpd_providers); /* Mutex to protect the list above. */ static DEFINE_MUTEX(of_genpd_mutex); +/* Used to prevent registering devices before the bus. */ +static bool genpd_bus_registered; /** * genpd_xlate_simple() - Xlate function for direct node-domain mapping @@ -3179,6 +3181,9 @@ struct device *genpd_dev_pm_attach_by_id(struct device *dev, if (num_domains < 0 || index >= num_domains) return NULL; + if (!genpd_bus_registered) + return ERR_PTR(-ENODEV); + /* Allocate and register device on the genpd bus. */ virt_dev = kzalloc(sizeof(*virt_dev), GFP_KERNEL); if (!virt_dev) @@ -3357,7 +3362,14 @@ EXPORT_SYMBOL_GPL(of_genpd_parse_idle_states); static int __init genpd_bus_init(void) { - return bus_register(&genpd_bus_type); + int ret; + + ret = bus_register(&genpd_bus_type); + if (ret) + return ret; + + genpd_bus_registered = true; + return 0; } core_initcall(genpd_bus_init); |