Use the rte_pktmbuf_mtod_offset macro.
Change was automatically generated by cocci/mtod-offset.cocci.

Signed-off-by: Stephen Hemminger <step...@networkplumber.org>
---
 lib/gso/gso_common.h      | 11 +++++------
 lib/gso/gso_tcp4.c        |  8 ++++----
 lib/gso/gso_tunnel_tcp4.c | 12 ++++++------
 lib/gso/gso_tunnel_udp4.c | 18 +++++++++---------
 4 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/lib/gso/gso_common.h b/lib/gso/gso_common.h
index 9456d596d3c5..8987e368605c 100644
--- a/lib/gso/gso_common.h
+++ b/lib/gso/gso_common.h
@@ -52,8 +52,8 @@ update_udp_header(struct rte_mbuf *pkt, uint16_t udp_offset)
 {
        struct rte_udp_hdr *udp_hdr;
 
-       udp_hdr = (struct rte_udp_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
-                       udp_offset);
+       udp_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_udp_hdr *,
+                                         udp_offset);
        udp_hdr->dgram_len = rte_cpu_to_be_16(pkt->pkt_len - udp_offset);
 }
 
@@ -77,8 +77,7 @@ update_tcp_header(struct rte_mbuf *pkt, uint16_t l4_offset, 
uint32_t sent_seq,
 {
        struct rte_tcp_hdr *tcp_hdr;
 
-       tcp_hdr = (struct rte_tcp_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
-                       l4_offset);
+       tcp_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_tcp_hdr *, l4_offset);
        tcp_hdr->sent_seq = rte_cpu_to_be_32(sent_seq);
        if (likely(non_tail))
                tcp_hdr->tcp_flags &= (~(TCP_HDR_PSH_MASK |
@@ -104,8 +103,8 @@ update_ipv4_header(struct rte_mbuf *pkt, uint16_t 
l3_offset, uint16_t id)
 {
        struct rte_ipv4_hdr *ipv4_hdr;
 
-       ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
-                       l3_offset);
+       ipv4_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *,
+                                          l3_offset);
        ipv4_hdr->total_length = rte_cpu_to_be_16(pkt->pkt_len - l3_offset);
        ipv4_hdr->packet_id = rte_cpu_to_be_16(id);
 }
diff --git a/lib/gso/gso_tcp4.c b/lib/gso/gso_tcp4.c
index d31feaff95cd..e2ae4aaf6c5a 100644
--- a/lib/gso/gso_tcp4.c
+++ b/lib/gso/gso_tcp4.c
@@ -16,8 +16,8 @@ update_ipv4_tcp_headers(struct rte_mbuf *pkt, uint8_t 
ipid_delta,
        uint16_t l3_offset = pkt->l2_len;
        uint16_t l4_offset = l3_offset + pkt->l3_len;
 
-       ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char*) +
-                       l3_offset);
+       ipv4_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *,
+                                          l3_offset);
        tcp_hdr = (struct rte_tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
        id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
        sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);
@@ -46,8 +46,8 @@ gso_tcp4_segment(struct rte_mbuf *pkt,
        int ret;
 
        /* Don't process the fragmented packet */
-       ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
-                       pkt->l2_len);
+       ipv4_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *,
+                                          pkt->l2_len);
        frag_off = rte_be_to_cpu_16(ipv4_hdr->fragment_offset);
        if (unlikely(IS_FRAGMENTED(frag_off))) {
                return 0;
diff --git a/lib/gso/gso_tunnel_tcp4.c b/lib/gso/gso_tunnel_tcp4.c
index 1a7ef30ddebf..3a9159774b27 100644
--- a/lib/gso/gso_tunnel_tcp4.c
+++ b/lib/gso/gso_tunnel_tcp4.c
@@ -23,13 +23,13 @@ update_tunnel_ipv4_tcp_headers(struct rte_mbuf *pkt, 
uint8_t ipid_delta,
        tcp_offset = inner_ipv4_offset + pkt->l3_len;
 
        /* Outer IPv4 header. */
-       ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
-                       outer_ipv4_offset);
+       ipv4_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *,
+                                          outer_ipv4_offset);
        outer_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
 
        /* Inner IPv4 header. */
-       ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
-                       inner_ipv4_offset);
+       ipv4_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *,
+                                          inner_ipv4_offset);
        inner_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
 
        tcp_hdr = (struct rte_tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
@@ -65,8 +65,8 @@ gso_tunnel_tcp4_segment(struct rte_mbuf *pkt,
        int ret;
 
        hdr_offset = pkt->outer_l2_len + pkt->outer_l3_len + pkt->l2_len;
-       inner_ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
-                       hdr_offset);
+       inner_ipv4_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *,
+                                                hdr_offset);
        /*
         * Don't process the packet whose MF bit or offset in the inner
         * IPv4 header are non-zero.
diff --git a/lib/gso/gso_tunnel_udp4.c b/lib/gso/gso_tunnel_udp4.c
index 1fc7a8dbc5aa..4fb275484ca8 100644
--- a/lib/gso/gso_tunnel_udp4.c
+++ b/lib/gso/gso_tunnel_udp4.c
@@ -22,13 +22,13 @@ update_tunnel_ipv4_udp_headers(struct rte_mbuf *pkt, struct 
rte_mbuf **segs,
        inner_ipv4_offset = outer_udp_offset + pkt->l2_len;
 
        /* Outer IPv4 header. */
-       ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
-                       outer_ipv4_offset);
+       ipv4_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *,
+                                          outer_ipv4_offset);
        outer_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
 
        /* Inner IPv4 header. */
-       ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
-                       inner_ipv4_offset);
+       ipv4_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *,
+                                          inner_ipv4_offset);
        inner_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
 
        tail_idx = nb_segs - 1;
@@ -42,9 +42,9 @@ update_tunnel_ipv4_udp_headers(struct rte_mbuf *pkt, struct 
rte_mbuf **segs,
                 *
                 * Set IP fragment offset for inner IP header.
                 */
-               ipv4_hdr = (struct rte_ipv4_hdr *)
-                       (rte_pktmbuf_mtod(segs[i], char *) +
-                               inner_ipv4_offset);
+               ipv4_hdr = rte_pktmbuf_mtod_offset(segs[i],
+                                                  struct rte_ipv4_hdr *,
+                                                  inner_ipv4_offset);
                is_mf = i < tail_idx ? IPV4_HDR_MF_BIT : 0;
                ipv4_hdr->fragment_offset =
                        rte_cpu_to_be_16(frag_offset | is_mf);
@@ -67,8 +67,8 @@ gso_tunnel_udp4_segment(struct rte_mbuf *pkt,
        int ret;
 
        hdr_offset = pkt->outer_l2_len + pkt->outer_l3_len + pkt->l2_len;
-       inner_ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
-                       hdr_offset);
+       inner_ipv4_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *,
+                                                hdr_offset);
        /*
         * Don't process the packet whose MF bit or offset in the inner
         * IPv4 header are non-zero.
-- 
2.39.2

Reply via email to