Skip to contentSkip to conversation

timer: stm32f2xx_timer: add check for prescaler value

PATCH Applied P J P 2 participants 2 messages Oct 18, 2016 – Oct 24, 2016 Arm STM32

lore
Share & tools
lore

P J P

author
#0 lore raw

PATCH 1/1 timer: stm32f2xx_timer: add check for prescaler value

From: Prasad J Pandit <[email protected]>

The STM32F2XX Timer emulator uses a 16 bit prescaler value to limit the timer clock rate. It does that by dividing the timer frequency. If the prescaler 's->tim_psc' was set to be UINT_MAX, it'd lead to divide by zero error. Limit prescaler value to 16 bits to avoid it.

---
 hw/timer/stm32f2xx_timer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/timer/stm32f2xx_timer.c +1 -1
index bf0fb28..2cad36d 100644
@@ -208,7 +208,7 @@ static void stm32f2xx_timer_write(void *opaque, hwaddr offset,
         return;
     case TIM_PSC:
         timer_val = stm32f2xx_ns_to_ticks(s, now) - s->tick_offset;
-        s->tim_psc = value;
+        s->tim_psc = value & 0xFFFF;
         value = timer_val;
         break;
     case TIM_CNT:
Signature · 1 line
2.7.4
#1 lore raw
Quoted 19 lines · P J P

From: Prasad J Pandit <[email protected]>

The STM32F2XX Timer emulator uses a 16 bit prescaler value to limit the timer clock rate. It does that by dividing the timer frequency. If the prescaler 's->tim_psc' was set to be UINT_MAX, it'd lead to divide by zero error. Limit prescaler value to 16 bits to avoid it.

---
 hw/timer/stm32f2xx_timer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/timer/stm32f2xx_timer.c +0 -0
index bf0fb28..2cad36d 100644

hw/timer/stm32f2xx_timer.c static void stm32f2xx_timer_write(void *opaque, hwaddr offset, · line 214

Quoted 8 lines
hw/timer/stm32f2xx_timer.c +1 -1
@@ -208,7 +208,7 @@ static void stm32f2xx_timer_write(void *opaque, hwaddr offset,
         return;
     case TIM_PSC:
         timer_val = stm32f2xx_ns_to_ticks(s, now) - s->tick_offset;
-        s->tim_psc = value;
+        s->tim_psc = value & 0xFFFF;
         value = timer_val;
         break;
     case TIM_CNT:

Applied to target-arm.next, thanks.

(That "value = timer_val;" line looks odd as it is dead code, but that's a different bug I think. Alistair, can you remember what you meant when you wrote that?)

-- PMM