[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210315215151.3029676-3-elder@linaro.org>
Date: Mon, 15 Mar 2021 16:51:47 -0500
From: Alex Elder <elder@...aro.org>
To: subashab@...eaurora.org, stranche@...eaurora.org,
davem@...emloft.net, kuba@...nel.org
Cc: sharathv@...eaurora.org, bjorn.andersson@...aro.org,
evgreen@...omium.org, cpratapa@...eaurora.org,
David.Laight@...LAB.COM, olteanv@...il.com,
alexander.duyck@...il.com, elder@...nel.org,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH net-next v6 2/6] net: qualcomm: rmnet: simplify some byte order logic
In rmnet_map_ipv4_ul_csum_header() and rmnet_map_ipv6_ul_csum_header()
the offset within a packet at which checksumming should commence is
calculated. This calculation involves byte swapping and a forced type
conversion that makes it hard to understand.
Simplify this by computing the offset in host byte order, then
converting the result when assigning it into the header field.
Signed-off-by: Alex Elder <elder@...aro.org>
---
v5: - Use skb_network_header_len() to decide the checksum offset.
.../net/ethernet/qualcomm/rmnet/rmnet_map_data.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
index 21d38167f9618..0bfe69698b278 100644
--- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
+++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
@@ -197,12 +197,10 @@ rmnet_map_ipv4_ul_csum_header(void *iphdr,
struct rmnet_map_ul_csum_header *ul_header,
struct sk_buff *skb)
{
- struct iphdr *ip4h = (struct iphdr *)iphdr;
- __be16 *hdr = (__be16 *)ul_header, offset;
+ __be16 *hdr = (__be16 *)ul_header;
+ struct iphdr *ip4h = iphdr;
- offset = htons((__force u16)(skb_transport_header(skb) -
- (unsigned char *)iphdr));
- ul_header->csum_start_offset = offset;
+ ul_header->csum_start_offset = htons(skb_network_header_len(skb));
ul_header->csum_insert_offset = skb->csum_offset;
ul_header->csum_enabled = 1;
if (ip4h->protocol == IPPROTO_UDP)
@@ -239,12 +237,10 @@ rmnet_map_ipv6_ul_csum_header(void *ip6hdr,
struct rmnet_map_ul_csum_header *ul_header,
struct sk_buff *skb)
{
- struct ipv6hdr *ip6h = (struct ipv6hdr *)ip6hdr;
- __be16 *hdr = (__be16 *)ul_header, offset;
+ __be16 *hdr = (__be16 *)ul_header;
+ struct ipv6hdr *ip6h = ip6hdr;
- offset = htons((__force u16)(skb_transport_header(skb) -
- (unsigned char *)ip6hdr));
- ul_header->csum_start_offset = offset;
+ ul_header->csum_start_offset = htons(skb_network_header_len(skb));
ul_header->csum_insert_offset = skb->csum_offset;
ul_header->csum_enabled = 1;
--
2.27.0
Powered by blists - more mailing lists