diff options
author | Dan Carpenter <dan.carpenter@linaro.org> | 2025-05-08 09:29:23 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2025-05-29 11:03:21 +0200 |
commit | e78908caf17cbddbceeac35bb54b1ada9610c4e6 (patch) | |
tree | d71aff6e9a25fab26edb7346ecfc5e910bde4b7e | |
parent | 0ae82a7abff8f92f96233f63aaf62ded78095fb8 (diff) |
pmdomain: core: Fix error checking in genpd_dev_pm_attach_by_id()
commit 0f5757667ec0aaf2456c3b76fcf0c6c3ea3591fe upstream.
The error checking for of_count_phandle_with_args() does not handle
negative error codes correctly. The problem is that "index" is a u32 so
in the condition "if (index >= num_domains)" negative error codes stored
in "num_domains" are type promoted to very high positive values and
"index" is always going to be valid.
Test for negative error codes first and then test if "index" is valid.
Fixes: 3ccf3f0cd197 ("PM / Domains: Enable genpd_dev_pm_attach_by_id|name() for single PM domain")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/aBxPQ8AI8N5v-7rL@stanley.mountain
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/pmdomain/core.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c index 88819659df83..05913e9fe082 100644 --- a/drivers/pmdomain/core.c +++ b/drivers/pmdomain/core.c @@ -3043,7 +3043,7 @@ struct device *genpd_dev_pm_attach_by_id(struct device *dev, /* Verify that the index is within a valid range. */ num_domains = of_count_phandle_with_args(dev->of_node, "power-domains", "#power-domain-cells"); - if (index >= num_domains) + if (num_domains < 0 || index >= num_domains) return NULL; /* Allocate and register device on the genpd bus. */ |