diff options
| author | Bernard Xiong <[email protected]> | 2020-04-14 10:36:46 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-04-14 10:36:46 +0800 |
| commit | aaecf9414b97790dc17068ed366d6c3ab612dd49 (patch) | |
| tree | 9f57aef892cc9f347ef98935992ffd38b8e5c6ac /components | |
| parent | 7cf7841cca0b270b16105a732e5045213bf2a341 (diff) | |
| parent | e9d930070d88362033312e0d7b6d07b0433e4069 (diff) | |
Merge pull request #3523 from DavidLin1577/patch-3
[components/drivers] update pipe.c
Diffstat (limited to 'components')
| -rw-r--r-- | components/drivers/src/pipe.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/components/drivers/src/pipe.c b/components/drivers/src/pipe.c index ae87b6f5f2..2a7e143f6c 100644 --- a/components/drivers/src/pipe.c +++ b/components/drivers/src/pipe.c @@ -323,18 +323,29 @@ 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) { pipe->fifo = rt_ringbuffer_create(pipe->bufsz); + if (pipe->fifo == RT_NULL) + { + ret = -RT_ENOMEM; + } } rt_mutex_release(&(pipe->lock)); - return RT_EOK; +__exit: + return ret; } rt_err_t rt_pipe_close (rt_device_t device) |
