net: hip04: use 16-bit byte order for HI13X1 TX fields
Subsystems (3)
PATCH v2 1/1 net: hip04: use 16-bit byte order for HI13X1 TX fields
The HI13X1 TX descriptor stores send_size and data_offset in 16-bit fields, unlike the 32-bit send_size field in the other descriptor layout. The transmit path nevertheless converts both HI13X1 fields with cpu_to_be32() before assigning them to u16 members.
On a little-endian CPU, the conversion moves these small values into the upper half of the 32-bit result and the assignment discards that half. The descriptor consequently loses the packet size and cache-line offset.
Use cpu_to_be16() for the two HI13X1 fields. Leave the other layout's 32-bit size conversion unchanged.
The issue was found by our static-analysis tool.
---
Changes since v1:
https://lore.kernel.org/all/[email protected]/
Use the full author name. Clarify the HI13X1/little-endian scope in response to Simon. The finding came from source analysis; there is no established explanation for why it remained unnoticed since 2019.
drivers/net/ethernet/hisilicon/hip04_eth.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/ethernet/hisilicon/hip04_eth.c +3 -2
@@ -527,13 +527,14 @@ hip04_mac_start_xmit(struct sk_buff *skb, struct net_device *ndev) priv->tx_skb[tx_head] = skb; priv->tx_phys[tx_head] = phys; - desc->send_size = (__force u32 )cpu_to_be32 (skb->len);#if defined(CONFIG_HI13X1_GMAC ) + desc->send_size = (__force u16 )cpu_to_be16 (skb->len); desc->cfg = (__force u32 )cpu_to_be32 (TX_CLEAR_WB |TX_FINISH_CACHE_INV |TX_RELEASE_TO_PPE | priv->port <<TX_POOL_SHIFT ); - desc->data_offset = (__force u32 )cpu_to_be32 (phys &SOC_CACHE_LINE_MASK ); + desc->data_offset = (__force u16 )cpu_to_be16 (phys &SOC_CACHE_LINE_MASK ); desc->send_addr = (__force u32 )cpu_to_be32 (phys & ~SOC_CACHE_LINE_MASK );#else + desc->send_size = (__force u32 )cpu_to_be32 (skb->len); desc->cfg = (__force u32 )cpu_to_be32 (TX_CLEAR_WB |TX_FINISH_CACHE_INV ); desc->send_addr = (__force u32 )cpu_to_be32 (phys);#endif
base-commit: 518e5b794c06c0f0eb40df3e202274a66202c137
Signature · 1 line
2.50.1 (Apple Git-155)
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Sun, 20 Sep 2026 11:36:41 +0800 you wrote:
The HI13X1 TX descriptor stores
send_sizeanddata_offsetin 16-bit fields, unlike the 32-bitsend_sizefield in the other descriptor layout. The transmit path nevertheless converts both HI13X1 fields withcpu_to_be32()before assigning them to u16 members.On a little-endian CPU, the conversion moves these small values into the upper half of the 32-bit result and the assignment discards that half. The descriptor consequently loses the packet size and cache-line offset.
[...]
Here is the summary with links:
- [net,v2] net: hip04: use 16-bit byte order for HI13X1 TX fields
https://git.kernel.org/netdev/net-next/c/114bd09838ac
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html