crypto/qat: fix uninitilized compiler warning

Message ID 20210514074113.2666225-1-feifei.wang2@arm.com (mailing list archive)
State Superseded, archived
Delegated to: Ajit Khaparde
Headers
Series crypto/qat: fix uninitilized compiler warning |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/iol-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/github-robot success github build: passed
ci/intel-Testing success Testing PASS
ci/iol-mellanox-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS

Commit Message

Feifei Wang May 14, 2021, 7:41 a.m. UTC
  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>
---
 drivers/crypto/qat/qat_sym_session.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

David Marchand May 14, 2021, 7:49 a.m. UTC | #1
On Fri, May 14, 2021 at 9:41 AM Feifei Wang <feifei.wang2@arm.com> wrote:
>
> 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>
> ---
>  drivers/crypto/qat/qat_sym_session.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/crypto/qat/qat_sym_session.c b/drivers/crypto/qat/qat_sym_session.c
> index 231b1640da..dab23a3290 100644
> --- a/drivers/crypto/qat/qat_sym_session.c
> +++ b/drivers/crypto/qat/qat_sym_session.c
> @@ -1190,8 +1190,8 @@ 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 = (uint8_t *)calloc(qat_hash_get_digest_size(
> +                               ICP_QAT_HW_AUTH_ALGO_DELIMITER), sizeof(uint8_t));

calloc can fail.
cast is unneded.

A simple uint8_t digest[...] = { 0 } would do the job.


>         uint32_t *hash_state_out_be32;
>         uint64_t *hash_state_out_be64;
>         int i;
> --
> 2.25.1
>
  
Feifei Wang May 14, 2021, 8:01 a.m. UTC | #2
Hi, David

> -----邮件原件-----
> 发件人: David Marchand <david.marchand@redhat.com>
> 发送时间: 2021年5月14日 15:50
> 收件人: Feifei Wang <Feifei.Wang2@arm.com>
> 抄送: John Griffin <john.griffin@intel.com>; Fiona Trahe
> <fiona.trahe@intel.com>; Deepak Kumar Jain <deepak.k.jain@intel.com>;
> Herbert Guan <Herbert.Guan@arm.com>; Jerin Jacob
> <jerin.jacob@caviumnetworks.com>; dev <dev@dpdk.org>; nd
> <nd@arm.com>; dpdk stable <stable@dpdk.org>; Ruifeng Wang
> <Ruifeng.Wang@arm.com>
> 主题: Re: [dpdk-stable] [PATCH] crypto/qat: fix uninitilized compiler warning
> 
> On Fri, May 14, 2021 at 9:41 AM Feifei Wang <feifei.wang2@arm.com> wrote:
> >
> > 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>
> > ---
> >  drivers/crypto/qat/qat_sym_session.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/crypto/qat/qat_sym_session.c
> > b/drivers/crypto/qat/qat_sym_session.c
> > index 231b1640da..dab23a3290 100644
> > --- a/drivers/crypto/qat/qat_sym_session.c
> > +++ b/drivers/crypto/qat/qat_sym_session.c
> > @@ -1190,8 +1190,8 @@ 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 = (uint8_t *)calloc(qat_hash_get_digest_size(
> > +                               ICP_QAT_HW_AUTH_ALGO_DELIMITER),
> > + sizeof(uint8_t));
> 
> calloc can fail.
> cast is unneded.
> 
> A simple uint8_t digest[...] = { 0 } would do the job.

Thanks for your comment. Actually, we have tried to use this simple method:
 uint8_t digest[qat_hash_get_digest_size(ICP_QAT_HW_AUTH_ALGO_DELIMITER)] = {0};

And it will report compile error:
../drivers/crypto/qat/qat_sym_session.c:1194:4: error: variable-sized object may not be initialized
 1194 |    ICP_QAT_HW_AUTH_ALGO_DELIMITER)] = {0};
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../drivers/crypto/qat/qat_sym_session.c:1194:40: warning: excess elements in array initializer
 1194 |    ICP_QAT_HW_AUTH_ALGO_DELIMITER)] = {0};
      |                                        ^
../drivers/crypto/qat/qat_sym_session.c:1194:40: note: (near initialization for ‘digest’)
ninja: build stopped: subcommand failed.

I think this is because compiler cannot know the size of digest due to function
'qat_hash_get_digest_size' during  compiling time.

Best Regards
Feifei
> 
> 
> >         uint32_t *hash_state_out_be32;
> >         uint64_t *hash_state_out_be64;
> >         int i;
> > --
> > 2.25.1
> >
> 
> 
> 
> --
> David Marchand
  
David Marchand May 14, 2021, 8:13 a.m. UTC | #3
On Fri, May 14, 2021 at 10:01 AM Feifei Wang <Feifei.Wang2@arm.com> wrote:
> > > @@ -1190,8 +1190,8 @@ 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 = (uint8_t *)calloc(qat_hash_get_digest_size(
> > > +                               ICP_QAT_HW_AUTH_ALGO_DELIMITER),
> > > + sizeof(uint8_t));
> >
> > calloc can fail.
> > cast is unneded.
> >
> > A simple uint8_t digest[...] = { 0 } would do the job.
>
> Thanks for your comment. Actually, we have tried to use this simple method:
>  uint8_t digest[qat_hash_get_digest_size(ICP_QAT_HW_AUTH_ALGO_DELIMITER)] = {0};
>
> And it will report compile error:
> ../drivers/crypto/qat/qat_sym_session.c:1194:4: error: variable-sized object may not be initialized
>  1194 |    ICP_QAT_HW_AUTH_ALGO_DELIMITER)] = {0};
>       |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../drivers/crypto/qat/qat_sym_session.c:1194:40: warning: excess elements in array initializer
>  1194 |    ICP_QAT_HW_AUTH_ALGO_DELIMITER)] = {0};
>       |                                        ^
> ../drivers/crypto/qat/qat_sym_session.c:1194:40: note: (near initialization for ‘digest’)
> ninja: build stopped: subcommand failed.
>
> I think this is because compiler cannot know the size of digest due to function
> 'qat_hash_get_digest_size' during  compiling time.

Ok, I had not noticed the function call.

Please check dynamic allocation succeeds.
+ free this temp buffer before leaving this helper function.
  
Feifei Wang May 14, 2021, 8:30 a.m. UTC | #4
> -----邮件原件-----
> 发件人: David Marchand <david.marchand@redhat.com>
> 发送时间: 2021年5月14日 16:14
> 收件人: Feifei Wang <Feifei.Wang2@arm.com>
> 抄送: John Griffin <john.griffin@intel.com>; Fiona Trahe
> <fiona.trahe@intel.com>; Deepak Kumar Jain <deepak.k.jain@intel.com>;
> Herbert Guan <Herbert.Guan@arm.com>; Jerin Jacob
> <jerin.jacob@caviumnetworks.com>; dev <dev@dpdk.org>; nd
> <nd@arm.com>; dpdk stable <stable@dpdk.org>; Ruifeng Wang
> <Ruifeng.Wang@arm.com>
> 主题: Re: [dpdk-stable] [PATCH] crypto/qat: fix uninitilized compiler warning
> 
> On Fri, May 14, 2021 at 10:01 AM Feifei Wang <Feifei.Wang2@arm.com>
> wrote:
> > > > @@ -1190,8 +1190,8 @@ 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 = (uint8_t *)calloc(qat_hash_get_digest_size(
> > > > +                               ICP_QAT_HW_AUTH_ALGO_DELIMITER),
> > > > + sizeof(uint8_t));
> > >
> > > calloc can fail.
> > > cast is unneded.
> > >
> > > A simple uint8_t digest[...] = { 0 } would do the job.
> >
> > Thanks for your comment. Actually, we have tried to use this simple
> method:
> >  uint8_t
> > digest[qat_hash_get_digest_size(ICP_QAT_HW_AUTH_ALGO_DELIMITER)]
> =
> > {0};
> >
> > And it will report compile error:
> > ../drivers/crypto/qat/qat_sym_session.c:1194:4: error: variable-sized
> object may not be initialized
> >  1194 |    ICP_QAT_HW_AUTH_ALGO_DELIMITER)] = {0};
> >       |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > ../drivers/crypto/qat/qat_sym_session.c:1194:40: warning: excess
> elements in array initializer
> >  1194 |    ICP_QAT_HW_AUTH_ALGO_DELIMITER)] = {0};
> >       |                                        ^
> > ../drivers/crypto/qat/qat_sym_session.c:1194:40: note: (near
> > initialization for ‘digest’)
> > ninja: build stopped: subcommand failed.
> >
> > I think this is because compiler cannot know the size of digest due to
> > function 'qat_hash_get_digest_size' during  compiling time.
> 
> Ok, I had not noticed the function call.
> 
> Please check dynamic allocation succeeds.
> + free this temp buffer before leaving this helper function.

Thanks for this comments, I will add check and free operations for this dynamic allocation
in the next version

Best Regards
Feifei 
> 
> 
> --
> David marchand
  

Patch

diff --git a/drivers/crypto/qat/qat_sym_session.c b/drivers/crypto/qat/qat_sym_session.c
index 231b1640da..dab23a3290 100644
--- a/drivers/crypto/qat/qat_sym_session.c
+++ b/drivers/crypto/qat/qat_sym_session.c
@@ -1190,8 +1190,8 @@  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 = (uint8_t *)calloc(qat_hash_get_digest_size(
+				ICP_QAT_HW_AUTH_ALGO_DELIMITER), sizeof(uint8_t));
 	uint32_t *hash_state_out_be32;
 	uint64_t *hash_state_out_be64;
 	int i;