Skip to content

Commit ac4d20b

Browse files
committed
kernel: restore size and signedness behavior in deprecated time-related API
The addition of API to correctly handle conversion between durations in different clocks inadvertently changed the type of the value produced by the API. Specific changes were: s32_t z_ms_to_ticks(s32_t t) => u32_t k_ms_to_ticks_ceil32(u32_t t) : signedness change s32_t __ticks_to_us(s32_t t) => u64_t k_ticks_to_us_floor64(u64_t t) : signedness and rank change s32_t z_us_to_ticks(s32_t t) => u64_t k_us_to_ticks_ceil64(u64_t t) : signedness and rank change int sys_clock_hw_cycles_per_tick() => u32_t k_ticks_to_cyc_floor32(1) : signedness change The effect of this is to change the essential type of operands in existing expressions, potentially resulting in behavior changes when calculations were promoted to unsigned types, or code size by requiring 64-bot arithmetic. Add casts as necessary to preserve the original return type, and to explicitly recognize impact of passing macro parameters into a context where a specific type will be used. Signed-off-by: Peter Bigot <[email protected]>
1 parent 540ac6d commit ac4d20b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

include/sys_clock.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,17 @@ extern void z_enable_sys_clock(void);
7373
#endif
7474

7575
#define __ticks_to_ms(t) __DEPRECATED_MACRO \
76-
k_ticks_to_ms_floor64(t)
76+
k_ticks_to_ms_floor64((u64_t)(t))
7777
#define z_ms_to_ticks(t) \
78-
k_ms_to_ticks_ceil32(t)
78+
((s32_t)k_ms_to_ticks_ceil32((u32_t)(t)))
7979
#define __ticks_to_us(t) __DEPRECATED_MACRO \
80-
k_ticks_to_us_floor64(t)
80+
((s32_t)k_ticks_to_us_floor32((u32_t)(t)))
8181
#define z_us_to_ticks(t) __DEPRECATED_MACRO \
82-
k_us_to_ticks_ceil64(t)
82+
((s32_t)k_us_to_ticks_ceil32((u32_t)(t)))
8383
#define sys_clock_hw_cycles_per_tick() __DEPRECATED_MACRO \
84-
k_ticks_to_cyc_floor32(1)
84+
((int)k_ticks_to_cyc_floor32(1U))
8585
#define SYS_CLOCK_HW_CYCLES_TO_NS64(t) __DEPRECATED_MACRO \
86-
k_cyc_to_ns_floor64(t)
86+
k_cyc_to_ns_floor64((u64_t)(X))
8787
#define SYS_CLOCK_HW_CYCLES_TO_NS(t) __DEPRECATED_MACRO \
8888
((u32_t)k_cyc_to_ns_floor64(t))
8989

0 commit comments

Comments
 (0)