Skip to content

Commit

Permalink
cpu/stm32/qdec: test null callback pointer (#14125)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
gdoffe authored Jul 10, 2020
1 parent 547a880 commit 8923701
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions cpu/stm32/periph/qdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8923701

Please sign in to comment.