Page 1 of 1

Bug in gpt_lld.c Callback pointer not verified.

Posted: Fri Jan 10, 2014 9:17 pm
by SvendStave
release 2.6.2

I just fell into this bug, defining the callback NULL causes a crash
the code misses a check that the pointer is not NULL


if (gptp->config->callback != NULL )
gptp->config->callback(gptp);


original code:
/**
* @brief Shared IRQ handler.
*
* @param[in] gptp pointer to a @p GPTDriver object
*/
static void gpt_lld_serve_interrupt(GPTDriver *gptp) {

gptp->tim->SR = 0;
if (gptp->state == GPT_ONESHOT) {
gptp->state = GPT_READY; /* Back in GPT_READY state. */
gpt_lld_stop_timer(gptp); /* Timer automatically stopped. */
}
gptp->config->callback(gptp);
}


/Svend

Re: Bug in gpt_lld.c Callback pointer not verified.

Posted: Sat Jan 11, 2014 12:44 pm
by Giovanni
Hi,

I am undecided on this one, I am thinking to give a different meaning to the NULL callback: the interrupt should not be enabled at all if a callback is not defined.

Anyway, at least an assertions should be there.

thank,
Giovanni

Re: Bug in gpt_lld.c Callback pointer not verified.

Posted: Sun Jan 12, 2014 1:04 am
by SvendStave
It would be cleaner not to enable an interrupt, and let the user do all the setup in the config - it's making it more difficult to initialize from scratch, but give better control.
I have extended my config to include cr1 and cr2 to be able to setup TRGO - so it's no big deal..

Making an assert of the callback while checking DIER would be right, but then the fixed setting of DIER in
void gpt_lld_start_timer(GPTDriver *gptp, gptcnt_t interval)
should be moved out and be part of user setting.

/Svend