Skip to content

Conversation

@jeppenodgaard
Copy link

@jeppenodgaard jeppenodgaard commented Nov 28, 2025

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.

Fixes #100020

@zephyrbot zephyrbot added the area: LED Label to identify LED subsystem label Nov 28, 2025
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>
@jeppenodgaard jeppenodgaard force-pushed the fix-led-pca9533-wrap-around branch from de5ff71 to fe1c4cf Compare November 28, 2025 08:06
@sonarqubecloud
Copy link

@kartben kartben added the Coverity A Coverity detected issue or its fix label Nov 28, 2025
Copy link
Contributor

@simonguinot simonguinot left a 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;
Copy link
Contributor

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

Copy link
Author

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?

Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: LED Label to identify LED subsystem Coverity A Coverity detected issue or its fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Coverity CID: 548302] Overflowed return value in drivers/led/pca9533.c

6 participants