From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 97F6CA0A02; Mon, 17 May 2021 11:07:21 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D5198410E2; Mon, 17 May 2021 11:07:20 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mails.dpdk.org (Postfix) with ESMTP id AAEB540041; Mon, 17 May 2021 11:07:19 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EF1DF106F; Mon, 17 May 2021 02:07:18 -0700 (PDT) Received: from net-x86-dell-8268.shanghai.arm.com (net-x86-dell-8268.shanghai.arm.com [10.169.210.111]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 951CE3F719; Mon, 17 May 2021 02:07:15 -0700 (PDT) From: Feifei Wang To: John Griffin , Fiona Trahe , Deepak Kumar Jain , Jerin Jacob , Herbert Guan Cc: dev@dpdk.org, david.marchand@redhat.com, nd@arm.com, Feifei Wang , stable@dpdk.org, Ruifeng Wang Date: Mon, 17 May 2021 17:07:09 +0800 Message-Id: <20210517090709.4078-1-feifei.wang2@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210514074113.2666225-1-feifei.wang2@arm.com> References: <20210514074113.2666225-1-feifei.wang2@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v3] crypto/qat: fix uninitilized compiler warning X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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: ‘’ 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 Reviewed-by: Ruifeng Wang --- v2: add check and free for memory dynamic allocation (David Marchand) v3: fix compiler error 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..105a10957a 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