From a7fdf0dea3e30ba55fcadf3b0e32d115b0f09ddd Mon Sep 17 00:00:00 2001 From: Chris Kay Date: Wed, 8 Aug 2018 13:14:36 +0100 Subject: misc: Fix `dereferencing type-punned pointer will break...` errors Fix `dereferencing type-punned pointer will break strict-aliasing rules` errors. Change-Id: I3eef4c8df85104e1b96edc7da7d5f68cf1455bfc Signed-off-by: Chris Kay --- module/gtimer/src/mod_gtimer.c | 14 ++++++-------- module/timer/src/mod_timer.c | 4 +++- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'module') diff --git a/module/gtimer/src/mod_gtimer.c b/module/gtimer/src/mod_gtimer.c index a1fd882d..dc195d23 100644 --- a/module/gtimer/src/mod_gtimer.c +++ b/module/gtimer/src/mod_gtimer.c @@ -138,6 +138,8 @@ static int get_timer(fwk_id_t dev_id, uint64_t *timestamp) { struct dev_ctx *ctx; int status; + uint32_t counter_low; + uint32_t counter_high; status = fwk_module_check_call(dev_id); if (status != FWK_SUCCESS) @@ -145,16 +147,12 @@ static int get_timer(fwk_id_t dev_id, uint64_t *timestamp) ctx = ctx_table + fwk_id_get_element_idx(dev_id); - struct { - uint32_t low; - uint32_t high; - } value; - /* Read 64-bit timer value */ - value.low = ctx->hw_timer->P_CVALL; - value.high = ctx->hw_timer->P_CVALH; + counter_low = ctx->hw_timer->P_CVALL; + counter_high = ctx->hw_timer->P_CVALH; + + *timestamp = ((uint64_t)counter_high << 32) | counter_low; - *timestamp = *(uint64_t *)&value; return FWK_SUCCESS; } diff --git a/module/timer/src/mod_timer.c b/module/timer/src/mod_timer.c index d3b7b115..8fc61399 100644 --- a/module/timer/src/mod_timer.c +++ b/module/timer/src/mod_timer.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -493,7 +494,8 @@ static void timer_isr(uintptr_t ctx_ptr) .target_id = alarm->listener, .id = alarm->event_id, }; - *(uintptr_t *)event.params = alarm->param; /* Word-size parameter */ + + memcpy(event.params, &alarm->param, sizeof(alarm->param)); status = fwk_thread_put_event(&event); if (status != FWK_SUCCESS) -- cgit v1.2.3