Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(serial_v2): tx_fifo->rb.buffer_ptr not init when RT_DEVICE_FLAG_D…
…MA_TX and RT_SERIAL_TX_BLOCKING 为什么提交这份PR (why to submit this PR) serial_v2驱动框架,rt_serial_tx_enable()函数,在 DMA阻塞发送(RT_DEVICE_FLAG_DMA_TX and RT_SERIAL_TX_BLOCKING) 的时候,使用rt_malloc分配了tx_fifo内存,但是并未对tx_fifo->rb.buffer_ptr指针进行初始化(rt_malloc不会自动初始化内存),因此可能导致buffer_ptr是一个随机指针。但是rt_serail_write()函数需要根据tx_fifo->rb.buffer_ptr是否为RT_NULL来判断是调用_serial_fifo_tx_blocking_nbuf()还是_serial_fifo_tx_blocking_buf()。 由于tx_fifo->rb.buffer_ptr可能是一个随机值(不一定为RT_NULL=0),导致RT_DEVICE_FLAG_DMA_TX and RT_SERIAL_TX_BLOCKING模式下调用了_serial_fifo_tx_blocking_buf(),但是rb没有真正开辟内存空间,导致内存异常 你的解决方案是什么 (what is your solution) rt_serial_tx_enable(),在DMA阻塞发送分支下,对tx_fifo->rb.buffer_ptr进行初始化,赋值为RT_NULL。
- Loading branch information
82bb104
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有个疑问请教一下大佬:
1、上述serial_v2提交引入的代码(tx_fifo->rb.buffer_ptr = RT_NULL)感觉和700行的代码(rt_memset(&tx_fifo->rb, RT_NULL, sizeof(tx_fifo->rb)))有重复?
2、如果是为了保证初始化,是否可以考虑使用rt_calloc
82bb104
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好建议~ 欢迎提交PR~