[v2,08/14] crypto/ipsec_mb: use rte_pktmbuf_mtod_offset

Message ID 20230506160404.7423-9-stephen@networkplumber.org (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series rte_pktmbuf_mtod_offset usage |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger May 6, 2023, 4:03 p.m. UTC
  Initial patch generated with cocci/mtod-offset.
Additional manual cleanups to indentation and remove unnecessary
parenthesis.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/crypto/ipsec_mb/pmd_kasumi.c | 16 ++++++-------
 drivers/crypto/ipsec_mb/pmd_snow3g.c | 35 +++++++++++-----------------
 drivers/crypto/ipsec_mb/pmd_zuc.c    | 16 ++++++-------
 3 files changed, 30 insertions(+), 37 deletions(-)
  

Comments

De Lara Guarch, Pablo May 29, 2023, 12:47 p.m. UTC | #1
> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: Saturday, May 6, 2023 5:04 PM
> To: dev@dpdk.org
> Cc: Stephen Hemminger <stephen@networkplumber.org>; Ji, Kai
> <kai.ji@intel.com>; De Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>
> Subject: [PATCH v2 08/14] crypto/ipsec_mb: use rte_pktmbuf_mtod_offset
> 
> Initial patch generated with cocci/mtod-offset.
> Additional manual cleanups to indentation and remove unnecessary
> parenthesis.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>

Acked-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
  

Patch

diff --git a/drivers/crypto/ipsec_mb/pmd_kasumi.c b/drivers/crypto/ipsec_mb/pmd_kasumi.c
index 5db9c523cd9a..5b1694276468 100644
--- a/drivers/crypto/ipsec_mb/pmd_kasumi.c
+++ b/drivers/crypto/ipsec_mb/pmd_kasumi.c
@@ -83,13 +83,13 @@  process_kasumi_cipher_op(struct ipsec_mb_qp *qp, struct rte_crypto_op **ops,
 	uint32_t num_bytes[num_ops];
 
 	for (i = 0; i < num_ops; i++) {
-		src[i] = rte_pktmbuf_mtod(ops[i]->sym->m_src, uint8_t *)
-			 + (ops[i]->sym->cipher.data.offset >> 3);
+		src[i] = rte_pktmbuf_mtod_offset(ops[i]->sym->m_src, uint8_t *,
+				ops[i]->sym->cipher.data.offset >> 3);
 		dst[i] = ops[i]->sym->m_dst
-			     ? rte_pktmbuf_mtod(ops[i]->sym->m_dst, uint8_t *)
-				   + (ops[i]->sym->cipher.data.offset >> 3)
-			     : rte_pktmbuf_mtod(ops[i]->sym->m_src, uint8_t *)
-				   + (ops[i]->sym->cipher.data.offset >> 3);
+			     ? rte_pktmbuf_mtod_offset(ops[i]->sym->m_dst, uint8_t *,
+						       ops[i]->sym->cipher.data.offset >> 3)
+			     : rte_pktmbuf_mtod_offset(ops[i]->sym->m_src, uint8_t *,
+						       ops[i]->sym->cipher.data.offset >> 3);
 		iv_ptr = rte_crypto_op_ctod_offset(ops[i], uint8_t *,
 						    session->cipher_iv_offset);
 		iv[i] = *((uint64_t *)(iv_ptr));
@@ -155,8 +155,8 @@  process_kasumi_hash_op(struct ipsec_mb_qp *qp, struct rte_crypto_op **ops,
 
 		length_in_bits = ops[i]->sym->auth.data.length;
 
-		src = rte_pktmbuf_mtod(ops[i]->sym->m_src, uint8_t *)
-		      + (ops[i]->sym->auth.data.offset >> 3);
+		src = rte_pktmbuf_mtod_offset(ops[i]->sym->m_src, uint8_t *,
+					      ops[i]->sym->auth.data.offset >> 3);
 		/* Direction from next bit after end of message */
 		num_bytes = length_in_bits >> 3;
 
diff --git a/drivers/crypto/ipsec_mb/pmd_snow3g.c b/drivers/crypto/ipsec_mb/pmd_snow3g.c
index 8ed069f42860..f6e51916e1fd 100644
--- a/drivers/crypto/ipsec_mb/pmd_snow3g.c
+++ b/drivers/crypto/ipsec_mb/pmd_snow3g.c
@@ -111,14 +111,12 @@  process_snow3g_cipher_op(struct ipsec_mb_qp *qp, struct rte_crypto_op **ops,
 
 		cipher_off = ops[i]->sym->cipher.data.offset >> 3;
 		cipher_len = ops[i]->sym->cipher.data.length >> 3;
-		src[i] = rte_pktmbuf_mtod_offset(
-			ops[i]->sym->m_src,	uint8_t *, cipher_off);
+		src[i] = rte_pktmbuf_mtod_offset(ops[i]->sym->m_src, uint8_t *, cipher_off);
 
 		/* If out-of-place operation */
 		if (ops[i]->sym->m_dst &&
 			ops[i]->sym->m_src != ops[i]->sym->m_dst) {
-			dst[i] = rte_pktmbuf_mtod_offset(
-				ops[i]->sym->m_dst, uint8_t *, cipher_off);
+			dst[i] = rte_pktmbuf_mtod_offset(ops[i]->sym->m_dst, uint8_t *, cipher_off);
 
 			/* In case of out-of-place, auth-cipher operation
 			 * with partial encryption of the digest, copy
@@ -133,16 +131,14 @@  process_snow3g_cipher_op(struct ipsec_mb_qp *qp, struct rte_crypto_op **ops,
 					cipher_off - cipher_len;
 			if (unencrypted_bytes > 0)
 				rte_memcpy(
-					rte_pktmbuf_mtod_offset(
-						ops[i]->sym->m_dst, uint8_t *,
+					rte_pktmbuf_mtod_offset(ops[i]->sym->m_dst, uint8_t *,
 						cipher_off + cipher_len),
-					rte_pktmbuf_mtod_offset(
-						ops[i]->sym->m_src, uint8_t *,
+					rte_pktmbuf_mtod_offset(ops[i]->sym->m_src, uint8_t *,
 						cipher_off + cipher_len),
 					unencrypted_bytes);
 		} else
-			dst[i] = rte_pktmbuf_mtod_offset(ops[i]->sym->m_src,
-						uint8_t *, cipher_off);
+			dst[i] = rte_pktmbuf_mtod_offset(ops[i]->sym->m_src, uint8_t *,
+						cipher_off);
 
 		iv[i] = rte_crypto_op_ctod_offset(ops[i], uint8_t *,
 				session->cipher_iv_offset);
@@ -205,13 +201,11 @@  process_snow3g_cipher_op_bit(struct ipsec_mb_qp *qp,
 			(length_in_bits >> 3);
 	if (unencrypted_bytes > 0)
 		rte_memcpy(
-			rte_pktmbuf_mtod_offset(
-				op->sym->m_dst, uint8_t *,
-				(length_in_bits >> 3)),
-			rte_pktmbuf_mtod_offset(
-				op->sym->m_src, uint8_t *,
-				(length_in_bits >> 3)),
-				unencrypted_bytes);
+			rte_pktmbuf_mtod_offset(op->sym->m_dst, uint8_t *,
+				length_in_bits >> 3),
+			rte_pktmbuf_mtod_offset(op->sym->m_src, uint8_t *,
+				length_in_bits >> 3),
+			unencrypted_bytes);
 
 	iv = rte_crypto_op_ctod_offset(op, uint8_t *,
 				session->cipher_iv_offset);
@@ -248,8 +242,8 @@  process_snow3g_hash_op(struct ipsec_mb_qp *qp, struct rte_crypto_op **ops,
 
 		length_in_bits = ops[i]->sym->auth.data.length;
 
-		src = rte_pktmbuf_mtod(ops[i]->sym->m_src, uint8_t *) +
-				(ops[i]->sym->auth.data.offset >> 3);
+		src = rte_pktmbuf_mtod_offset(ops[i]->sym->m_src, uint8_t *,
+					      ops[i]->sym->auth.data.offset >> 3);
 		iv = rte_crypto_op_ctod_offset(ops[i], uint8_t *,
 				session->auth_iv_offset);
 
@@ -261,8 +255,7 @@  process_snow3g_hash_op(struct ipsec_mb_qp *qp, struct rte_crypto_op **ops,
 				session->op ==
 				IPSEC_MB_OP_DECRYPT_THEN_HASH_VERIFY) &&
 				ops[i]->sym->m_dst != NULL)
-				src = rte_pktmbuf_mtod_offset(
-					ops[i]->sym->m_dst, uint8_t *,
+				src = rte_pktmbuf_mtod_offset(ops[i]->sym->m_dst, uint8_t *,
 					ops[i]->sym->auth.data.offset >> 3);
 
 			IMB_SNOW3G_F9_1_BUFFER(qp->mb_mgr,
diff --git a/drivers/crypto/ipsec_mb/pmd_zuc.c b/drivers/crypto/ipsec_mb/pmd_zuc.c
index 92fd9d180894..65b00e80390e 100644
--- a/drivers/crypto/ipsec_mb/pmd_zuc.c
+++ b/drivers/crypto/ipsec_mb/pmd_zuc.c
@@ -107,13 +107,13 @@  process_zuc_cipher_op(struct ipsec_mb_qp *qp, struct rte_crypto_op **ops,
 		}
 #endif
 
-		src[i] = rte_pktmbuf_mtod(ops[i]->sym->m_src, uint8_t *) +
-				(ops[i]->sym->cipher.data.offset >> 3);
+		src[i] = rte_pktmbuf_mtod_offset(ops[i]->sym->m_src, uint8_t *,
+						 ops[i]->sym->cipher.data.offset >> 3);
 		dst[i] = ops[i]->sym->m_dst ?
-			rte_pktmbuf_mtod(ops[i]->sym->m_dst, uint8_t *) +
-				(ops[i]->sym->cipher.data.offset >> 3) :
-			rte_pktmbuf_mtod(ops[i]->sym->m_src, uint8_t *) +
-				(ops[i]->sym->cipher.data.offset >> 3);
+			rte_pktmbuf_mtod_offset(ops[i]->sym->m_dst, uint8_t *,
+						ops[i]->sym->cipher.data.offset >> 3) :
+			rte_pktmbuf_mtod_offset(ops[i]->sym->m_src, uint8_t *,
+						ops[i]->sym->cipher.data.offset >> 3);
 		iv[i] = rte_crypto_op_ctod_offset(ops[i], uint8_t *,
 				sess->cipher_iv_offset);
 		num_bytes[i] = ops[i]->sym->cipher.data.length >> 3;
@@ -159,8 +159,8 @@  process_zuc_hash_op(struct ipsec_mb_qp *qp, struct rte_crypto_op **ops,
 
 		length_in_bits[i] = ops[i]->sym->auth.data.length;
 
-		src[i] = rte_pktmbuf_mtod(ops[i]->sym->m_src, uint8_t *) +
-				(ops[i]->sym->auth.data.offset >> 3);
+		src[i] = rte_pktmbuf_mtod_offset(ops[i]->sym->m_src, uint8_t *,
+						 ops[i]->sym->auth.data.offset >> 3);
 		iv[i] = rte_crypto_op_ctod_offset(ops[i], uint8_t *,
 				sess->auth_iv_offset);