From 7050c312df35c204877b488ceb1bc6e14fa50e3f Mon Sep 17 00:00:00 2001 From: wangchen Date: Wed, 6 Mar 2024 16:39:48 +0800 Subject: [PATCH] pipes:fix the issue of the circbuf cannot be incorrectly initialized due to PIPE_POLICY_0 if dev->d_flags is POLICY_1, the circbuf cannot be initialized incorrectly. We determine whether the circbuf should be initialized based on first reference on device and d_buffer is NULL Signed-off-by: wangchen --- drivers/pipes/pipe_common.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/pipes/pipe_common.c b/drivers/pipes/pipe_common.c index 0254c3a142..efb95027ca 100644 --- a/drivers/pipes/pipe_common.c +++ b/drivers/pipes/pipe_common.c @@ -144,12 +144,9 @@ int pipecommon_open(FAR struct file *filep) return ret; } - /* If this the first reference on the device, then allocate the buffer. - * In the case of policy 1, the buffer already be present when the pipe - * is first opened. - */ + /* If d_buffer is not initialized, init it. */ - if (dev->d_crefs == 0 && PIPE_IS_POLICY_0(dev->d_flags)) + if (!circbuf_is_init(&dev->d_buffer)) { ret = circbuf_init(&dev->d_buffer, NULL, dev->d_bufsize); if (ret < 0)