-
Notifications
You must be signed in to change notification settings - Fork 8.3k
drivers: led: pca9533: fix ms_to_psc wrap-around #100194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
drivers: led: pca9533: fix ms_to_psc wrap-around #100194
Conversation
If `period_ms` is 3 or less `tmp` is 0. Since `tmp` is type `uint32` subtracting 1 from 0 will wrap around to `UINT32_MAX` and is then clamped to `UINT8_MAX`. Fix the issue by changing `tmp` and `1` to signed types. Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
de5ff71 to
fe1c4cf
Compare
|
simonguinot
left a comment
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.
Thanks :)
| static uint8_t ms_to_psc(uint32_t period_ms) | ||
| { | ||
| uint32_t tmp = (period_ms * 152U + 500U) / 1000U; | ||
| int32_t tmp = (period_ms * 152U + 500U) / 1000U; |
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.
should probably have
int32_t tmp = (int32_t)((period_ms * 152U + 500U) / 1000U);
or will get a future warning on type assignment
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.
I am not familiar with the warning.
Can you share a link please?
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.
I am not familiar with the warning.
Can you share a link please?



If
period_msis 3 or lesstmpis 0. Sincetmpis typeuint32subtracting 1 from 0 will wrap around toUINT32_MAXand is then clamped toUINT8_MAX.Fix the issue by changing
tmpand1to signed types.Fixes #100020