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 e993f0f012dc23b9083a02ec17bc52ff96ab2740
Author: likun17 <[email protected]>
AuthorDate: Tue Oct 27 22:11:41 2026 +0800

    drivers/sensors: Add SNIOC_DISCARD to drop unread data.
    
    sensor_rpmsg_publish_handler() drops the data it published on behalf
    of a remote core with file_read(filep, NULL, len). file_readv() now
    rejects a NULL buffer with a non-zero length, so the data stays unread
    and is sent back to the remote subscribers again.
    
    Add SNIOC_DISCARD, which moves the caller's read position past the
    unread data without copying it, and use it in the publish handler.
    
    Signed-off-by: likun17 <[email protected]>
---
 drivers/sensors/sensor.c       | 27 +++++++++++++++++++++++++++
 drivers/sensors/sensor_rpmsg.c |  2 +-
 include/nuttx/sensors/ioctl.h  |  9 +++++++++
 3 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/drivers/sensors/sensor.c b/drivers/sensors/sensor.c
index 3df8e7619a1..18354bfff71 100644
--- a/drivers/sensors/sensor.c
+++ b/drivers/sensors/sensor.c
@@ -1169,6 +1169,33 @@ static int sensor_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
         }
         break;
 
+      case SNIOC_DISCARD:
+        {
+          if (arg == 0)
+            {
+              ret = -EINVAL;
+              break;
+            }
+
+          /* Fetch-based drivers keep no circular buffer to skip over */
+
+          if (lower->ops->fetch)
+            {
+              ret = -ENOTSUP;
+              break;
+            }
+
+          nxrmutex_lock(&upper->lock);
+          if (!circbuf_is_empty(&upper->buffer) &&
+              sensor_is_updated(upper, user))
+            {
+              ret = sensor_do_samples(upper, user, NULL, arg);
+            }
+
+          nxrmutex_unlock(&upper->lock);
+        }
+        break;
+
       case SNIOC_GET_INFO:
         {
           if (lower->ops->get_info == NULL)
diff --git a/drivers/sensors/sensor_rpmsg.c b/drivers/sensors/sensor_rpmsg.c
index 97951935e64..293956f036c 100644
--- a/drivers/sensors/sensor_rpmsg.c
+++ b/drivers/sensors/sensor_rpmsg.c
@@ -1503,7 +1503,7 @@ static int sensor_rpmsg_publish_handler(FAR struct 
rpmsg_endpoint *ept,
       list_for_every_entry_safe(&dev->stublist, stub, stmp,
                                 struct sensor_rpmsg_stub_s, node)
         {
-          file_read(&stub->file, NULL, cell->len);
+          file_ioctl(&stub->file, SNIOC_DISCARD, cell->len);
         }
 
       sensor_rpmsg_unlock(dev);
diff --git a/include/nuttx/sensors/ioctl.h b/include/nuttx/sensors/ioctl.h
index 6fef65c879a..ba48589b339 100644
--- a/include/nuttx/sensors/ioctl.h
+++ b/include/nuttx/sensors/ioctl.h
@@ -533,6 +533,15 @@
 
 #define SNIOC_GNSS_SET_PRIORITY       _SNIOC(0x00AA)
 
+/* Command:      SNIOC_DISCARD
+ * Description:  Discard unread data of the caller, as if it had been read
+ *               but without copying it out. Other users are not affected.
+ * Argument:     Maximum number of bytes to discard.
+ * Return:       Number of bytes discarded, or a negated errno value.
+ */
+
+#define SNIOC_DISCARD                 _SNIOC(0x00AB)
+
 /****************************************************************************
  * Public types
  ****************************************************************************/

Reply via email to