[PATCH net-next v1 1/1] net: usb: lan78xx: annotate checksum assignment to silence sparse warnings

From: Oleksij Rempel
Date: Fri Jun 20 2025 - 04:47:36 EST


sparse warns about suspicious type casts in checksum assignment:

drivers/net/usb/lan78xx.c:3865:29: warning: cast to restricted __be16
drivers/net/usb/lan78xx.c:3865:27: warning: incorrect type in assignment
(different base types) expected restricted __wsum [usertype] csum
got unsigned short [usertype]

Use __force to annotate the casts from u16 to __be16 to __wsum.
This makes the type conversion explicit and silences the warnings.
The code is otherwise correct; this change only clarifies intent.

Signed-off-by: Oleksij Rempel <o.rempel@xxxxxxxxxxxxxx>
---
drivers/net/usb/lan78xx.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c
index f00284c9ad34..565b9847e2ab 100644
--- a/drivers/net/usb/lan78xx.c
+++ b/drivers/net/usb/lan78xx.c
@@ -3819,7 +3819,10 @@ static void lan78xx_rx_csum_offload(struct lan78xx_net *dev,
!(dev->net->features & NETIF_F_HW_VLAN_CTAG_RX))) {
skb->ip_summed = CHECKSUM_NONE;
} else {
- skb->csum = ntohs((u16)(rx_cmd_b >> RX_CMD_B_CSUM_SHIFT_));
+ __be16 csum_raw;
+
+ csum_raw = (__force __be16)(rx_cmd_b >> RX_CMD_B_CSUM_SHIFT_);
+ skb->csum = (__force __wsum)ntohs(csum_raw);
skb->ip_summed = CHECKSUM_COMPLETE;
}
}
--
2.39.5