Bug in gpt_lld.c Callback pointer not verified.

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
SvendStave
Posts: 8
Joined: Thu Nov 28, 2013 7:07 am

Bug in gpt_lld.c Callback pointer not verified.

Post 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
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

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

Post 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
SvendStave
Posts: 8
Joined: Thu Nov 28, 2013 7:07 am

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

Post 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
Post Reply