This is an automated email from the ASF dual-hosted git repository. jerpelea pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 430125506403b9f088791f04618570c11737f6ee Author: p-szafonimateusz <[email protected]> AuthorDate: Wed Oct 28 15:11:28 2026 +0100 drivers/can/ctucanfd_pci.c: Pad CAN FD TX data to the frame length. For CAN FD frames the controller sends can_dlc2bytes(dlc) bytes, which is more than the frame length when it is not a valid CAN FD length (for example 25 bytes are sent as 32). Only the frame length was written, so the rest came from stale TX buffer contents. Write the whole length the controller sends, padded with zeros. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: p-szafonimateusz <[email protected]> --- drivers/can/ctucanfd_pci.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/can/ctucanfd_pci.c b/drivers/can/ctucanfd_pci.c index 60026cfd814..67f81323265 100644 --- a/drivers/can/ctucanfd_pci.c +++ b/drivers/can/ctucanfd_pci.c @@ -1117,6 +1117,9 @@ static int ctucanfd_sock_transmit(FAR struct netdev_lowerhalf_s *dev, uint32_t offset; int txidx; int i; +#ifdef CONFIG_NET_CAN_CANFD + int wirelen; +#endif /* Get TX empty buffer */ @@ -1234,11 +1237,15 @@ static int ctucanfd_sock_transmit(FAR struct netdev_lowerhalf_s *dev, ctucanfd_putreg(priv, offset + CTUCANFD_TXBUF_TSL, 0); ctucanfd_putreg(priv, offset + CTUCANFD_TXBUF_TSU, 0); - /* Pack bytes into aligned register writes and pad the final word. */ + /* Pack bytes into aligned register writes. The controller sends + * can_dlc2bytes(dlc) bytes, which can be more than frame->len, so + * pad up to that length with zeros. + */ - for (i = 0; i < frame->len; i += 4) + wirelen = can_dlc2bytes(fmt.s.dlc); + for (i = 0; i < wirelen; i += 4) { - regval = (uint32_t)frame->data[i]; + regval = (uint32_t)(i < frame->len ? frame->data[i] : 0); regval |= (uint32_t)(i + 1 < frame->len ? frame->data[i + 1] : 0) << 8; regval |= (uint32_t)(i + 2 < frame->len ? frame->data[i + 2] : 0)
