RTEMS | bsps/shared/dev/can/ctucanfd/ctucanfd.c: CAN error frame bugs (#5654)

Avi Weiss (@thnkslprpt) gitlab at rtems.org
Mon Jul 20 12:46:49 UTC 2026



Issue created by Avi Weiss: https://gitlab.rtems.org/rtems/rtos/rtems/-/work_items/5654



## Summary
It looks like in `bsps/shared/dev/can/ctucanfd/ctucanfd.c` there are a couple of bugs in `ctucanfd_err_interrupt` when it’s building the CAN error frame (`err_frame`).   

In this block:
```c
  /* Check for RX overflow interrupt */
  if ( FIELD_GET( REG_INT_STAT_DOI, isr ) ) {
    rtems_can_stats_add_rx_overflows( &chip->chip_stats );
    ctucanfd_write32( internal, CTUCANFD_TX_COMMAND, REG_COMMAND_CDO );
    err_frame.header.can_id |= CAN_ERR_ID_CRTL;
    err_frame.header.flags |= CAN_FRAME_ERR;
    err_frame.data[ CAN_ERR_ID_LOSTARB ] |= CAN_ERR_CRTL_RX_OVERFLOW;
  }
```

It mixes up an `err_frame.header.can_id` macro with a `err_frame.data` macro. (`CAN_ERR_ID_LOSTARB` instead of `CAN_ERR_DATA_BYTE_TRX_CTRL`)  

This ends up resulting in the wrong index being accessed (`data[2] `instead of `data[1]`) - so it assigns an error to the wrong byte.  

There is also another issue in the same block I think.  

When clearing the data overrun, it writes to the wrong register (`CTUCANFD_TX_COMMAND` instead of `CTUCANFD_COMMAND`)  

You can see the correct combination in the upstream linux version at [this link](https://github.com/torvalds/linux/blob/1229e2e57a5c2980ccd457b9b53ea0eed5a22ab3/drivers/net/can/ctucanfd/ctucanfd_base.c#L960). `ctucan_rx_poll` is where it handles the RX-overflow part of `ctucanfd_err_interrupt`.  
```c
cf->can_id |= CAN_ERR_CRTL;
cf->data[1] |= CAN_ERR_CRTL_RX_OVERFLOW;
...
/* Clear Data Overrun */ ctucan_write32( priv, CTUCANFD_COMMAND, REG_COMMAND_CDO );
```

(First issue/code also exists in `bsps/shared/dev/can/sja1000/sja1000.c` but it looks like the 2nd issue is already corrected there or maybe was always correct).

-- 
View it on GitLab: https://gitlab.rtems.org/rtems/rtos/rtems/-/work_items/5654
You're receiving this email because of your account on gitlab.rtems.org. Unsubscribe from this thread: https://gitlab.rtems.org/-/sent_notifications/4-9cw4k6j5ibfl7er852c57p82d-1d/unsubscribe | Manage all notifications: https://gitlab.rtems.org/-/profile/notifications | Help: https://gitlab.rtems.org/help


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/bugs/attachments/20260720/660408c6/attachment.htm>


More information about the bugs mailing list