From ae5e5b77530948220dc1b9ba474ac4e8672472f8 Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Thu, 31 Oct 2019 06:36:10 -0500 Subject: [PATCH] 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 --- include/sys_clock.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/sys_clock.h b/include/sys_clock.h index 681061ea51c..ff5da044984 100644 --- a/include/sys_clock.h +++ b/include/sys_clock.h @@ -73,17 +73,17 @@ extern void z_enable_sys_clock(void); #endif #define __ticks_to_ms(t) __DEPRECATED_MACRO \ - k_ticks_to_ms_floor64(t) + k_ticks_to_ms_floor64((u64_t)(t)) #define z_ms_to_ticks(t) \ - k_ms_to_ticks_ceil32(t) + ((s32_t)k_ms_to_ticks_ceil32((u32_t)(t))) #define __ticks_to_us(t) __DEPRECATED_MACRO \ - k_ticks_to_us_floor64(t) + ((s32_t)k_ticks_to_us_floor32((u32_t)(t))) #define z_us_to_ticks(t) __DEPRECATED_MACRO \ - k_us_to_ticks_ceil64(t) + ((s32_t)k_us_to_ticks_ceil32((u32_t)(t))) #define sys_clock_hw_cycles_per_tick() __DEPRECATED_MACRO \ - k_ticks_to_cyc_floor32(1) + ((int)k_ticks_to_cyc_floor32(1U)) #define SYS_CLOCK_HW_CYCLES_TO_NS64(t) __DEPRECATED_MACRO \ - k_cyc_to_ns_floor64(t) + k_cyc_to_ns_floor64((u64_t)(X)) #define SYS_CLOCK_HW_CYCLES_TO_NS(t) __DEPRECATED_MACRO \ ((u32_t)k_cyc_to_ns_floor64(t))