[v2,04/14] test: cryptodev use rte_pktmbuf_mtod_offset

Message ID 20230506160404.7423-5-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 warning coding style issues

Commit Message

Stephen Hemminger May 6, 2023, 4:03 p.m. UTC
  Based off patch generated by cocci/mtod-offset.cocci.
With some cleanup to shorten lines by using conditional
with ommited operand.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/test/test_cryptodev.c | 66 +++++++++++++++++++++------------------
 1 file changed, 36 insertions(+), 30 deletions(-)
  

Patch

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 9c670e9a3554..b4cddcd55f59 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -3151,8 +3151,9 @@  test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
 				ut_params->op);
 	ut_params->obuf = ut_params->op->sym->m_src;
 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
-	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
-			+ plaintext_pad_len;
+	ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
+						    uint8_t *,
+						    plaintext_pad_len);
 
 	/* Validate obuf */
 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
@@ -3243,8 +3244,9 @@  test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
 				ut_params->op);
 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
 	ut_params->obuf = ut_params->op->sym->m_src;
-	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
-				+ plaintext_pad_len;
+	ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
+						    uint8_t *,
+						    plaintext_pad_len);
 
 	/* Validate obuf */
 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
@@ -3331,8 +3333,9 @@  test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
 
 	ut_params->obuf = ut_params->op->sym->m_src;
 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
-	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
-			+ plaintext_pad_len;
+	ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
+						    uint8_t *,
+						    plaintext_pad_len);
 
 	/* Validate obuf */
 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
@@ -3417,8 +3420,9 @@  test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
 				ut_params->op);
 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
 	ut_params->obuf = ut_params->op->sym->m_src;
-	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
-				+ plaintext_pad_len;
+	ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
+						    uint8_t *,
+						    plaintext_pad_len);
 
 	/* Validate obuf */
 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
@@ -4851,8 +4855,9 @@  test_zuc_cipher_auth(const struct wireless_test_data *tdata)
 			tdata->validDataLenInBits.len,
 			"ZUC Ciphertext data not as expected");
 
-	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
-	    + plaintext_pad_len;
+	ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
+						    uint8_t *,
+						    plaintext_pad_len);
 
 	/* Validate obuf */
 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
@@ -4963,8 +4968,9 @@  test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
 			tdata->validDataLenInBits.len,
 			"SNOW 3G Ciphertext data not as expected");
 
-	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
-	    + plaintext_pad_len;
+	ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
+						    uint8_t *,
+						    plaintext_pad_len);
 
 	/* Validate obuf */
 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
@@ -5129,9 +5135,9 @@  test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
 		debug_hexdump(stdout, "ciphertext expected:",
 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
 
-		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
-			+ (tdata->digest.offset_bytes == 0 ?
-		plaintext_pad_len : tdata->digest.offset_bytes);
+		ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
+					uint8_t *,
+					tdata->digest.offset_bytes ? : plaintext_pad_len);
 
 		debug_hexdump(stdout, "digest:", ut_params->digest,
 			tdata->digest.len);
@@ -5537,10 +5543,9 @@  test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
 		debug_hexdump(stdout, "ciphertext expected:",
 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
 
-		ut_params->digest = rte_pktmbuf_mtod(
-			ut_params->obuf, uint8_t *) +
-			(tdata->digest.offset_bytes == 0 ?
-			plaintext_pad_len : tdata->digest.offset_bytes);
+		ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
+					uint8_t *,
+					tdata->digest.offset_bytes ? : plaintext_pad_len);
 
 		debug_hexdump(stdout, "digest:", ut_params->digest,
 			tdata->digest.len);
@@ -5878,8 +5883,9 @@  test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
 				tdata->validCipherOffsetInBits.len >> 3);
 
-	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
-			+ plaintext_pad_len;
+	ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
+						    uint8_t *,
+						    plaintext_pad_len);
 
 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
 				(tdata->validCipherOffsetInBits.len >> 3);
@@ -6292,8 +6298,9 @@  test_zuc_authentication(const struct wireless_test_data *tdata,
 				ut_params->op);
 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
 	ut_params->obuf = ut_params->op->sym->m_src;
-	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
-			+ plaintext_pad_len;
+	ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
+						    uint8_t *,
+						    plaintext_pad_len);
 
 	if (auth_op != RTE_CRYPTO_AUTH_OP_VERIFY) {
 		/* Validate obuf */
@@ -6476,10 +6483,9 @@  test_zuc_auth_cipher(const struct wireless_test_data *tdata,
 		debug_hexdump(stdout, "ciphertext expected:",
 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
 
-		ut_params->digest = rte_pktmbuf_mtod(
-			ut_params->obuf, uint8_t *) +
-			(tdata->digest.offset_bytes == 0 ?
-			plaintext_pad_len : tdata->digest.offset_bytes);
+		ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
+					uint8_t *,
+					tdata->digest.offset_bytes ? : plaintext_pad_len);
 
 		debug_hexdump(stdout, "digest:", ut_params->digest,
 			tdata->digest.len);
@@ -7897,9 +7903,9 @@  test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
 				tdata->ciphertext.data,
 				tdata->ciphertext.len_bits >> 3);
 
-		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
-				+ (tdata->digest_enc.offset == 0 ?
-		plaintext_pad_len : tdata->digest_enc.offset);
+		ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
+					uint8_t *,
+					tdata->digest_enc.offset ? : plaintext_pad_len);
 
 		debug_hexdump(stdout, "digest:", ut_params->digest,
 				tdata->digest_enc.len);