From 9642d8dae6fe287f5325e7453bc366949a59688c Mon Sep 17 00:00:00 2001 From: zhanghu5 Date: Sun, 8 Oct 2023 10:24:42 +0800 Subject: [PATCH] fix goldfish_pipe poll error when multiple processes call poll and a event occured, all the processes are waked up. it should wake up one process based on pipe->id Signed-off-by: zhanghu5 --- drivers/misc/goldfish_pipe.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/drivers/misc/goldfish_pipe.c b/drivers/misc/goldfish_pipe.c index 7b4ff114a3..afaf81e3ac 100644 --- a/drivers/misc/goldfish_pipe.c +++ b/drivers/misc/goldfish_pipe.c @@ -487,7 +487,6 @@ static int goldfish_pipe_poll(FAR struct file *filp, pollevent_t mask = 0; int status; - int i; int ret; ret = nxmutex_lock(&dev->polllock); @@ -498,17 +497,7 @@ static int goldfish_pipe_poll(FAR struct file *filp, if (setup) { - for (i = 0; i < dev->pipes_capacity; i++) - { - if (!dev->fds[i]) - { - dev->fds[i] = fds; - fds->priv = &dev->fds[i]; - break; - } - } - - if (i >= dev->pipes_capacity) + if (dev->fds[pipe->id] != NULL) { fds->priv = NULL; ret = -EBUSY; @@ -521,6 +510,9 @@ static int goldfish_pipe_poll(FAR struct file *filp, return -ERESTART; } + dev->fds[pipe->id] = fds; + fds->priv = &dev->fds[pipe->id]; + if (status & PIPE_POLL_IN) mask |= EPOLLIN | EPOLLRDNORM; if (status & PIPE_POLL_OUT) @@ -531,7 +523,7 @@ static int goldfish_pipe_poll(FAR struct file *filp, mask |= EPOLLERR; if (mask) - poll_notify(dev->fds, dev->pipes_capacity, mask); + poll_notify(&fds, 1, mask); } else if (fds->priv != NULL) { @@ -663,13 +655,13 @@ static void goldfish_interrupt_task(FAR void *arg) if (nxmutex_lock(&dev->polllock) == OK) { if (wakes & PIPE_WAKE_READ) - poll_notify(dev->fds, dev->pipes_capacity, EPOLLIN); + poll_notify(&dev->fds[pipe->id], 1, EPOLLIN); if (wakes & PIPE_WAKE_WRITE) - poll_notify(dev->fds, dev->pipes_capacity, EPOLLOUT); + poll_notify(&dev->fds[pipe->id], 1, EPOLLOUT); if (wakes & PIPE_WAKE_CLOSED) - poll_notify(dev->fds, dev->pipes_capacity, EPOLLHUP); + poll_notify(&dev->fds[pipe->id], 1, EPOLLHUP); nxmutex_unlock(&dev->polllock); } @@ -876,6 +868,7 @@ static int goldfish_pipe_release(FAR struct file *filp) flags = spin_lock_irqsave(&dev->lock); dev->pipes[pipe->id] = NULL; + dev->fds[pipe->id] = NULL; signalled_pipes_remove_locked(dev, pipe); spin_unlock_irqrestore(&dev->lock, flags);