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

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

commit 915c8fa5d8566c96a7acc92256a95f3a81952e5a
Author: likun17 <[email protected]>
AuthorDate: Tue Apr 28 21:14:24 2026 +0800

    drivers/sensors/sensor_rpmsg: Release the rx buffer before handling.
    
    The handlers hold the rpmsg rx buffer while they look up the device,
    allocate proxies and stubs and send replies, so under load the remote
    core runs out of buffers to send with.
    
    Except for PUBLISH, copy the message to the stack, release the rx
    buffer and return RPMSG_SUCCESS_BUFFER_RELEASED. PUBLISH keeps using
    the rx buffer to avoid copying the sample data.
    
    Signed-off-by: likun17 <[email protected]>
---
 drivers/sensors/sensor_rpmsg.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/sensors/sensor_rpmsg.c b/drivers/sensors/sensor_rpmsg.c
index ac1fb538b2f..d9d1123975d 100644
--- a/drivers/sensors/sensor_rpmsg.c
+++ b/drivers/sensors/sensor_rpmsg.c
@@ -1573,14 +1573,24 @@ static int sensor_rpmsg_ept_cb(FAR struct 
rpmsg_endpoint *ept,
                                FAR void *priv)
 {
   FAR struct sensor_rpmsg_advsub_s *msg = data;
+  uint32_t command = msg->command;
 
-  if (msg->command < sizeof(g_sensor_rpmsg_handler) /
-                     sizeof(g_sensor_rpmsg_handler[0]))
+  /* For publish handler, use the original rx buffer directly to avoid
+   * extra copy. For all other handlers, copy data to a temporary stack
+   * buffer and release the rx buffer early.
+   */
+
+  if (command != SENSOR_RPMSG_PUBLISH)
     {
-      return g_sensor_rpmsg_handler[msg->command](ept, data, len, src, priv);
+      FAR void *tmp = alloca(len);
+
+      memcpy(tmp, data, len);
+      rpmsg_release_rx_buffer(ept, data);
+      g_sensor_rpmsg_handler[command](ept, tmp, len, src, priv);
+      return RPMSG_SUCCESS_BUFFER_RELEASED;
     }
 
-  return -EINVAL;
+  return g_sensor_rpmsg_handler[command](ept, data, len, src, priv);
 }
 
 static void sensor_rpmsg_bound_worker(FAR void *arg)

Reply via email to