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 eaa8c2e07e9b22a70fbe45d91ffa25c9776f9f63
Author: likun17 <[email protected]>
AuthorDate: Tue Aug 5 15:20:00 2025 +0800

    drivers/sensors: Return -ENOTTY for unsupported ioctls.
    
    The sensor upper half, sensor_rpmsg and gnss return -ENOTSUP when the
    lower half does not implement the callback of an ioctl. -ENOTTY is the
    error for an ioctl that a driver does not support, and is what
    sensor_rpmsg_control() already checks to forward a command to the
    remote core.
    
    Return -ENOTTY in these cases, and check for -ENOTTY where the flush
    result is converted for local callers.
    
    Signed-off-by: likun17 <[email protected]>
---
 drivers/sensors/gnss_uorb.c    |  2 +-
 drivers/sensors/sensor.c       | 14 +++++++-------
 drivers/sensors/sensor_rpmsg.c | 10 +++++-----
 3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/sensors/gnss_uorb.c b/drivers/sensors/gnss_uorb.c
index e1d44b08c3c..0434183cb57 100644
--- a/drivers/sensors/gnss_uorb.c
+++ b/drivers/sensors/gnss_uorb.c
@@ -385,7 +385,7 @@ static ssize_t gnss_write(FAR struct file *filep, FAR const 
char *buffer,
                           size_t buflen)
 {
   FAR struct gnss_upperhalf_s *upper;
-  int ret = -ENOTSUP;
+  int ret = -ENOTTY;
 
   upper = filep->f_inode->i_private;
 
diff --git a/drivers/sensors/sensor.c b/drivers/sensors/sensor.c
index 76781acc0a1..4f162e7728e 100644
--- a/drivers/sensors/sensor.c
+++ b/drivers/sensors/sensor.c
@@ -1043,7 +1043,7 @@ static int sensor_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
         {
           if (lower->ops->selftest == NULL)
             {
-              ret = -ENOTSUP;
+              ret = -ENOTTY;
               break;
             }
 
@@ -1055,7 +1055,7 @@ static int sensor_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
         {
           if (lower->ops->set_calibvalue == NULL)
             {
-              ret = -ENOTSUP;
+              ret = -ENOTTY;
               break;
             }
 
@@ -1067,7 +1067,7 @@ static int sensor_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
         {
           if (lower->ops->calibrate == NULL)
             {
-              ret = -ENOTSUP;
+              ret = -ENOTTY;
               break;
             }
 
@@ -1125,7 +1125,7 @@ static int sensor_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
         {
           if (lower->ops->get_info == NULL)
             {
-              ret = -ENOTSUP;
+              ret = -ENOTTY;
               break;
             }
 
@@ -1154,7 +1154,7 @@ static int sensor_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
               return -EINVAL;
             }
 
-          ret = -ENOTSUP;
+          ret = -ENOTTY;
           if (lower->ops->flush != NULL)
             {
               /* Lower half driver will do flush in asynchronous mode,
@@ -1170,7 +1170,7 @@ static int sensor_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
                 }
             }
 
-          if (ret == -ENOTSUP)
+          if (ret == -ENOTTY)
             {
               /* If flush is not supported, complete immediately */
 
@@ -1178,7 +1178,7 @@ static int sensor_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
               user->event |= SENSOR_EVENT_FLUSH_COMPLETE;
               sensor_pollnotify_one(user, POLLPRI, user->role);
 
-              /* If caller isn't from remote core, convert ENOTSUP
+              /* If caller isn't from remote core, convert ENOTTY
                * to zero return, indicating the flush is completed.
                * If it's from remote core, need to inform the remote
                * core the flush is not supported for driver.
diff --git a/drivers/sensors/sensor_rpmsg.c b/drivers/sensors/sensor_rpmsg.c
index 752a1baea82..61bba3c58d6 100644
--- a/drivers/sensors/sensor_rpmsg.c
+++ b/drivers/sensors/sensor_rpmsg.c
@@ -75,7 +75,7 @@ static int sensor_rpmsg_##name(FAR struct sensor_lowerhalf_s 
*lower, \
     } \
   else \
     { \
-      return wait ? -ENOTSUP : 0; \
+      return wait ? -ENOTTY : 0; \
     } \
 } \
 
@@ -923,10 +923,10 @@ static int sensor_rpmsg_flush(FAR struct 
sensor_lowerhalf_s *lower,
       /* If the driver (drv) does not support the flush operation,
        * and the caller is a remote invocation or the current device
        * is an advertiser, then you can still consider the flush
-       * operation as unsupported and therefore return ENOTSUP
+       * operation as unsupported and therefore return ENOTTY
        */
 
-      return -ENOTSUP;
+      return -ENOTTY;
     }
   else
     {
@@ -956,10 +956,10 @@ static int sensor_rpmsg_set_wakeup(FAR struct 
sensor_lowerhalf_s *lower,
       /* If the driver (drv) does not support the wakeup operation,
        * and the caller is a remote invocation or the current device
        * is an advertiser, then you can still consider the wakeup
-       * operation as unsupported and therefore return ENOTSUP
+       * operation as unsupported and therefore return ENOTTY
        */
 
-      return -ENOTSUP;
+      return -ENOTTY;
     }
   else
     {

Reply via email to