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 <wangchen41@xiaomi.com>
This commit is contained in:
wangchen 2024-03-06 16:39:48 +08:00 committed by Alan Carvalho de Assis
parent 9147c955dc
commit 7050c312df
1 changed files with 2 additions and 5 deletions

View File

@ -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)