Skip to content

Commit aaecf94

Browse files
authored
Merge pull request #3523 from DavidLin1577/patch-3
[components/drivers] update pipe.c
2 parents 7cf7841 + e9d9300 commit aaecf94

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

components/drivers/src/pipe.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,18 +323,29 @@ static const struct dfs_file_ops pipe_fops =
323323
rt_err_t rt_pipe_open (rt_device_t device, rt_uint16_t oflag)
324324
{
325325
rt_pipe_t *pipe = (rt_pipe_t *)device;
326+
rt_err_t ret = RT_EOK;
326327

327-
if (device == RT_NULL) return -RT_EINVAL;
328+
if (device == RT_NULL)
329+
{
330+
ret = -RT_EINVAL;
331+
goto __exit;
332+
}
333+
328334
rt_mutex_take(&(pipe->lock), RT_WAITING_FOREVER);
329335

330336
if (pipe->fifo == RT_NULL)
331337
{
332338
pipe->fifo = rt_ringbuffer_create(pipe->bufsz);
339+
if (pipe->fifo == RT_NULL)
340+
{
341+
ret = -RT_ENOMEM;
342+
}
333343
}
334344

335345
rt_mutex_release(&(pipe->lock));
336346

337-
return RT_EOK;
347+
__exit:
348+
return ret;
338349
}
339350

340351
rt_err_t rt_pipe_close (rt_device_t device)

0 commit comments

Comments
 (0)