This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit ce59558a0ebce54c44906981e5e0456e079b08a5
Author: Bowen Wang <[email protected]>
AuthorDate: Fri Sep 4 17:35:16 2026 +0800

    fs/poll: make POLLALWAYS a two-sided handshake
    
    epoll sets POLLALWAYS on every node and poll_notify() honours it for
    every driver, so a notification carrying an event the user did not ask
    for still runs the callback.  epoll marks that node notified, then tears
    the fd down and sets it up again on the next epoll_wait() while
    reporting nothing.  Only a driver whose poll registration goes stale on
    an internal state change needs that re-registration; for everyone else
    it is pure overhead, and a driver had no way to say which it is.
    
    Require both sides to agree: the waiter still sets POLLALWAYS in events
    to accept a callback carrying no event, and the driver now has to set it
    in the notified eventset to ask for one.  Also keep POLLALWAYS out of
    revents, it is kernel internal.
    
    Signed-off-by: Bowen Wang <[email protected]>
---
 fs/vfs/fs_poll.c     | 6 ++++--
 include/nuttx/poll.h | 8 ++++++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/fs/vfs/fs_poll.c b/fs/vfs/fs_poll.c
index 8d28b231765..f50f3fa1ebe 100644
--- a/fs/vfs/fs_poll.c
+++ b/fs/vfs/fs_poll.c
@@ -287,7 +287,8 @@ void poll_notify(FAR struct pollfd_s **afds, int nfds, 
pollevent_t eventset)
         {
           /* The error event must be set in fds->revents */
 
-          fds->revents |= eventset & (fds->events | POLLERR | POLLHUP);
+          fds->revents |= eventset & (fds->events | POLLERR | POLLHUP) &
+                          ~POLLALWAYS;
           if ((fds->revents & (POLLERR | POLLHUP)) != 0)
             {
               /* Error or Hung up, clear POLLOUT event */
@@ -295,7 +296,8 @@ void poll_notify(FAR struct pollfd_s **afds, int nfds, 
pollevent_t eventset)
               fds->revents &= ~POLLOUT;
             }
 
-          if ((fds->revents != 0 || (fds->events & POLLALWAYS) != 0) &&
+          if ((fds->revents != 0 ||
+               (fds->events & eventset & POLLALWAYS) != 0) &&
               fds->cb != NULL)
             {
               finfo("Report events: %08" PRIx32 "\n", fds->revents);
diff --git a/include/nuttx/poll.h b/include/nuttx/poll.h
index e5f75357e34..aaaa559624a 100644
--- a/include/nuttx/poll.h
+++ b/include/nuttx/poll.h
@@ -36,8 +36,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-/* POLLALWAYS: call the poll callback whether or not the driver reported an
- * event that the waiter asked for (events only, kernel only).
+/* POLLALWAYS: call the poll callback even when the notified event is not
+ * one the waiter asked for.  Kernel only.  Both sides must agree:  the
+ * waiter sets it in events to accept a callback carrying no event (epoll
+ * does, to re-run poll setup), and the driver sets it in the notified
+ * eventset to ask for one, which only a driver whose poll registration goes
+ * stale on an internal state change needs to do.
  */
 
 #define POLLALWAYS   (0x10000) /* Does not conflict with Linux */

Reply via email to