diff --git a/fs/vfs/fs_poll.c b/fs/vfs/fs_poll.c index f043f57ee25b8..9078ea0602d21 100644 --- a/fs/vfs/fs_poll.c +++ b/fs/vfs/fs_poll.c @@ -275,6 +275,7 @@ void poll_notify(FAR struct pollfd **afds, int nfds, pollevent_t eventset) { int i; FAR struct pollfd *fds; + pollevent_t revents; irqstate_t flags; DEBUGASSERT(afds != NULL && nfds >= 1); @@ -284,27 +285,31 @@ void poll_notify(FAR struct pollfd **afds, int nfds, pollevent_t eventset) fds = afds[i]; if (fds != NULL) { - /* race condition protection when modifying fds->revents */ - - flags = enter_critical_section(); - /* The error event must be set in fds->revents */ - fds->revents |= eventset & (fds->events | POLLERR | POLLHUP); - if ((fds->revents & (POLLERR | POLLHUP)) != 0) + revents = eventset & (fds->events | POLLERR | POLLHUP); + if (revents != 0) { - /* Error or Hung up, clear POLLOUT event */ + /* race condition protection when modifying fds->revents */ - fds->revents &= ~POLLOUT; - } + flags = enter_critical_section(); - leave_critical_section(flags); + fds->revents |= revents; + if ((fds->revents & (POLLERR | POLLHUP)) != 0) + { + /* Error or Hung up, clear POLLOUT event */ - if ((fds->revents != 0 || (fds->events & POLLALWAYS) != 0) && - fds->cb != NULL) - { - finfo("Report events: %08" PRIx32 "\n", fds->revents); - fds->cb(fds); + fds->revents &= ~POLLOUT; + } + + leave_critical_section(flags); + + if ((fds->events & POLLALWAYS) != 0 && + fds->cb != NULL) + { + finfo("Report events: %08" PRIx32 "\n", fds->revents); + fds->cb(fds); + } } } }