From 543128771c59e9f1ee91c245d342e929d5ba7fa1 Mon Sep 17 00:00:00 2001 From: Sandrine Bailleux <sandrine.bailleux@arm.com> Date: Mon, 28 Sep 2015 16:32:38 +0100 Subject: [PATCH] Bug fix in the SP804 dual timer driver The generic delay timer driver expects a pointer to a timer_ops_t structure containing the specific timer driver information. It doesn't make a copy of the structure, instead it just keeps the pointer. Therefore, this pointer must remain valid over time. The SP804 driver doesn't satisfy this requirement. The sp804_timer_init() macro creates a temporary instanciation of the timer_ops_t structure on the fly and passes it to the generic delay timer. When this temporary instanciation gets deallocated, the generic delay timer is left with a pointer to invalid data. This patch fixes this bug by statically allocating the SP804 timer_ops_t structure. Change-Id: I8fbf75907583aef06701e3fd9fabe0b2c9bc95bf --- include/drivers/arm/sp804_delay_timer.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/include/drivers/arm/sp804_delay_timer.h b/include/drivers/arm/sp804_delay_timer.h index 5a335716c..1531e5a12 100644 --- a/include/drivers/arm/sp804_delay_timer.h +++ b/include/drivers/arm/sp804_delay_timer.h @@ -40,8 +40,13 @@ uint32_t sp804_get_timer_value(void); void sp804_timer_ops_init(uintptr_t base_addr, const timer_ops_t *ops); #define sp804_timer_init(base_addr, clk_mult, clk_div) \ - sp804_timer_ops_init((base_addr), &(const timer_ops_t) \ - { sp804_get_timer_value, (clk_mult), (clk_div) }) - + do { \ + static const timer_ops_t sp804_timer_ops = { \ + sp804_get_timer_value, \ + (clk_mult), \ + (clk_div) \ + }; \ + sp804_timer_ops_init((base_addr), &sp804_timer_ops); \ + } while (0) #endif /* __SP804_DELAY_TIMER_H__ */ -- GitLab