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
+14 -9
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() */ /* Allocate the descriptor list for poll() */
pollset = (struct pollfd *)kmm_zalloc(npfds * sizeof(struct pollfd)); pollset = (struct pollfd *)kmm_zalloc(npfds * sizeof(struct pollfd));
if (!pollset) if (!pollset)
{ {
set_errno(ENOMEM); errcode = ENOMEM;
leave_cancellation_point(); goto errout;
return ERROR;
} }
/* Initialize the descriptor list for poll() */ /* 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? */ /* Did poll() fail above? */
if (ret < 0) if (ret >= 0)
{ {
/* Yes.. restore the errno value */ leave_cancellation_point();
return ret;
set_errno(errcode);
} }
errout:
set_errno(errcode);
leave_cancellation_point(); leave_cancellation_point();
return ret; return ERROR;
} }
#endif /* CONFIG_DISABLE_POLL */ #endif /* CONFIG_DISABLE_POLL */