From 892370121ded21733f2a10b35563646f2472cc74 Mon Sep 17 00:00:00 2001 From: Gilles DOFFE Date: Fri, 10 Jul 2020 15:05:53 +0200 Subject: [PATCH] cpu/stm32/qdec: test null callback pointer (#14125) cpu/stm32/qdec: test if callback pointer is set Callback pointer is not tested and could result in a hard fault if the pointer is NULL. Thus only activate interrupt if a callback provided. Signed-off-by: Gilles DOFFE --- cpu/stm32/periph/qdec.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cpu/stm32/periph/qdec.c b/cpu/stm32/periph/qdec.c index f8f3d72997..1eaef36575 100644 --- a/cpu/stm32/periph/qdec.c +++ b/cpu/stm32/periph/qdec.c @@ -114,9 +114,13 @@ int32_t qdec_init(qdec_t qdec, qdec_mode_t mode, qdec_cb_t cb, void *arg) isr_ctx[qdec].cb = cb; isr_ctx[qdec].arg = arg; - /* Enable the qdec's interrupt */ - NVIC_EnableIRQ(qdec_config[qdec].irqn); - dev(qdec)->DIER |= TIM_DIER_UIE; + /* Enable the qdec's interrupt only if there is a callback provided */ + if (cb) { + NVIC_EnableIRQ(qdec_config[qdec].irqn); + dev(qdec)->DIER |= TIM_DIER_UIE; + } else { + dev(qdec)->DIER &= ~TIM_DIER_UIE; + } /* Reset counter and start qdec */ qdec_start(qdec);