Commit 561aa5b4 authored by Marc Kleine-Budde's avatar Marc Kleine-Budde

can: mcp251xfd: mcp251xfd_tx_obj_from_skb(): clean up padding of CAN-FD frames

CAN-FD frames have only specific frame length (0, 1, 2, 3, 4, 5, 6, 7, 8, 12,
16, 20, 24, 32, 48, 64). A CAN-FD frame provided by user space might not cover
the whole CAN-FD frame. To avoid sending garbage over the CAN bus the driver
pads the CAN frame with 0x0 (if MCP251XFD_SANITIZE_CAN is activated).

This patch cleans up the pad len calculation. Rounding to full u32 brings no
benefit, in case of CRC transfers, the hw_tx_obj->data is not aligned to u32
anyway.

Link: https://lore.kernel.org/r/20210114153448.1506901-3-mkl@pengutronix.deSigned-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent 9845b8f5
......@@ -2303,7 +2303,7 @@ mcp251xfd_tx_obj_from_skb(const struct mcp251xfd_priv *priv,
union mcp251xfd_tx_obj_load_buf *load_buf;
u8 dlc;
u32 id, flags;
int offset, len;
int pad_len, len;
if (cfd->can_id & CAN_EFF_FLAG) {
u32 sid, eid;
......@@ -2351,13 +2351,14 @@ mcp251xfd_tx_obj_from_skb(const struct mcp251xfd_priv *priv,
put_unaligned_le32(id, &hw_tx_obj->id);
put_unaligned_le32(flags, &hw_tx_obj->flags);
/* Clear data at end of CAN frame */
offset = round_down(cfd->len, sizeof(u32));
len = round_up(can_fd_dlc2len(dlc), sizeof(u32)) - offset;
if (MCP251XFD_SANITIZE_CAN && len)
memset(hw_tx_obj->data + offset, 0x0, len);
/* Copy data */
memcpy(hw_tx_obj->data, cfd->data, cfd->len);
/* Clear unused data at end of CAN frame */
pad_len = can_fd_dlc2len(dlc) - cfd->len;
if (MCP251XFD_SANITIZE_CAN && pad_len)
memset(hw_tx_obj->data + cfd->len, 0x0, pad_len);
/* Number of bytes to be written into the RAM of the controller */
len = sizeof(hw_tx_obj->id) + sizeof(hw_tx_obj->flags);
if (MCP251XFD_SANITIZE_CAN)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment