DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	Akhil Goyal <gakhil@marvell.com>,
	Fan Zhang <fanzhang.oss@gmail.com>,
	Kirill Rybalchenko <kirill.rybalchenko@intel.com>
Subject: [PATCH 05/14] examples: use rte_pktmbuf_mtod_offset
Date: Fri,  5 May 2023 10:48:04 -0700	[thread overview]
Message-ID: <20230505174813.133894-6-stephen@networkplumber.org> (raw)
In-Reply-To: <20230505174813.133894-1-stephen@networkplumber.org>

Automatically generated from cocci/mtod-offset.cocci

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 examples/l2fwd-crypto/main.c   | 16 +++++++++-------
 examples/ptpclient/ptpclient.c | 18 +++++++++---------
 2 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c
index efe7eea2a768..981b449710a7 100644
--- a/examples/l2fwd-crypto/main.c
+++ b/examples/l2fwd-crypto/main.c
@@ -410,8 +410,8 @@ l2fwd_simple_crypto_enqueue(struct rte_mbuf *m,
 
 	ipdata_offset = sizeof(struct rte_ether_hdr);
 
-	ip_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(m, char *) +
-			ipdata_offset);
+	ip_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *,
+					 ipdata_offset);
 
 	ipdata_offset += (ip_hdr->version_ihl & RTE_IPV4_HDR_IHL_MASK)
 			* RTE_IPV4_IHL_MULTIPLIER;
@@ -479,8 +479,9 @@ l2fwd_simple_crypto_enqueue(struct rte_mbuf *m,
 			op->sym->auth.digest.data = (uint8_t *)rte_pktmbuf_append(m,
 				cparams->digest_length);
 		} else {
-			op->sym->auth.digest.data = rte_pktmbuf_mtod(m,
-				uint8_t *) + ipdata_offset + data_len;
+			op->sym->auth.digest.data = rte_pktmbuf_mtod_offset(m,
+									    uint8_t *,
+									    ipdata_offset + data_len);
 		}
 
 		op->sym->auth.digest.phys_addr = rte_pktmbuf_iova_offset(m,
@@ -540,8 +541,9 @@ l2fwd_simple_crypto_enqueue(struct rte_mbuf *m,
 			op->sym->aead.digest.data = (uint8_t *)rte_pktmbuf_append(m,
 				cparams->digest_length);
 		} else {
-			op->sym->aead.digest.data = rte_pktmbuf_mtod(m,
-				uint8_t *) + ipdata_offset + data_len;
+			op->sym->aead.digest.data = rte_pktmbuf_mtod_offset(m,
+									    uint8_t *,
+									    ipdata_offset + data_len);
 		}
 
 		op->sym->aead.digest.phys_addr = rte_pktmbuf_iova_offset(m,
@@ -631,7 +633,7 @@ l2fwd_simple_forward(struct rte_mbuf *m, uint16_t portid,
 	struct rte_ipv4_hdr *ip_hdr;
 	uint32_t ipdata_offset = sizeof(struct rte_ether_hdr);
 
-	ip_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(m, char *) +
+	ip_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *,
 					 ipdata_offset);
 	dst_port = l2fwd_dst_ports[portid];
 
diff --git a/examples/ptpclient/ptpclient.c b/examples/ptpclient/ptpclient.c
index cdf2da64dfee..2535d848a1e9 100644
--- a/examples/ptpclient/ptpclient.c
+++ b/examples/ptpclient/ptpclient.c
@@ -354,8 +354,8 @@ parse_sync(struct ptpv2_data_slave_ordinary *ptp_data, uint16_t rx_tstamp_idx)
 {
 	struct ptp_header *ptp_hdr;
 
-	ptp_hdr = (struct ptp_header *)(rte_pktmbuf_mtod(ptp_data->m, char *)
-			+ sizeof(struct rte_ether_hdr));
+	ptp_hdr = rte_pktmbuf_mtod_offset(ptp_data->m, struct ptp_header *,
+					  sizeof(struct rte_ether_hdr));
 	ptp_data->seqID_SYNC = rte_be_to_cpu_16(ptp_hdr->seq_id);
 
 	if (ptp_data->ptpset == 0) {
@@ -397,15 +397,15 @@ parse_fup(struct ptpv2_data_slave_ordinary *ptp_data)
 	int ret;
 
 	eth_hdr = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
-	ptp_hdr = (struct ptp_header *)(rte_pktmbuf_mtod(m, char *)
-			+ sizeof(struct rte_ether_hdr));
+	ptp_hdr = rte_pktmbuf_mtod_offset(m, struct ptp_header *,
+					  sizeof(struct rte_ether_hdr));
 	if (memcmp(&ptp_data->master_clock_id,
 			&ptp_hdr->source_port_id.clock_id,
 			sizeof(struct clock_id)) != 0)
 		return;
 
 	ptp_data->seqID_FOLLOWUP = rte_be_to_cpu_16(ptp_hdr->seq_id);
-	ptp_msg = (struct ptp_message *) (rte_pktmbuf_mtod(m, char *) +
+	ptp_msg = rte_pktmbuf_mtod_offset(m, struct ptp_message *,
 					  sizeof(struct rte_ether_hdr));
 
 	origin_tstamp = &ptp_msg->follow_up.precise_origin_tstamp;
@@ -537,8 +537,8 @@ parse_drsp(struct ptpv2_data_slave_ordinary *ptp_data)
 	struct tstamp *rx_tstamp;
 	uint16_t seq_id;
 
-	ptp_msg = (struct ptp_message *) (rte_pktmbuf_mtod(m, char *) +
-					sizeof(struct rte_ether_hdr));
+	ptp_msg = rte_pktmbuf_mtod_offset(m, struct ptp_message *,
+					  sizeof(struct rte_ether_hdr));
 	seq_id = rte_be_to_cpu_16(ptp_msg->delay_resp.hdr.seq_id);
 	if (memcmp(&ptp_data->client_clock_id,
 		   &ptp_msg->delay_resp.req_port_id.clock_id,
@@ -585,8 +585,8 @@ parse_ptp_frames(uint16_t portid, struct rte_mbuf *m) {
 	if (eth_type == PTP_PROTOCOL) {
 		ptp_data.m = m;
 		ptp_data.portid = portid;
-		ptp_hdr = (struct ptp_header *)(rte_pktmbuf_mtod(m, char *)
-					+ sizeof(struct rte_ether_hdr));
+		ptp_hdr = rte_pktmbuf_mtod_offset(m, struct ptp_header *,
+						  sizeof(struct rte_ether_hdr));
 
 		switch (ptp_hdr->msg_type) {
 		case SYNC:
-- 
2.39.2


  parent reply	other threads:[~2023-05-05 17:48 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-05 17:47 [PATCH 00/14] rte_pktmbuf_mtod_offset usage Stephen Hemminger
2023-05-05 17:48 ` [PATCH 01/14] gro: use rte_pktmbuf_mtod_offset Stephen Hemminger
2023-05-05 17:48 ` [PATCH 02/14] gso: " Stephen Hemminger
2023-05-05 17:48 ` [PATCH 03/14] testpmd: " Stephen Hemminger
2023-05-05 17:48 ` [PATCH 04/14] test: cryptodev " Stephen Hemminger
2023-05-05 17:48 ` Stephen Hemminger [this message]
2023-05-05 17:48 ` [PATCH 06/14] net/tap: " Stephen Hemminger
2023-05-05 17:48 ` [PATCH 07/14] net/nfp: " Stephen Hemminger
2023-05-05 17:48 ` [PATCH 08/14] crypto/ipsec_mb: " Stephen Hemminger
2023-05-05 17:48 ` [PATCH 09/14] crypto/qat: " Stephen Hemminger
2023-05-05 17:48 ` [PATCH 10/14] crypto/cnxk: use rte_ptkmbuf_mtod_offset Stephen Hemminger
2023-05-05 17:48 ` [PATCH 11/14] common/cpt: use rte_pktmbuf_mtod_offset Stephen Hemminger
2023-05-05 17:48 ` [PATCH 12/14] crypto/caam_jr: " Stephen Hemminger
2023-05-09 11:43   ` Hemant Agrawal
2023-05-05 17:48 ` [PATCH 13/14] net/mlx4: " Stephen Hemminger
2023-05-05 17:48 ` [PATCH 14/14] baseband/fpga_5gnr: use rte_pktmbu_mtod_offset Stephen Hemminger
2023-05-06 16:03 ` [PATCH v2 00/14] rte_pktmbuf_mtod_offset usage Stephen Hemminger
2023-05-06 16:03   ` [PATCH v2 01/14] gro: use rte_pktmbuf_mtod_offset Stephen Hemminger
2023-05-06 16:03   ` [PATCH v2 02/14] gso: " Stephen Hemminger
2023-05-06 16:03   ` [PATCH v2 03/14] testpmd: " Stephen Hemminger
2023-05-06 16:03   ` [PATCH v2 04/14] test: cryptodev " Stephen Hemminger
2023-05-06 16:03   ` [PATCH v2 05/14] examples: " Stephen Hemminger
2023-05-06 16:03   ` [PATCH v2 06/14] net/tap: " Stephen Hemminger
2023-05-06 16:03   ` [PATCH v2 07/14] net/nfp: " Stephen Hemminger
2023-05-09 13:35     ` Niklas Söderlund
2023-05-06 16:03   ` [PATCH v2 08/14] crypto/ipsec_mb: " Stephen Hemminger
2023-05-29 12:47     ` De Lara Guarch, Pablo
2023-05-06 16:03   ` [PATCH v2 09/14] crypto/qat: " Stephen Hemminger
2023-05-06 16:03   ` [PATCH v2 10/14] crypto/cnxk: use rte_ptkmbuf_mtod_offset Stephen Hemminger
2023-05-06 16:04   ` [PATCH v2 11/14] common/cpt: use rte_pktmbuf_mtod_offset Stephen Hemminger
2023-05-06 16:04   ` [PATCH v2 12/14] crypto/caam_jr: " Stephen Hemminger
2023-05-06 16:04   ` [PATCH v2 13/14] net/mlx4: " Stephen Hemminger
2023-05-06 16:04   ` [PATCH v2 14/14] baseband/fpga_5gnr: use rte_pktmbu_mtod_offset Stephen Hemminger
2023-07-06 17:59 ` [PATCH v3 00/14] Use rte_pktmbuf_mtod_offset() where possible Stephen Hemminger
2023-07-06 17:59   ` [PATCH v3 01/14] gro: use rte_pktmbuf_mtod_offset Stephen Hemminger
2023-07-06 17:59   ` [PATCH v3 02/14] gso: " Stephen Hemminger
2023-07-06 17:59   ` [PATCH v3 03/14] testpmd: " Stephen Hemminger
2023-07-06 17:59   ` [PATCH v3 04/14] test: cryptodev " Stephen Hemminger
2023-07-07 12:46     ` Ferruh Yigit
2023-07-07 20:32       ` Stephen Hemminger
2023-07-06 17:59   ` [PATCH v3 05/14] examples: " Stephen Hemminger
2023-07-06 17:59   ` [PATCH v3 06/14] net/tap: " Stephen Hemminger
2023-07-06 17:59   ` [PATCH v3 07/14] net/nfp: " Stephen Hemminger
2023-07-06 17:59   ` [PATCH v3 08/14] crypto/ipsec_mb: " Stephen Hemminger
2023-07-06 17:59   ` [PATCH v3 09/14] crypto/qat: " Stephen Hemminger
2023-07-06 17:59   ` [PATCH v3 10/14] crypto/cnxk: use rte_ptkmbuf_mtod_offset Stephen Hemminger
2023-07-06 17:59   ` [PATCH v3 11/14] common/cpt: use rte_pktmbuf_mtod_offset Stephen Hemminger
2023-07-06 17:59   ` [PATCH v3 12/14] crypto/caam_jr: " Stephen Hemminger
2023-07-06 17:59   ` [PATCH v3 13/14] net/mlx4: " Stephen Hemminger
2023-07-07 12:46     ` Ferruh Yigit
2023-07-06 17:59   ` [PATCH v3 14/14] baseband/fpga_5gnr: use rte_pktmbu_mtod_offset Stephen Hemminger
2023-07-07 12:47   ` [PATCH v3 00/14] Use rte_pktmbuf_mtod_offset() where possible Ferruh Yigit
2023-07-07 20:38 ` [PATCH v4 00/11] Use rte_pktmbuf_mtod_offset Stephen Hemminger
2023-07-07 20:38   ` [PATCH v4 01/11] gro: use rte_pktmbuf_mtod_offset Stephen Hemminger
2023-07-07 20:38   ` [PATCH v4 02/11] gso: " Stephen Hemminger
2023-07-07 20:39   ` [PATCH v4 03/11] test: " Stephen Hemminger
2023-07-07 20:39   ` [PATCH v4 04/11] drivers/crypto: " Stephen Hemminger
2023-07-07 20:39   ` [PATCH v4 05/11] net/nfp: " Stephen Hemminger
2023-07-07 20:39   ` [PATCH v4 06/11] net/tap: use rte_pktmbuf_motd_offset Stephen Hemminger
2023-07-07 20:39   ` [PATCH v4 07/11] baseband/fpga: use rte_pktmbuf_offset Stephen Hemminger
2023-07-07 20:39   ` [PATCH v4 08/11] cpt: use rte_pktmbuf_mtod_offset Stephen Hemminger
2023-07-07 20:39   ` [PATCH v4 09/11] testpmd: " Stephen Hemminger
2023-07-07 20:39   ` [PATCH v4 10/11] examples/ptpclient: " Stephen Hemminger
2023-07-07 20:39   ` [PATCH v4 11/11] examples/l2fwd-crypto: " Stephen Hemminger
2023-07-08  1:57 ` [PATCH v5 00/11] use rte_pktmbuf_mto_offset Stephen Hemminger
2023-07-08  1:57   ` [PATCH v5 01/11] gro: use rte_pktmbuf_mtod_offset Stephen Hemminger
2023-07-08  1:57   ` [PATCH v5 02/11] gso: " Stephen Hemminger
2023-07-08  1:57   ` [PATCH v5 03/11] test/crypto_dev: " Stephen Hemminger
2023-07-08  1:57   ` [PATCH v5 04/11] drivers/crypto: " Stephen Hemminger
2023-07-11  5:34     ` [EXT] " Anoob Joseph
2023-07-12 14:56     ` Hemant Agrawal
2023-07-08  1:57   ` [PATCH v5 05/11] net/nfp: " Stephen Hemminger
2023-07-10 12:19     ` Niklas Söderlund
2024-01-24 13:44       ` Thomas Monjalon
2023-07-08  1:57   ` [PATCH v5 06/11] net/tap: use rte_pktmbuf_motd_offset Stephen Hemminger
2024-01-24 13:47     ` Thomas Monjalon
2023-07-08  1:57   ` [PATCH v5 07/11] baseband/fpga: use rte_pktmbuf_offset Stephen Hemminger
2023-07-08  1:57   ` [PATCH v5 08/11] cpt: use rte_pktmbuf_mtod_offset Stephen Hemminger
2023-07-11  5:35     ` [EXT] " Anoob Joseph
2023-07-08  1:57   ` [PATCH v5 09/11] testpmd: " Stephen Hemminger
2023-07-08  1:57   ` [PATCH v5 10/11] examples/ptpclient: " Stephen Hemminger
2023-07-08  1:57   ` [PATCH v5 11/11] examples/l2fwd-crypto: " Stephen Hemminger
2023-07-09  3:54   ` [PATCH v5 00/11] use rte_pktmbuf_mto_offset fengchengwen
2024-01-24 14:55     ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230505174813.133894-6-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=fanzhang.oss@gmail.com \
    --cc=gakhil@marvell.com \
    --cc=kirill.rybalchenko@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).