VFS poll(): Add some error handling logic

This commit is contained in:
Gregory Nutt 2017-04-20 19:15:17 -06:00
parent 356e71850b
commit 7457875447
1 changed files with 14 additions and 9 deletions

View File

@ -133,14 +133,19 @@ int select(int nfds, FAR fd_set *readfds, FAR fd_set *writefds,
}
}
if (npfds <= 0)
{
errcode = EINVAL;
goto errout;
}
/* Allocate the descriptor list for poll() */
pollset = (struct pollfd *)kmm_zalloc(npfds * sizeof(struct pollfd));
if (!pollset)
{
set_errno(ENOMEM);
leave_cancellation_point();
return ERROR;
errcode = ENOMEM;
goto errout;
}
/* Initialize the descriptor list for poll() */
@ -279,16 +284,16 @@ int select(int nfds, FAR fd_set *readfds, FAR fd_set *writefds,
/* Did poll() fail above? */
if (ret < 0)
if (ret >= 0)
{
/* Yes.. restore the errno value */
set_errno(errcode);
leave_cancellation_point();
return ret;
}
errout:
set_errno(errcode);
leave_cancellation_point();
return ret;
return ERROR;
}
#endif /* CONFIG_DISABLE_POLL */