xiaoxiang781216 commented on code in PR #20796:
URL: https://github.com/apache/nuttx/pull/20796#discussion_r4388172006
##########
fs/vfs/fs_poll.c:
##########
@@ -525,26 +534,19 @@ int poll(FAR struct pollfd *fds, nfds_t nfds, int timeout)
nxsem_destroy(&sem);
-#ifdef CONFIG_BUILD_KERNEL
- /* Copy the events back to user */
+ /* Copy the events back to the user */
- if (ret == OK)
+ for (i = 0; i < nfds; i++)
{
- int i;
-
- for (i = 0; i < nfds; i++)
- {
- fds[i].revents = kfds[i].revents;
- }
+ fds[i].revents = (short)kfds[i].revents;
Review Comment:
remove the cast too
##########
fs/vfs/fs_poll.c:
##########
@@ -416,39 +422,43 @@ int file_poll(FAR struct file *filep, FAR struct pollfd_s
*fds, bool setup)
int poll(FAR struct pollfd *fds, nfds_t nfds, int timeout)
{
+ struct pollfd_s sfds[POLL_NSTACKFDS];
+ struct pollinfo_s fdsinfo;
FAR struct pollfd_s *kfds;
sem_t sem;
int count = 0;
int ret = OK;
+ nfds_t i;
DEBUGASSERT(nfds == 0 || fds != NULL);
/* poll() is a cancellation point */
enter_cancellation_point();
-#ifdef CONFIG_BUILD_KERNEL
- /* Allocate kernel memory for the fds */
+ /* Copy the user fds to a kernel array, which also holds the internal
+ * fields of each entry.
+ */
- kfds = fs_heap_malloc(nfds * sizeof(struct pollfd_s));
- if (!kfds)
+ if (nfds <= POLL_NSTACKFDS)
{
- /* Out of memory */
-
- ret = -ENOMEM;
- goto out_with_cancelpt;
+ kfds = sfds;
+ }
+ else
+ {
+ kfds = fs_heap_malloc(nfds * sizeof(struct pollfd_s));
+ if (kfds == NULL)
+ {
+ ret = -ENOMEM;
+ goto out_with_cancelpt;
+ }
}
- /* Copy the user fds to neutral kernel memory */
-
- memcpy(kfds, fds, nfds * sizeof(struct pollfd));
-#else
- /* Can use the user fds directly: struct pollfd has the layout of struct
- * pollfd_s.
- */
-
- kfds = (FAR struct pollfd_s *)fds;
-#endif
+ for (i = 0; i < nfds; i++)
+ {
+ kfds[i].fd = fds[i].fd;
+ kfds[i].events = (uint16_t)fds[i].events;
Review Comment:
remove the cast
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]