You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/11/06 17:39:27 UTC

[GitHub] [incubator-nuttx] xiaoxiang781216 opened a new pull request, #7539: Correct epoll lock usage

xiaoxiang781216 opened a new pull request, #7539:
URL: https://github.com/apache/incubator-nuttx/pull/7539

   ## Summary
   
   - vfs/epoll: Replace sem_t with mutex_t for locking usage 
   - vfs/epoll: Protect epoll_ctl by mutex 
   
   ## Impact
   epoll
   
   ## Testing
   
   


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #7539: Correct epoll lock usage

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7539:
URL: https://github.com/apache/incubator-nuttx/pull/7539#discussion_r1016086031


##########
fs/vfs/fs_epoll.c:
##########
@@ -180,10 +181,11 @@ static int epoll_do_create(int size, int flags)
   if (eph == NULL)
     {
       set_errno(ENOMEM);
-      return -1;
+      return ERROR;
     }
 
-  nxsem_init(&eph->sem, 0, 0);

Review Comment:
   It isn't a problem since the user can't do anything before we return fd from epoll_do_open.



-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] pkarashchenko commented on a diff in pull request #7539: Correct epoll lock usage

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7539:
URL: https://github.com/apache/incubator-nuttx/pull/7539#discussion_r1015167766


##########
fs/vfs/fs_epoll.c:
##########
@@ -201,13 +203,12 @@ static int epoll_do_create(int size, int flags)
   fd = file_allocate(&g_epoll_inode, flags, 0, eph, 0, true);
   if (fd < 0)
     {
-      nxsem_destroy(&eph->sem);
+      nxmutex_destroy(&eph->lock);
       kmm_free(eph);
       set_errno(-fd);
       return -1;

Review Comment:
   Should we use `ERROR` and `OK`?



##########
fs/vfs/fs_epoll.c:
##########
@@ -277,6 +278,7 @@ void epoll_close(int epfd)
 int epoll_ctl(int epfd, int op, int fd, struct epoll_event *ev)

Review Comment:
   ```suggestion
   int epoll_ctl(int epfd, int op, int fd, FAR struct epoll_event *ev)
   ```



##########
fs/vfs/fs_epoll.c:
##########
@@ -352,19 +360,26 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event *ev)
 
         if (i > eph->occupied)
           {
-            set_errno(ENOENT);
-            return -1;
+            ret = -ENOENT;
+            goto err;
           }
 
         break;
 
       default:
-        set_errno(EINVAL);
-        return -1;
+        ret = -EINVAL;
+        goto err;
     }
 
+  nxmutex_unlock(&eph->lock);
   poll_notify(&eph->poll, 1, POLLIN);
   return 0;
+
+err:
+  nxmutex_unlock(&eph->lock);
+err_without_lock:
+  set_errno(-ret);
+  return -1;

Review Comment:
   should we use `ERROR` and `OK`?



-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] pkarashchenko commented on a diff in pull request #7539: Correct epoll lock usage

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7539:
URL: https://github.com/apache/incubator-nuttx/pull/7539#discussion_r1015880486


##########
fs/vfs/fs_epoll.c:
##########
@@ -180,10 +181,11 @@ static int epoll_do_create(int size, int flags)
   if (eph == NULL)
     {
       set_errno(ENOMEM);
-      return -1;
+      return ERROR;
     }
 
-  nxsem_init(&eph->sem, 0, 0);

Review Comment:
   The new behavior is a bit different from the original one. I do not think that should matter, but in "old" code the semaphore kept locked after init and only unlocked before return. Do we need to take lock and hold until `file_allocate` return `OK`?



-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] pkarashchenko merged pull request #7539: Correct epoll lock usage

Posted by GitBox <gi...@apache.org>.
pkarashchenko merged PR #7539:
URL: https://github.com/apache/incubator-nuttx/pull/7539


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #7539: Correct epoll lock usage

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7539:
URL: https://github.com/apache/incubator-nuttx/pull/7539#discussion_r1015371598


##########
fs/vfs/fs_epoll.c:
##########
@@ -352,19 +360,26 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event *ev)
 
         if (i > eph->occupied)
           {
-            set_errno(ENOENT);
-            return -1;
+            ret = -ENOENT;
+            goto err;
           }
 
         break;
 
       default:
-        set_errno(EINVAL);
-        return -1;
+        ret = -EINVAL;
+        goto err;
     }
 
+  nxmutex_unlock(&eph->lock);
   poll_notify(&eph->poll, 1, POLLIN);
   return 0;
+
+err:
+  nxmutex_unlock(&eph->lock);
+err_without_lock:
+  set_errno(-ret);
+  return -1;

Review Comment:
   Done.



##########
fs/vfs/fs_epoll.c:
##########
@@ -277,6 +278,7 @@ void epoll_close(int epfd)
 int epoll_ctl(int epfd, int op, int fd, struct epoll_event *ev)

Review Comment:
   Done.



##########
fs/vfs/fs_epoll.c:
##########
@@ -201,13 +203,12 @@ static int epoll_do_create(int size, int flags)
   fd = file_allocate(&g_epoll_inode, flags, 0, eph, 0, true);
   if (fd < 0)
     {
-      nxsem_destroy(&eph->sem);
+      nxmutex_destroy(&eph->lock);
       kmm_free(eph);
       set_errno(-fd);
       return -1;

Review Comment:
   Done.



-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org