HMC5x83 driver dereferences null pointer


Following snippet is from pios_board.c

The problem is that EXTI gets enabled in PIOS_HMC5x83_Init() and its handler uses onboad_mag global which is not yet initialized.

And inside PIOS_HMC5x83_IRQHandler() there is

PIOS_DEBUG_Assert() is no-op in non debug code (code compiled without DEBUG = YES i target board Makefile)

Which essentially means that with DEBUG enabled, code panics, and without debug, it dereferences null pointer.

Following is backtrace from debug code.




Paul Jewell
September 30, 2016, 8:00 PM

Vladimir - please be patient with me - I am using this as an opportunity to learn more about the structure of the software! Based on the code, would it be acceptable to move the enabling of the EXTI into PIOS_board_init() after the call to setup the onboard mag? Perhaps a new routine called PIOS_HMC5x83_Enable() with the interrupt enable code and the sensor loop code for the external mags? Once the initialisation routine returns, onboard_mag is correctly initialised and will therefore no longer cause a problem. Alternatively, is there a way to disable all interrupts in PIOS_board_init() until everything is set up?

I am happy to proceed and propose these changes if you think this is the right way to go, and I am also happy to learn more from you if my proposal is not so good! Also, how are you debugging the hardware? Through JTag? I would be interested to know more about your setup (but not here - maybe in slack?)


Paul Jewell


Vladimir Zidar



Fix versions

Affects versions