]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
pmdomain: core: Fix error checking in genpd_dev_pm_attach_by_id()
authorDan Carpenter <dan.carpenter@linaro.org>
Thu, 8 May 2025 06:29:23 +0000 (09:29 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 27 Jun 2025 10:05:18 +0000 (11:05 +0100)
commitef0c767a559b827b250951a8802d9c4d94cf4ff7
treece0742f496b847faee160ac0f6f009d060e1f68e
parent432a171d60056489270c462e651e6c3a13f855b1
pmdomain: core: Fix error checking in genpd_dev_pm_attach_by_id()

[ Upstream commit 0f5757667ec0aaf2456c3b76fcf0c6c3ea3591fe ]

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: Sasha Levin <sashal@kernel.org>
drivers/base/power/domain.c