From ff09587d2381da4d02fd8a31a73e6271f3ca3e9f Mon Sep 17 00:00:00 2001 From: David Lin Date: Sun, 12 Apr 2020 11:58:33 +0800 Subject: [PATCH 1/2] [components/drivers] update pipe.c Fixed stackover flow bug when create pipe->fifo --- components/drivers/src/pipe.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/components/drivers/src/pipe.c b/components/drivers/src/pipe.c index ae87b6f5f2..393370fc9a 100644 --- a/components/drivers/src/pipe.c +++ b/components/drivers/src/pipe.c @@ -330,6 +330,11 @@ rt_err_t rt_pipe_open (rt_device_t device, rt_uint16_t oflag) if (pipe->fifo == RT_NULL) { pipe->fifo = rt_ringbuffer_create(pipe->bufsz); + if (pipe->fifo == RT_NULL) + { + rt_mutex_release(&(pipe->lock)); + return -RT_ENOMEM; + } } rt_mutex_release(&(pipe->lock)); From e9d930070d88362033312e0d7b6d07b0433e4069 Mon Sep 17 00:00:00 2001 From: David Lin Date: Mon, 13 Apr 2020 07:20:29 +0800 Subject: [PATCH 2/2] Update pipe.c --- components/drivers/src/pipe.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/components/drivers/src/pipe.c b/components/drivers/src/pipe.c index 393370fc9a..2a7e143f6c 100644 --- a/components/drivers/src/pipe.c +++ b/components/drivers/src/pipe.c @@ -323,8 +323,14 @@ static const struct dfs_file_ops pipe_fops = rt_err_t rt_pipe_open (rt_device_t device, rt_uint16_t oflag) { rt_pipe_t *pipe = (rt_pipe_t *)device; + rt_err_t ret = RT_EOK; - if (device == RT_NULL) return -RT_EINVAL; + if (device == RT_NULL) + { + ret = -RT_EINVAL; + goto __exit; + } + rt_mutex_take(&(pipe->lock), RT_WAITING_FOREVER); if (pipe->fifo == RT_NULL) @@ -332,14 +338,14 @@ rt_err_t rt_pipe_open (rt_device_t device, rt_uint16_t oflag) pipe->fifo = rt_ringbuffer_create(pipe->bufsz); if (pipe->fifo == RT_NULL) { - rt_mutex_release(&(pipe->lock)); - return -RT_ENOMEM; + ret = -RT_ENOMEM; } } rt_mutex_release(&(pipe->lock)); - return RT_EOK; +__exit: + return ret; } rt_err_t rt_pipe_close (rt_device_t device)