* [PATCH net-next v1 1/1] net: usb: lan78xx: annotate checksum assignment to silence sparse warnings
@ 2025-06-20 8:46 Oleksij Rempel
2025-06-23 23:49 ` Jakub Kicinski
0 siblings, 1 reply; 3+ messages in thread
From: Oleksij Rempel @ 2025-06-20 8:46 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Woojung Huh, Andrew Lunn, Russell King, Thangaraj Samynathan,
Rengarajan Sundararajan
Cc: Oleksij Rempel, kernel, linux-kernel, netdev, UNGLinuxDriver,
Phil Elwell, Maxime Chevallier, Simon Horman
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@pengutronix.de>
---
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next v1 1/1] net: usb: lan78xx: annotate checksum assignment to silence sparse warnings
2025-06-20 8:46 [PATCH net-next v1 1/1] net: usb: lan78xx: annotate checksum assignment to silence sparse warnings Oleksij Rempel
@ 2025-06-23 23:49 ` Jakub Kicinski
2025-06-24 10:47 ` Simon Horman
0 siblings, 1 reply; 3+ messages in thread
From: Jakub Kicinski @ 2025-06-23 23:49 UTC (permalink / raw)
To: Oleksij Rempel
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Woojung Huh,
Andrew Lunn, Russell King, Thangaraj Samynathan,
Rengarajan Sundararajan, kernel, linux-kernel, netdev,
UNGLinuxDriver, Phil Elwell, Maxime Chevallier, Simon Horman
On Fri, 20 Jun 2025 10:46:18 +0200 Oleksij Rempel wrote:
> - 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);
You can avoid the __force __be16 if you switch the variable to be u16
and then htons instead of ntohs
--
pw-bot: cr
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next v1 1/1] net: usb: lan78xx: annotate checksum assignment to silence sparse warnings
2025-06-23 23:49 ` Jakub Kicinski
@ 2025-06-24 10:47 ` Simon Horman
0 siblings, 0 replies; 3+ messages in thread
From: Simon Horman @ 2025-06-24 10:47 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Oleksij Rempel, David S. Miller, Eric Dumazet, Paolo Abeni,
Woojung Huh, Andrew Lunn, Russell King, Thangaraj Samynathan,
Rengarajan Sundararajan, kernel, linux-kernel, netdev,
UNGLinuxDriver, Phil Elwell, Maxime Chevallier
On Mon, Jun 23, 2025 at 04:49:13PM -0700, Jakub Kicinski wrote:
> On Fri, 20 Jun 2025 10:46:18 +0200 Oleksij Rempel wrote:
> > - 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);
>
> You can avoid the __force __be16 if you switch the variable to be u16
> and then htons instead of ntohs
Ok, now I am confused.
What is the endian of these integers?
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-06-24 10:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-20 8:46 [PATCH net-next v1 1/1] net: usb: lan78xx: annotate checksum assignment to silence sparse warnings Oleksij Rempel
2025-06-23 23:49 ` Jakub Kicinski
2025-06-24 10:47 ` Simon Horman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).