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

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

commit 8a3862995912c8ed6a71ca093c00dad971d5bb38
Author: raiden00pl <[email protected]>
AuthorDate: Thu Oct 22 18:17:12 2026 +0200

    drivers/can/can.c: Do not fail flush ioctls the lower half ignores.
    
    CANIOC_IFLUSH, CANIOC_OFLUSH and CANIOC_IOFLUSH flush the upper-half
    buffers but returned the lower-half result, so they failed with ENOTTY
    with lower halves that do not handle them (sim, ctucanfd, kvaser).
    include/nuttx/can/can.h: "Zero (OK) is returned on success".  Treat
    -ENOTTY as success, as drivers/bch/bchdev_driver.c does for BIOC_FLUSH.
    
    Assisted-by: Claude:claude-opus-5-5
    Signed-off-by: raiden00pl <[email protected]>
---
 drivers/can/can.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/can/can.c b/drivers/can/can.c
index 87215c72e5a..a5e4a394943 100644
--- a/drivers/can/can.c
+++ b/drivers/can/can.c
@@ -903,6 +903,24 @@ static void can_rxfifo_flush(FAR struct can_rxfifo_s *fifo)
   nxsem_reset(&fifo->rx_sem, 0);
 }
 
+/****************************************************************************
+ * Name: can_flush_ioctl
+ *
+ * Description:
+ *   Pass a flush command to the lower half.  The upper half has already
+ *   flushed its own buffers, so a lower half that does not handle the
+ *   command (-ENOTTY) is not an error.
+ *
+ ****************************************************************************/
+
+static int can_flush_ioctl(FAR struct can_dev_s *dev, int cmd,
+                           unsigned long arg)
+{
+  int ret = dev_ioctl(dev, cmd, arg);
+
+  return ret == -ENOTTY ? OK : ret;
+}
+
 /****************************************************************************
  * Name: can_rtrread
  *
@@ -1043,7 +1061,7 @@ static int can_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
 
           /* invoke lower half ioctl */
 
-          ret = dev_ioctl(dev, cmd, arg);
+          ret = can_flush_ioctl(dev, cmd, arg);
         }
         break;
 
@@ -1055,7 +1073,7 @@ static int can_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
 
           /* invoke lower half ioctl */
 
-          ret = dev_ioctl(dev, cmd, arg);
+          ret = can_flush_ioctl(dev, cmd, arg);
         }
         break;
 
@@ -1070,7 +1088,7 @@ static int can_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
 
           /* invoke lower half ioctl */
 
-          ret = dev_ioctl(dev, cmd, arg);
+          ret = can_flush_ioctl(dev, cmd, arg);
         }
         break;
 

Reply via email to