Skip to contentSkip to conversation

pmdomain: rockchip: fix domain check in rockchip_pm_add_one_domain()

PATCH In review Sergey Shtylyov 3 participants 11 messages Sep 20 – Sep 25

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pmdomain: rockchip: fix domain check in rockchip_pm_add_one_domain()

In rockchip_pm_add_one_domain(), there's the check (most probably for the case where the "reg" prop has an unexpected value?) which doesn't make much sense as the variable pd_info will be NULL iff pmu->info-> domain_info is NULL and the variable id is 0. What does make sense there is checking pd_info->pwr_mask and pd_info->req_mask which (as seems to follow from the code) can't both be 0 for a valid domain...

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

Fixes 7c696693a4f5 ("soc: rockchip: power-domain: Add power domain driver")

---
This patch is against the fixes branch of Ulf Hansson's linux-pm.git repo.

 drivers/pmdomain/rockchip/pm-domains.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pmdomain/rockchip/pm-domains.c +1 -1
index ba66ae719428..69792e2b215b 100644
@@ -809,7 +809,7 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu,
 		return 0;
 
 	pd_info = &pmu->info->domain_info[id];
-	if (!pd_info) {
+	if (!pd_info->pwr_mask && !pd_info->req_mask) {
 		dev_err(pmu->dev, "%pOFn: undefined domain id %d\n",
 			node, id);
 		return -EINVAL;
Signature · 6 lines
2.55.0

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
#1 lore raw

Hi Sergey,

Quoted 2 lines · Sergey Shtylyov

In rockchip_pm_add_one_domain(), there's the check (most probably for the case where the "reg" prop has an unexpected value?) which doesn't

Agreed that check indeed makes little sense. But "most probably for the
case where the reg prop has an unexpected value" does not hold: an out-of-range reg value is already rejected by the "id >= pmu->info-

Quoted 1 line

num_domains" check above, and num_domains equals

ARRAY_SIZE(domain_info) for every SoC, so there are no holes in the
table that the new check could catch with the current data. AFAICT, this patch does not change any runtime behaviour; it only turns dead code into a defensive check on the match-data tables.

Quoted 5 lines

make much sense as the variable pd_info will be NULL iff pmu->info-> domain_info is NULL and the variable id is 0. What does make sense there is checking pd_info->pwr_mask and pd_info->req_mask which (as seems to follow from the code) can't both be 0 for a valid domain...

That means there is no bug being fixed here, should we drop the fixes tag?

Quoted 17 lines

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

Fixes 7c696693a4f5 ("soc: rockchip: power-domain: Add power domain driver")

---
This patch is against the fixes branch of Ulf Hansson's linux-pm.git repo.

  drivers/pmdomain/rockchip/pm-domains.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pmdomain/rockchip/pm-domains.c +0 -0
index ba66ae719428..69792e2b215b 100644

drivers/pmdomain/rockchip/pm-domains.c static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, · line 815

Quoted 8 lines
drivers/pmdomain/rockchip/pm-domains.c +1 -1
@@ -809,7 +809,7 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu,
  		return 0;
 
  	pd_info = &pmu->info->domain_info[id];
-	if (!pd_info) {
+	if (!pd_info->pwr_mask && !pd_info->req_mask) {
  		dev_err(pmu->dev, "%pOFn: undefined domain id %d\n",
  			node, id);
  		return -EINVAL;

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

#2 lore raw

On 9/21/26 9:36 AM, Shawn Lin wrote:

[...]

Quoted 5 lines
Quoted 2 lines

In rockchip_pm_add_one_domain(), there's the check (most probably for the case where the "reg" prop has an unexpected value?) which doesn't

Agreed that check indeed makes little sense. But "most probably for the case where the reg prop has an unexpected value" does not hold: an

I tried to guess what the check in question was actually intended for
(despite making a little sense as it is now)...

Quoted 2 lines

out-of-range reg value is already rejected by the "id >= pmu->info-

Quoted 1 line

num_domains" check above, and num_domains equals

I noticed. :-)

Quoted 2 lines

ARRAY_SIZE(domain_info) for every SoC, so there are no holes in the table that the new check could catch with the current data. AFAICT, this

Oh, there are holes! :-)
If you look at (and behind) the indexed initializers of *_pm_domains[],
you'll see that the indexes don't always start at 0, and so the arrays are actually sparse...

Quoted 2 lines

patch does not change any runtime behaviour; it only turns dead code into a defensive check on the match-data tables.

I hope you see now that this defensive check makes a bit more sense...

Quoted 6 lines
Quoted 4 lines

make much sense as the variable pd_info will be NULL iff pmu->info-> domain_info is NULL and the variable id is 0.  What does make sense there is checking pd_info->pwr_mask and pd_info->req_mask which (as seems to follow from the code) can't both be 0 for a valid domain...

That means there is no bug being fixed here, should we drop the fixes tag?

I'd like to keep it (but that's up to the maintainers, of course)...

Quoted 5 lines
Quoted 5 lines

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

Fixes 7c696693a4f5 ("soc: rockchip: power-domain: Add power domain driver")

[...]

MBR, Sergey

Reviewed-by
#3 lore raw
Quoted 18 lines · Sergey Shtylyov

On 9/21/26 9:36 AM, Shawn Lin wrote:

[...]

Quoted 5 lines
Quoted 2 lines

In rockchip_pm_add_one_domain(), there's the check (most probably for the case where the "reg" prop has an unexpected value?) which doesn't

Agreed that check indeed makes little sense. But "most probably for the case where the reg prop has an unexpected value" does not hold: an

I tried to guess what the check in question was actually intended for
(despite making a little sense as it is now)...

Quoted 2 lines

out-of-range reg value is already rejected by the "id >= pmu->info-

Quoted 1 line

num_domains" check above, and num_domains equals

    I noticed. :-)
Quoted 7 lines
Quoted 2 lines

ARRAY_SIZE(domain_info) for every SoC, so there are no holes in the table that the new check could catch with the current data. AFAICT, this

Oh, there are holes! :-)
If you look at (and behind) the indexed initializers of *_pm_domains[],
you'll see that the indexes don't always start at 0, and so the arrays are actually sparse...

Looked more closely by each one, you're right.

Quoted 6 lines
Quoted 3 lines

patch does not change any runtime behaviour; it only turns dead code into a defensive check on the match-data tables.

I hope you see now that this defensive check makes a bit more sense...

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

make much sense as the variable pd_info will be NULL iff pmu->info-> domain_info is NULL and the variable id is 0.  What does make sense there is checking pd_info->pwr_mask and pd_info->req_mask which (as seems to follow from the code) can't both be 0 for a valid domain...

That means there is no bug being fixed here, should we drop the fixes tag?

I'd like to keep it (but that's up to the maintainers, of course)...

Sure, it's Ulf's call. Anyway, feel free to add

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Fixes 7c696693a4f5 ("soc: rockchip: power-domain: Add power domain driver")

[...]

MBR, Sergey

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

#4 lore raw

On 9/22/26 3:47 AM, Shawn Lin wrote:

[...]

Quoted 17 lines
Quoted 17 lines
Quoted 5 lines
Quoted 2 lines

In rockchip_pm_add_one_domain(), there's the check (most probably for the case where the "reg" prop has an unexpected value?) which doesn't

Agreed that check indeed makes little sense. But "most probably for the case where the reg prop has an unexpected value" does not hold: an

    I tried to guess what the check in question was actually intended for (despite making a little sense as it is now)...

Quoted 2 lines

out-of-range reg value is already rejected by the "id >= pmu->info-

Quoted 1 line

num_domains" check above, and num_domains equals

    I noticed. :-)

Quoted 2 lines

ARRAY_SIZE(domain_info) for every SoC, so there are no holes in the table that the new check could catch with the current data. AFAICT, this

Quoted 6 lines
Quoted 4 lines

    Oh, there are holes! :-)
    If you look at (and behind) the indexed initializers of *_pm_domains[], you'll see that the indexes don't always start at 0, and so the arrays are actually sparse...

Looked more closely by each one, you're right.

Perhaps I just should've been more verbose in the patch description...

Quoted 10 lines
Quoted 10 lines
Quoted 2 lines

patch does not change any runtime behaviour; it only turns dead code into a defensive check on the match-data tables.

    I hope you see now that this defensive check makes a bit more sense...

Quoted 5 lines
Quoted 4 lines

make much sense as the variable pd_info will be NULL iff pmu->info-> domain_info is NULL and the variable id is 0.  What does make sense there is checking pd_info->pwr_mask and pd_info->req_mask which (as seems to follow from the code) can't both be 0 for a valid domain...

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

That means there is no bug being fixed here, should we drop the fixes tag?

    I'd like to keep it (but that's up to the maintainers, of course)...

Sure, it's  Ulf's call. Anyway, feel free to add

Thank you!

[...]

MBR, Sergey

#5 lore raw
In reply to Sergey Shtylyov
Quoted 8 lines · Sergey Shtylyov

In rockchip_pm_add_one_domain(), there's the check (most probably for the case where the "reg" prop has an unexpected value?) which doesn't make much sense as the variable pd_info will be NULL iff pmu->info-> domain_info is NULL and the variable id is 0. What does make sense there is checking pd_info->pwr_mask and pd_info->req_mask which (as seems to follow from the code) can't both be 0 for a valid domain...

Quoted 5 lines

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

Fixes 7c696693a4f5 ("soc: rockchip: power-domain: Add power domain driver")

Applied for next, but without the fixes tag, thanks!

Note, that I am dropping the fixes tag because if there was a real problem, we would require yet another fix on top to get the corresponding domain declaration to be correct. Yet, the patch is useful as is!

Kind regards
Uffe

Quoted 22 lines

---
This patch is against the fixes branch of Ulf Hansson's linux-pm.git repo.

 drivers/pmdomain/rockchip/pm-domains.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pmdomain/rockchip/pm-domains.c +1 -2
index ba66ae719428..69792e2b215b 100644
@@ -809,7 +809,7 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu,
                return 0;
 
        pd_info = &pmu->info->domain_info[id];
-       if (!pd_info) {
+       if (!pd_info->pwr_mask && !pd_info->req_mask) {
                dev_err(pmu->dev, "%pOFn: undefined domain id %d\n",
                        node, id);
                return -EINVAL;
--

2.55.0

#6 lore raw

On 9/23/26 3:14 PM, Ulf Hansson wrote:

[...]

Quoted 13 lines
Quoted 7 lines

In rockchip_pm_add_one_domain(), there's the check (most probably for the case where the "reg" prop has an unexpected value?) which doesn't make much sense as the variable pd_info will be NULL iff pmu->info-> domain_info is NULL and the variable id is 0. What does make sense there is checking pd_info->pwr_mask and pd_info->req_mask which (as seems to follow from the code) can't both be 0 for a valid domain...

Quoted 5 lines

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

Fixes 7c696693a4f5 ("soc: rockchip: power-domain: Add power domain driver")
Quoted 6 lines

Applied for next, but without the fixes tag, thanks!

Note, that I am dropping the fixes tag because if there was a real problem, we would require yet another fix on top to get the corresponding domain declaration to be correct. Yet, the patch is useful as is!

I'm not sure I understand you. The patch should hopefully be
enough to detect the undefined entries (implicitly init'ed with all 0s). What fix for the domain definitions do you have in mind, turning the arrays into lookup tables by adding a domain ID as a field to *struct* rockchip_domain_info?

Quoted 2 lines

Kind regards
Uffe

MBR, Sergey

#7 lore raw
Quoted 25 lines · Sergey Shtylyov

On 9/23/26 3:14 PM, Ulf Hansson wrote:

[...]

Quoted 13 lines
Quoted 7 lines

In rockchip_pm_add_one_domain(), there's the check (most probably for the case where the "reg" prop has an unexpected value?) which doesn't make much sense as the variable pd_info will be NULL iff pmu->info-> domain_info is NULL and the variable id is 0. What does make sense there is checking pd_info->pwr_mask and pd_info->req_mask which (as seems to follow from the code) can't both be 0 for a valid domain...

Quoted 5 lines

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

Fixes 7c696693a4f5 ("soc: rockchip: power-domain: Add power domain driver")
Quoted 6 lines

Applied for next, but without the fixes tag, thanks!

Note, that I am dropping the fixes tag because if there was a real problem, we would require yet another fix on top to get the corresponding domain declaration to be correct. Yet, the patch is useful as is!

Quoted 5 lines

I'm not sure I understand you. The patch should hopefully be
enough to detect the undefined entries (implicitly init'ed with all 0s). What fix for the domain definitions do you have in mind, turning the arrays into lookup tables by adding a domain ID as a field to *struct* rockchip_domain_info?

Apologize if I was vague, but you kind of point out what I just said.

The patch helps us to *detect* incorrect entries. If it turns out we find one, we need to fix that entry.

Kind regards
Uffe

#8 lore raw

On 9/24/26 11:48 AM, Ulf Hansson wrote:

[...]

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

In rockchip_pm_add_one_domain(), there's the check (most probably for the case where the "reg" prop has an unexpected value?) which doesn't make much sense as the variable pd_info will be NULL iff pmu->info-> domain_info is NULL and the variable id is 0. What does make sense there is checking pd_info->pwr_mask and pd_info->req_mask which (as seems to follow from the code) can't both be 0 for a valid domain...

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

Fixes 7c696693a4f5 ("soc: rockchip: power-domain: Add power domain driver")

Applied for next, but without the fixes tag, thanks!

One detail I've just remembered about: if the patch won't be backported to
the stable kernels, it would be easier to just check rockchip_domain_info::name for NULL instead of the {pwr,req}_mask fields checked by the patch; this field seems to always be set for all domains the driver cares about, it just was added in 5.14-rc1 (I think), see this:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=0a69452e03564c5eaf99f729de398cd94ee90851

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Note, that I am dropping the fixes tag because if there was a real problem, we would require yet another fix on top to get the

The problem can (probably) happen iff a device tree has a domain # in
the "reg" property that the driver doesn't care about -- in this case the .{pwr,req}_mask fields (and .name as well) will both be 0 (since IIRC a C compiler should set not explicitly initialized entried to 0). My patch was intended for checking for the domain #s that the driver doesn't care about (and so doesn't init in the *_pm_domains[] definitions, not for the validity of the domains it does care about; try looking at at e.g. include/dt-bindings/power/px30-power.h and you'll see that the "valid" domains start at 5 (and the domain #s are not even contiguous as e.g. PX30_PD_{CRYPTO,DDR} indices remain uninitialized)...

Quoted 11 lines
Quoted 6 lines
Quoted 2 lines

corresponding domain declaration to be correct. Yet, the patch is
useful as is! >>>> I'm not sure I understand you. The patch should hopefully be

enough to detect the undefined entries (implicitly init'ed with all 0s). What fix for the domain definitions do you have in mind, turning the arrays into lookup tables by adding a domain ID as a field to *struct* rockchip_domain_info?

Apologize if I was vague, but you kind of point out what I just said.

The patch helps us to *detect* incorrect entries. If it turns out we find one, we need to fix that entry.

No, the intent was not to detect the improperly initialized entries but
to verify the supplied DT is correct; I suppose this was the intention of the original (bogus) check in rockchip_pm_add_one_domain()...

Quoted 2 lines

Kind regards
Uffe

MBR, Sergey

#9 lore raw
In reply to Ulf Hansson

On 9/23/26 3:14 PM, Ulf Hansson wrote:
[...]

Quoted 13 lines
Quoted 7 lines

In rockchip_pm_add_one_domain(), there's the check (most probably for the case where the "reg" prop has an unexpected value?) which doesn't make much sense as the variable pd_info will be NULL iff pmu->info-> domain_info is NULL and the variable id is 0. What does make sense there is checking pd_info->pwr_mask and pd_info->req_mask which (as seems to follow from the code) can't both be 0 for a valid domain...

Quoted 5 lines

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

Fixes 7c696693a4f5 ("soc: rockchip: power-domain: Add power domain driver")
Quoted 6 lines

Applied for next, but without the fixes tag, thanks!

Note, that I am dropping the fixes tag because if there was a real problem, we would require yet another fix on top to get the corresponding domain declaration to be correct. Yet, the patch is useful as is!

I was thinking of doing a more elaborate description but if you
considered it good enough, OK... :-)

Quoted 2 lines

Kind regards
Uffe

[...]

MBR, Sergey

#10 lore raw

On 9/23/26 11:44 PM, Sergey Shtylyov wrote:
[...]

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

In rockchip_pm_add_one_domain(), there's the check (most probably for the case where the "reg" prop has an unexpected value?) which doesn't

By "unexpected value" I meant a domain that isn't controlled by this
driver and so have no explicit initializer in *_pm_domains[]. Looks like for such domain #s rockchip_pm_add_one_domain() should fail with -EINVAL.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

make much sense as the variable pd_info will be NULL iff pmu->info-> domain_info is NULL and the variable id is 0. What does make sense there is checking pd_info->pwr_mask and pd_info->req_mask which (as seems to follow from the code) can't both be 0 for a valid domain...

For the domains that have no matching initializer these fields should
be both 0. I had chosen checking these 2 fields instead of pd_info->name as I intended this patch as a fix, easily backportable to the LTS kernels.

Quoted 10 lines
Quoted 10 lines
Quoted 5 lines

Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.

Fixes 7c696693a4f5 ("soc: rockchip: power-domain: Add power domain driver")

Applied for next, but without the fixes tag, thanks!

Note, that I am dropping the fixes tag because if there was a real problem, we would require yet another fix on top to get the

If a defective DT is considered an issue then there's a problem. :-)

Quoted 2 lines
Quoted 2 lines

corresponding domain declaration to be correct. Yet, the patch is useful as is!

Like I've already told, my aim was not detecting the bad declarations,
just bad DTs. I probably just wasn't elaborate/assertive enough...

Quoted 2 lines

I was thinking of doing a more elaborate description but if you
considered it good enough, OK... :-)

So what are you going to do with this, leave things as they are: the
patch merged to the next branch (in its current form) and not merged to fixes? Perhaps a revert or an incremental patch?

Quoted 2 lines
Quoted 2 lines

Kind regards
Uffe

MBR, Sergey