This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 851511d2b33fd98fee5a071cf25f949a92820c37
Author: Xiang Xiao <[email protected]>
AuthorDate: Sat Apr 19 18:52:24 2025 +0800

    drivers/misc/rpmsgdev: always handle FIONBIO locally
    
    The server reads and writes the exported device from the rpmsg work
    queue, so the device on the server side must stay non-blocking. Keep
    the O_NONBLOCK state of the client file in the client and do not
    forward FIONBIO to the server.
    
    Signed-off-by: Xiang Xiao <[email protected]>
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/misc/rpmsgdev.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/drivers/misc/rpmsgdev.c b/drivers/misc/rpmsgdev.c
index dce851f13eb..b92f0bdb117 100644
--- a/drivers/misc/rpmsgdev.c
+++ b/drivers/misc/rpmsgdev.c
@@ -604,7 +604,6 @@ static ssize_t rpmsgdev_ioctl_arglen(int cmd, unsigned long 
arg)
 {
   switch (cmd)
     {
-      case FIONBIO:
       case FIONWRITE:
       case FIONREAD:
       case FIONSPACE:
@@ -657,10 +656,10 @@ static int rpmsgdev_ioctl(FAR struct file *filep, int 
cmd, unsigned long arg)
   FAR struct rpmsgdev_s *dev;
   FAR struct rpmsgdev_priv_s *priv;
   FAR struct rpmsgdev_ioctl_s *msg;
+  FAR void *argp = (FAR void *)(uintptr_t)arg;
   uint32_t space;
   ssize_t arglen;
   size_t msglen;
-  int ret;
 
   /* Recover our private data from the struct file instance */
 
@@ -668,6 +667,19 @@ static int rpmsgdev_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
   priv = filep->f_priv;
   DEBUGASSERT(dev != NULL && priv != NULL);
 
+  /* Always handle FIONBIO locally since the remote side
+   * must always be in non-blocking mode to avoid blocking
+   * the rpmsg work thread.
+   */
+
+  if (cmd == FIONBIO)
+    {
+      FAR int *nonblock = (FAR int *)argp;
+
+      priv->nonblock = *nonblock;
+      return 0;
+    }
+
   /* Call our internal routine to perform the ioctl */
 
   arglen = rpmsgdev_ioctl_arglen(cmd, arg);
@@ -691,19 +703,11 @@ static int rpmsgdev_ioctl(FAR struct file *filep, int 
cmd, unsigned long arg)
 
   if (arglen > 0)
     {
-      memcpy(msg->buf, (FAR void *)(uintptr_t)arg, arglen);
+      memcpy(msg->buf, argp, arglen);
     }
 
-  ret = rpmsgdev_send_recv(dev, RPMSGDEV_IOCTL, false, &msg->header,
-                           msglen, arglen > 0 ? (FAR void *)arg : NULL);
-  if (cmd == FIONBIO && ret >= 0)
-    {
-      FAR int *nonblock = (FAR int *)(uintptr_t)arg;
-
-      priv->nonblock = *nonblock;
-    }
-
-  return ret;
+  return rpmsgdev_send_recv(dev, RPMSGDEV_IOCTL, false, &msg->header,
+                            msglen, arglen > 0 ? argp : NULL);
 }
 
 /****************************************************************************

Reply via email to