Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SerialBase:: _irq_handler() tries to invoke NULL callback #189

Open
dbaba opened this issue Jul 5, 2016 · 1 comment
Open

SerialBase:: _irq_handler() tries to invoke NULL callback #189

dbaba opened this issue Jul 5, 2016 · 1 comment

Comments

@dbaba
Copy link

dbaba commented Jul 5, 2016

handler->_irq[irq_type] can be undefined/nullptr if SeriaBasel#attach() is invoked for attaching a callback function to either Serial::RxIrq or Serial::TxIrq.

SerialBase.cpp#L62

void SerialBase::_irq_handler(uint32_t id, SerialIrq irq_type) {
    SerialBase *handler = (SerialBase*)id;
    handler->_irq[irq_type].call();
}

Because of lack of the checking, I got an assertion error (_membercaller != NULL) && (_object != NULL) at core-util/core-util/FunctionPointerBase.h:68 when UART RX received data and RawSerial::attach(&some_callbck, Serial::RxIrq) was called.

Here is a backtrace at that time:

#0  0x0800a766 in us_ticker_read () at /path/to/my-workspace/yotta_modules/mbed-hal-st-stm32f4/source/us_ticker.c:48
#1  0x08007694 in wait_us (us=150000) at /path/to/my-workspace/yotta_modules/mbed-drivers/source/wait_api.c:30
#2  0x08007678 in wait_ms (ms=150) at /path/to/my-workspace/yotta_modules/mbed-drivers/source/wait_api.c:25
#3  0x0800828a in mbed_die () at /path/to/my-workspace/yotta_modules/mbed-drivers/source/board.c:59
#4  0x0800a222 in core_util_assert_internal (expr=0x8016c78 "(_membercaller != NULL) && (_object != NULL)", 
    file=0x8016c10 "/path/to/my-workspace/yotta_modules/core-util/core-util/FunctionPointerBase.h", line=68, msg=0x0)
    at /path/to/my-workspace/yotta_modules/core-util/source/assert_mbed.c:53
#5  0x08008d82 in mbed::util::FunctionPointerBase<void>::call (this=0x20008844 <rs485+172>, arg=0x0)
    at /path/to/my-workspace/yotta_modules/core-util/core-util/FunctionPointerBase.h:68
#6  0x08008cae in mbed::util::FunctionPointer0<void>::call (this=0x20008844 <rs485+172>) at /path/to/my-workspace/yotta_modules/core-util/core-util/FunctionPointer.h:84
#7  0x08008bf6 in mbed::SerialBase::_irq_handler (id=536905624, irq_type=TxIrq) at /path/to/my-workspace/yotta_modules/mbed-drivers/source/SerialBase.cpp:64
#8  0x0800b10a in uart_irq (id=0) at /path/to/my-workspace/yotta_modules/mbed-hal-st-stm32f4/source/serial_api.c:442
#9  0x0800b15e in uart1_irq () at /path/to/my-workspace/yotta_modules/mbed-hal-st-stm32f4/source/serial_api.c:486
#10 <signal handler called>
#11 0x0800ae5a in NVIC_EnableIRQ (IRQn=USART1_IRQn) at /path/to/my-workspace/yotta_modules/cmsis-core/cmsis-core/core_cm4.h:1471
#12 0x0800b23a in serial_irq_set (obj=0x20008800 <rs485+104>, irq=RxIrq, enable=1) at /path/to/my-workspace/yotta_modules/mbed-hal-st-stm32f4/source/serial_api.c:753
#13 0x0800762c in mbed::SerialBase::attach<MySerialTest> (this=0x20008798 <rs485>, tptr=0x20009660, 
    mptr=(void (MySerialTest::*)(MySerialTest * const)) 0x80071ed <MySerialTest::rx_interrupt()>, type=mbed::SerialBase::RxIrq)
    at /path/to/my-workspace/yotta_modules/mbed-drivers/mbed-drivers/SerialBase.h:113
#14 0x0800728e in MySerialTest::rs485_txrx_tick (this=0x20009660) at /path/to/my-workspace/source/my_serial_test.cpp:124
#15 0x08003f60 in mbed::util::FunctionPointer0<void>::membercaller<MySerialTest> (object=0x20009660, member=0x2001793c "Qr", arg=0x20017950)
    at /path/to/my-workspace/yotta_modules/core-util/core-util/FunctionPointer.h:108
#16 0x08008d92 in mbed::util::FunctionPointerBase<void>::call (this=0x20017938, arg=0x20017950)
    at /path/to/my-workspace/yotta_modules/core-util/core-util/FunctionPointerBase.h:70
#17 0x0800a07e in mbed::util::FunctionPointerBind<void>::call (this=0x20017938) at /path/to/my-workspace/yotta_modules/core-util/core-util/FunctionPointerBind.h:50
#18 0x08009b7e in mbed::util::FunctionPointerBind<void>::operator() (this=0x20017938)
    at /path/to/my-workspace/yotta_modules/core-util/core-util/FunctionPointerBind.h:93
#19 0x08009740 in minar::SchedulerData::start (this=0x20009040) at /path/to/my-workspace/yotta_modules/minar/source/minar.cpp:354
#20 0x080093f4 in minar::Scheduler::start () at /path/to/my-workspace/yotta_modules/minar/source/minar.cpp:178
#21 0x08007e68 in main () at /path/to/my-workspace/yotta_modules/mbed-drivers/source/retarget.cpp:559

So SerialBase::_irq_handler has to check if the callback associated with the irq_type exists.

void SerialBase::_irq_handler(uint32_t id, SerialIrq irq_type) {
    SerialBase *handler = (SerialBase*)id;
    if (handler->_irq[irq_type]) {
        handler->_irq[irq_type].call();
    }
}

By the way, I don't have any idea why Serial::TxIrq was fired though the actual event should be UART RX. This could be the root cause but I don't know if it's true the expected behavior.

mbed-drivers version:

  "version": "1.5.0",
@0xc0170 0xc0170 added the bug label Jul 5, 2016
@ciarmcom
Copy link
Member

ciarmcom commented Jul 5, 2016

ARM Internal Ref: IOTSFW-2752

dbaba pushed a commit to dbaba/mbed-drivers that referenced this issue Jul 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants