DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH v2] crypto/qat: fix uninitilized compiler warning
@ 2021-05-17  6:26 Feifei Wang
  0 siblings, 0 replies; only message in thread
From: Feifei Wang @ 2021-05-17  6:26 UTC (permalink / raw)
  To: John Griffin, Fiona Trahe, Deepak Kumar Jain, Herbert Guan, Jerin Jacob
  Cc: dev, david.marchand, nd, Feifei Wang, stable, Ruifeng Wang

In Arm platform, when "RTE_ARCH_ARM64_MEMCPY" is set as true, compiler
will report variable uninitilized warning:

../drivers/crypto/qat/qat_sym_session.c: In function ‘partial_hash_compute’:
../lib/eal/include/generic/rte_byteorder.h:241:24: warning:
‘<U35a0>’ may be used uninitialized in this function [-Wmaybe-uninitialized]
	241 | #define rte_bswap32(x) __builtin_bswap32(x)
	...

This is because "digest" will be initialized by "rte_memcpy" function
rather than "memcpy" if "RTE_ARCH_ARM64_MEMCPY" is set as true. However,
compiler cannot know it is initialized by the function.

To fix this, use "calloc" to initialize "digest".

Fixes: cd7fc8a84b48 ("eal/arm64: optimize memcpy")
Cc: stable@dpdk.org

Signed-off-by: Feifei Wang <feifei.wang2@arm.com>
Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
---
v2: add check and free for memory dynamic allocation (David Marchand)

 drivers/crypto/qat/qat_sym_session.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/drivers/crypto/qat/qat_sym_session.c b/drivers/crypto/qat/qat_sym_session.c
index 231b1640da..32b1c45046 100644
--- a/drivers/crypto/qat/qat_sym_session.c
+++ b/drivers/crypto/qat/qat_sym_session.c
@@ -1190,8 +1190,7 @@ static int partial_hash_compute(enum icp_qat_hw_auth_algo hash_alg,
 			uint8_t *data_out)
 {
 	int digest_size;
-	uint8_t digest[qat_hash_get_digest_size(
-			ICP_QAT_HW_AUTH_ALGO_DELIMITER)];
+	uint8_t *digest;
 	uint32_t *hash_state_out_be32;
 	uint64_t *hash_state_out_be64;
 	int i;
@@ -1200,55 +1199,65 @@ static int partial_hash_compute(enum icp_qat_hw_auth_algo hash_alg,
 	if (digest_size <= 0)
 		return -EFAULT;
 
+	digest = calloc(qat_hash_get_digest_size(
+				ICP_QAT_HW_AUTH_ALGO_DELIMITER), sizeof(uint8_t));
+	if (!digest)
+		return -ENOMEM;
+
 	hash_state_out_be32 = (uint32_t *)data_out;
 	hash_state_out_be64 = (uint64_t *)data_out;
 
 	switch (hash_alg) {
 	case ICP_QAT_HW_AUTH_ALGO_SHA1:
 		if (partial_hash_sha1(data_in, digest))
-			return -EFAULT;
+			goto fail
 		for (i = 0; i < digest_size >> 2; i++, hash_state_out_be32++)
 			*hash_state_out_be32 =
 				rte_bswap32(*(((uint32_t *)digest)+i));
 		break;
 	case ICP_QAT_HW_AUTH_ALGO_SHA224:
 		if (partial_hash_sha224(data_in, digest))
-			return -EFAULT;
+			goto fail;
 		for (i = 0; i < digest_size >> 2; i++, hash_state_out_be32++)
 			*hash_state_out_be32 =
 				rte_bswap32(*(((uint32_t *)digest)+i));
 		break;
 	case ICP_QAT_HW_AUTH_ALGO_SHA256:
 		if (partial_hash_sha256(data_in, digest))
-			return -EFAULT;
+			goto fail;
 		for (i = 0; i < digest_size >> 2; i++, hash_state_out_be32++)
 			*hash_state_out_be32 =
 				rte_bswap32(*(((uint32_t *)digest)+i));
 		break;
 	case ICP_QAT_HW_AUTH_ALGO_SHA384:
 		if (partial_hash_sha384(data_in, digest))
-			return -EFAULT;
+			goto fail;
 		for (i = 0; i < digest_size >> 3; i++, hash_state_out_be64++)
 			*hash_state_out_be64 =
 				rte_bswap64(*(((uint64_t *)digest)+i));
 		break;
 	case ICP_QAT_HW_AUTH_ALGO_SHA512:
 		if (partial_hash_sha512(data_in, digest))
-			return -EFAULT;
+			goto fail;
 		for (i = 0; i < digest_size >> 3; i++, hash_state_out_be64++)
 			*hash_state_out_be64 =
 				rte_bswap64(*(((uint64_t *)digest)+i));
 		break;
 	case ICP_QAT_HW_AUTH_ALGO_MD5:
 		if (partial_hash_md5(data_in, data_out))
-			return -EFAULT;
+			goto fail;
 		break;
 	default:
 		QAT_LOG(ERR, "invalid hash alg %u", hash_alg);
-		return -EFAULT;
+		goto fail;
 	}
 
+	free(digest);
 	return 0;
+
+fail:
+	free(digest);
+	return -EFAULT;
 }
 #define HMAC_IPAD_VALUE	0x36
 #define HMAC_OPAD_VALUE	0x5c
-- 
2.25.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-17  6:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-17  6:26 [dpdk-dev] [PATCH v2] crypto/qat: fix uninitilized compiler warning Feifei Wang

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).