summaryrefslogtreecommitdiff
path: root/components/drivers/serial
diff options
context:
space:
mode:
authorLaterComer <[email protected]>2024-02-21 13:29:53 +0800
committerGitHub <[email protected]>2024-02-21 00:29:53 -0500
commit82bb104f650011684515508b846a7a7f9c7b229d (patch)
tree24052213206a47fa3b0112f6fc32e13658cb1c04 /components/drivers/serial
parentc6bdee3c503a287a0967fd0e3cb6b7a1eb6d0b5e (diff)
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。
Diffstat (limited to 'components/drivers/serial')
-rw-r--r--components/drivers/serial/serial_v2.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/components/drivers/serial/serial_v2.c b/components/drivers/serial/serial_v2.c
index 1d7a556bf2..5d6f2a8be3 100644
--- a/components/drivers/serial/serial_v2.c
+++ b/components/drivers/serial/serial_v2.c
@@ -684,6 +684,9 @@ static rt_err_t rt_serial_tx_enable(struct rt_device *dev,
(sizeof(struct rt_serial_tx_fifo));
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;
#ifndef RT_USING_DEVICE_OPS