Skip to content

Commit e78908c

Browse files
Dan Carpentergregkh
authored andcommitted
pmdomain: core: Fix error checking in genpd_dev_pm_attach_by_id()
commit 0f57576 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: 3ccf3f0 ("PM / Domains: Enable genpd_dev_pm_attach_by_id|name() for single PM domain") Signed-off-by: Dan Carpenter <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ulf Hansson <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 0ae82a7 commit e78908c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/pmdomain/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3043,7 +3043,7 @@ struct device *genpd_dev_pm_attach_by_id(struct device *dev,
30433043
/* Verify that the index is within a valid range. */
30443044
num_domains = of_count_phandle_with_args(dev->of_node, "power-domains",
30453045
"#power-domain-cells");
3046-
if (index >= num_domains)
3046+
if (num_domains < 0 || index >= num_domains)
30473047
return NULL;
30483048

30493049
/* Allocate and register device on the genpd bus. */

0 commit comments

Comments
 (0)