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 cb26015ee179f4ca4e65f8df78ebb57e67e94e90
Author: raiden00pl <[email protected]>
AuthorDate: Sat Oct 10 15:40:07 2026 +0200

    drivers/can/can.c: Fix FIONREAD result type and FIFO wrap.
    
    FIONREAD wrote the count through a uint8_t pointer, but
    include/nuttx/fs/ioctl.h defines its argument as int *.  The count
    was also negative once the RX FIFO had wrapped.
    
    Write an int and handle the wrap.  Callers that passed a uint8_t
    must pass an int now.  The result is still the number of queued
    messages, not bytes.
    
    Assisted-by: Claude:claude-opus-5-5
    Signed-off-by: raiden00pl <[email protected]>
---
 drivers/can/can.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/can/can.c b/drivers/can/can.c
index 445e2c83282..d01647dcac0 100644
--- a/drivers/can/can.c
+++ b/drivers/can/can.c
@@ -1044,11 +1044,18 @@ static int can_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
 
       case FIONREAD:
         {
-          *(FAR uint8_t *)arg =
+          int count = reader->fifo.rx_tail - reader->fifo.rx_head;
+
+          if (count < 0)
+            {
+              count += CONFIG_CAN_RXFIFOSIZE;
+            }
+
 #ifdef CONFIG_CAN_ERRORS
-                            (reader->fifo.rx_error != 0) +
+          count += (reader->fifo.rx_error != 0);
 #endif
-                            reader->fifo.rx_tail - reader->fifo.rx_head;
+
+          *(FAR int *)arg = count;
         }
         break;
 

Reply via email to