Skip to content

Commit bda111b

Browse files
rugeGerritsennordicjm
authored andcommitted
[nrf fromlist] include: common: sys_bitops: Specify sign when bitshifting
When left-shifting '1' by 31, the result is undefined. This is something ASAN detects. Solve this by explicitly defining that the integer is unsigned. Upstream PR #: 86624 Signed-off-by: Rubin Gerritsen <[email protected]>
1 parent 6971f74 commit bda111b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

include/zephyr/arch/common/sys_bitops.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ static ALWAYS_INLINE void sys_set_bit(mem_addr_t addr, unsigned int bit)
2525
{
2626
uint32_t temp = *(volatile uint32_t *)addr;
2727

28-
*(volatile uint32_t *)addr = temp | (1 << bit);
28+
*(volatile uint32_t *)addr = temp | (1U << bit);
2929
}
3030

3131
static ALWAYS_INLINE void sys_clear_bit(mem_addr_t addr, unsigned int bit)
3232
{
3333
uint32_t temp = *(volatile uint32_t *)addr;
3434

35-
*(volatile uint32_t *)addr = temp & ~(1 << bit);
35+
*(volatile uint32_t *)addr = temp & ~(1U << bit);
3636
}
3737

3838
static ALWAYS_INLINE int sys_test_bit(mem_addr_t addr, unsigned int bit)
3939
{
4040
uint32_t temp = *(volatile uint32_t *)addr;
4141

42-
return temp & (1 << bit);
42+
return temp & (1U << bit);
4343
}
4444

4545
static ALWAYS_INLINE void sys_set_bits(mem_addr_t addr, unsigned int mask)
@@ -62,19 +62,19 @@ static ALWAYS_INLINE
6262
/* Doing memory offsets in terms of 32-bit values to prevent
6363
* alignment issues
6464
*/
65-
sys_set_bit(addr + ((bit >> 5) << 2), bit & 0x1F);
65+
sys_set_bit(addr + ((bit >> 5) << 2U), bit & 0x1F);
6666
}
6767

6868
static ALWAYS_INLINE
6969
void sys_bitfield_clear_bit(mem_addr_t addr, unsigned int bit)
7070
{
71-
sys_clear_bit(addr + ((bit >> 5) << 2), bit & 0x1F);
71+
sys_clear_bit(addr + ((bit >> 5U) << 2U), bit & 0x1F);
7272
}
7373

7474
static ALWAYS_INLINE
7575
int sys_bitfield_test_bit(mem_addr_t addr, unsigned int bit)
7676
{
77-
return sys_test_bit(addr + ((bit >> 5) << 2), bit & 0x1F);
77+
return sys_test_bit(addr + ((bit >> 5U) << 2U), bit & 0x1F);
7878
}
7979

8080
static ALWAYS_INLINE

0 commit comments

Comments
 (0)