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 e2fa8e24129597c2b1fc29e233f2ab768435a231
Author: zhaoxingyu1 <[email protected]>
AuthorDate: Sun Apr 26 12:56:52 2026 +0800

    drivers/misc/rpmsgdev: forward the configdata ioctls
    
    struct config_data_s carries a pointer to the data, which cannot cross
    cores. For CFGDIOC_GETCONFIG..CFGDIOC_NEXTCONFIG copy the data inline
    after the struct on the client, rebuild the struct on the server, and
    copy the data, name and length back into the caller's struct.
    
    Signed-off-by: zhaoxingyu1 <[email protected]>
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/misc/rpmsgdev.c        | 75 ++++++++++++++++++++++++++++++++++++++++--
 drivers/misc/rpmsgdev_server.c | 17 ++++++++--
 2 files changed, 87 insertions(+), 5 deletions(-)

diff --git a/drivers/misc/rpmsgdev.c b/drivers/misc/rpmsgdev.c
index d74a269778e..bbfa4f73533 100644
--- a/drivers/misc/rpmsgdev.c
+++ b/drivers/misc/rpmsgdev.c
@@ -48,6 +48,7 @@
 #include <nuttx/drivers/rpmsgdev.h>
 #include <nuttx/power/battery_ioctl.h>
 #include <nuttx/input/mouse.h>
+#include <nuttx/mtd/configdata.h>
 
 #include "rpmsgdev.h"
 
@@ -574,6 +575,53 @@ static off_t rpmsgdev_seek(FAR struct file *filep, off_t 
offset, int whence)
   return ret;
 }
 
+/****************************************************************************
+ * Name: rpmsgdev_marshal_cfgdata
+ ****************************************************************************/
+
+static void rpmsgdev_marshal_cfgdata(FAR void *buf, FAR void *cfg)
+{
+  FAR struct config_data_s *src = (FAR struct config_data_s *)cfg;
+  FAR struct config_data_s *dst = (FAR struct config_data_s *)buf;
+
+#ifdef CONFIG_MTD_CONFIG_NAMED
+  memcpy(dst->name, src->name, sizeof(dst->name));
+#else
+  dst->id = src->id;
+  dst->instance = src->instance;
+#endif
+  dst->len = src->len;
+  dst->configdata = (FAR uint8_t *)(dst + 1);
+  if (src->configdata != NULL && src->len > 0)
+    {
+      memcpy(dst->configdata, src->configdata, src->len);
+    }
+}
+
+/****************************************************************************
+ * Name: rpmsgdev_unmarshal_cfgdata
+ ****************************************************************************/
+
+static void rpmsgdev_unmarshal_cfgdata(FAR void *buf, FAR void *cfg)
+{
+  FAR struct config_data_s *src = (FAR struct config_data_s *)buf;
+  FAR struct config_data_s *dst = (FAR struct config_data_s *)cfg;
+
+  if (dst->configdata != NULL && src->len > 0)
+    {
+      memcpy(dst->configdata, (FAR uint8_t *)(src + 1),
+             MIN(src->len, dst->len));
+    }
+
+#ifdef CONFIG_MTD_CONFIG_NAMED
+  memcpy(dst->name, src->name, sizeof(dst->name));
+#else
+  dst->id = src->id;
+  dst->instance = src->instance;
+#endif
+  dst->len = src->len;
+}
+
 /****************************************************************************
  * Name: rpmsgdev_ioctl_arglen
  *
@@ -620,6 +668,14 @@ static ssize_t rpmsgdev_ioctl_arglen(int cmd, unsigned 
long arg)
                ((FAR struct mouse_vendor_cmd_s *)(uintptr_t)arg)->len;
       case MSIOC_GRAB:
         return 0;
+      case CFGDIOC_GETCONFIG:
+      case CFGDIOC_SETCONFIG:
+      case CFGDIOC_FIRSTCONFIG:
+      case CFGDIOC_NEXTCONFIG:
+        return sizeof(struct config_data_s) +
+               ((FAR struct config_data_s *)(uintptr_t)arg)->len;
+      case CFGDIOC_DELCONFIG:
+        return sizeof(struct config_data_s);
       case RPMSGDEV_PRIVATE_IOCTL:
         return sizeof(struct rpmsgdev_private_ioctl) +
                ((FAR struct rpmsgdev_private_ioctl *)(uintptr_t)arg)->len;
@@ -701,7 +757,14 @@ static int rpmsgdev_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
 
   if (arglen > 0)
     {
-      memcpy(msg->buf, argp, arglen);
+      if (cmd >= CFGDIOC_GETCONFIG && cmd <= CFGDIOC_NEXTCONFIG)
+        {
+          rpmsgdev_marshal_cfgdata(msg->buf, argp);
+        }
+      else
+        {
+          memcpy(msg->buf, argp, arglen);
+        }
     }
 
   return rpmsgdev_send_recv(dev, RPMSGDEV_IOCTL, false, &msg->header,
@@ -989,7 +1052,15 @@ static int rpmsgdev_ioctl_handler(FAR struct 
rpmsg_endpoint *ept,
   cookie->result = header->result;
   if (cookie->result >= 0 && rsp->arglen > 0)
     {
-      memcpy(cookie->data, rsp->buf, rsp->arglen);
+      if (rsp->request >= CFGDIOC_GETCONFIG &&
+          rsp->request <= CFGDIOC_NEXTCONFIG)
+        {
+          rpmsgdev_unmarshal_cfgdata(rsp->buf, cookie->data);
+        }
+      else
+        {
+          memcpy(cookie->data, rsp->buf, rsp->arglen);
+        }
     }
 
   rpmsg_post(ept, &cookie->sem);
diff --git a/drivers/misc/rpmsgdev_server.c b/drivers/misc/rpmsgdev_server.c
index 68e8d879fac..d667b18efc9 100644
--- a/drivers/misc/rpmsgdev_server.c
+++ b/drivers/misc/rpmsgdev_server.c
@@ -39,6 +39,7 @@
 #include <nuttx/wqueue.h>
 #include <nuttx/drivers/rpmsgdev.h>
 #include <nuttx/rpmsg/rpmsg.h>
+#include <nuttx/mtd/configdata.h>
 
 #include "rpmsgdev.h"
 
@@ -478,9 +479,19 @@ static int rpmsgdev_ioctl_handler(FAR struct 
rpmsg_endpoint *ept,
   FAR struct rpmsgdev_ioctl_s *msg = data;
   FAR struct file *filep = (FAR struct file *)(uintptr_t)msg->filep;
 
-  msg->header.result = file_ioctl(filep, msg->request,
-                                  msg->arglen == 0 ? msg->arg :
-                                  (unsigned long)msg->buf);
+  if (msg->request >= CFGDIOC_GETCONFIG &&
+      msg->request <= CFGDIOC_NEXTCONFIG &&
+      msg->arglen != (sizeof(struct config_data_s) +
+      ((FAR struct config_data_s *)msg->buf)->len))
+    {
+      msg->header.result = -EMSGSIZE;
+    }
+  else
+    {
+      msg->header.result = file_ioctl(filep, msg->request,
+                                      msg->arglen == 0 ? msg->arg :
+                                      (unsigned long)(FAR void *)msg->buf);
+    }
 
   return rpmsg_send(ept, msg, len);
 }

Reply via email to