fix(serial_v2): tx_fifo->rb.buffer_ptr not init when RT_DEVICE_FLAG_DMA_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。
This commit is contained in:
parent
c6bdee3c50
commit
82bb104f65
|
@ -684,6 +684,9 @@ static rt_err_t rt_serial_tx_enable(struct rt_device *dev,
|
||||||
(sizeof(struct rt_serial_tx_fifo));
|
(sizeof(struct rt_serial_tx_fifo));
|
||||||
RT_ASSERT(tx_fifo != RT_NULL);
|
RT_ASSERT(tx_fifo != RT_NULL);
|
||||||
|
|
||||||
|
/* Init rb.buffer_ptr to RT_NULL, in rt_serial_write() need check it
|
||||||
|
* otherwise buffer_ptr maybe a random value, as rt_malloc not init memory */
|
||||||
|
tx_fifo->rb.buffer_ptr = RT_NULL;
|
||||||
serial->serial_tx = tx_fifo;
|
serial->serial_tx = tx_fifo;
|
||||||
|
|
||||||
#ifndef RT_USING_DEVICE_OPS
|
#ifndef RT_USING_DEVICE_OPS
|
||||||
|
|
|
@ -755,7 +755,11 @@ static rt_ssize_t _vcom_rb_block_put(struct vcom *data, const rt_uint8_t *buf, r
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static rt_ssize_t _vcom_tx(struct rt_serial_device *serial, rt_uint8_t *buf, rt_size_t size, int direction)
|
#ifdef RT_USING_SERIAL_V1
|
||||||
|
static rt_size_t _vcom_tx(struct rt_serial_device *serial, rt_uint8_t *buf, rt_size_t size, int direction)
|
||||||
|
#else
|
||||||
|
static rt_size_t _vcom_tx(struct rt_serial_device *serial, rt_uint8_t *buf, rt_size_t size, rt_uint32_t tx_flag)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
struct ufunction *func;
|
struct ufunction *func;
|
||||||
struct vcom *data;
|
struct vcom *data;
|
||||||
|
|
Loading…
Reference in New Issue