Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what exactly problem is this addressing? If
num_cpu_statesis returned as 0, theniis assigned -1, so this loop isn't run at all as it should. Ifpm_state_cpu_get_all()returns something like 254 the old code would run the loop 254 times, while the new one will convert that to -2 and not run at all (if my mental integer conversions are right). Neither of those cases seem particularly meaningful. If it returns 127, the behaviour would be the same... So what is this fixing?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Integer overflow.
In original code for 0 this will hit UINT_MAX and out-of-range unsigned→signed conversion (implementation-defined in C, pre-C23). This is well-defined in gcc and xtensa so there is no real impact/issue here, just a better code with proper matching return type from pm_state_cpu_get_all() like in reference zephyr pm policy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alright... So in theory, compilers, implementing older than C23 C standards (but I suppose they're still in active use, since the standard is apparently only 3 years old?) could convert
int i = UINT_MAXto something different than -1... interesting. Would just changing the type ofnum_cpu_statestointfix this too? With no type-casting then?