diff --git a/ChangeLog b/ChangeLog index e3366023162..ba34d12012a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4777,8 +4777,7 @@ * net/net_poll.c: When readahead data is availalbe, the network poll logic should set POLLIN (or POLLRDNORM), not POLLOUT. Max Holtzberg (2013-5-23) - * fs/fs_poll.c: Actually, it should not ignore invlid descriptors, it - should set the POLLNVAL event and return immediately (2013-5-23). + * fs/fs_poll.c: Actually, it should also set revents == 0. (2013-5-23). * libc/misc/lib_slcdencode.c and lib_slcddecode.c: Add logic to marshal and serialized special SLCD intermixed with normal ASCII data (2013-5-23) * configs/stm32ldiscovery/src/stm32_lcd.c: STM32L-Discovery's segment LCD diff --git a/fs/fs_poll.c b/fs/fs_poll.c index b6a09b64490..52d7f94a853 100644 --- a/fs/fs_poll.c +++ b/fs/fs_poll.c @@ -166,28 +166,22 @@ static inline int poll_setup(FAR struct pollfd *fds, nfds_t nfds, sem_t *sem) /* Setup the poll descriptor */ fds[i].sem = sem; + fds[i].revents = 0; fds[i].priv = NULL; - /* Check for invalid descriptors */ + /* Check for invalid descriptors. "If the value of fd is less than 0, + * events shall be ignored, and revents shall be set to 0 in that entry + * on return from poll()." + * + * NOTE: There is a potential problem here. If there is only one fd + * and if it is negative, then poll will hang. From my reading of the + * spec, that appears to be the correct behavior. + */ - if (fds[i].fd < 0) - { - /* Set POLLNVAL to indicate the invalid fd member */ - - fds[i].revents = POLLNVAL; - - /* And increment the semaphore so that poll will return - * immediately (but with a successful return value). - */ - - sem_post(sem); - } - else + if (fds[i].fd >= 0) { /* Set up the poll on this valid file descriptor */ - fds[i].revents = 0; - ret = poll_fdsetup(fds[i].fd, &fds[i], true); if (ret < 0) {