[dpdk-dev,2/3] crypto: fix pedentic compilation errors

Message ID 7f9e891b0e441a6b949d4b298140efad6936c67e.1511338151.git.nelio.laranjeiro@6wind.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK

Commit Message

Nélio Laranjeiro Nov. 22, 2017, 8:10 a.m. UTC
  /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_crypto.h:126:28: error: ISO C forbids zero-size array ‘sym’ [-Werror=pedantic]
   struct rte_crypto_sym_op sym[0];
                            ^~~

Fixes: d2a4223c4c6d ("cryptodev: do not store pointer to op specific params")
Cc: pablo.de.lara.guarch@intel.com
Cc: stable@dpdk.org

Signed-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
---
 lib/librte_cryptodev/rte_crypto.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

De Lara Guarch, Pablo Nov. 22, 2017, 9:48 a.m. UTC | #1
Hi Nelio,

> -----Original Message-----

> From: Nelio Laranjeiro [mailto:nelio.laranjeiro@6wind.com]

> Sent: Wednesday, November 22, 2017 8:10 AM

> To: Akhil Goyal <akhil.goyal@nxp.com>; Doherty, Declan

> <declan.doherty@intel.com>

> Cc: dev@dpdk.org; De Lara Guarch, Pablo

> <pablo.de.lara.guarch@intel.com>; stable@dpdk.org

> Subject: [PATCH 2/3] crypto: fix pedentic compilation errors

> 

>  /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_crypto.h:126:28:

> error: ISO C forbids zero-size array ‘sym’ [-Werror=pedantic]

>    struct rte_crypto_sym_op sym[0];

>                             ^~~

> 

> Fixes: d2a4223c4c6d ("cryptodev: do not store pointer to op specific

> params")

> Cc: pablo.de.lara.guarch@intel.com

> Cc: stable@dpdk.org

> 

> Signed-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>

> ---

>  lib/librte_cryptodev/rte_crypto.h | 2 +-

>  1 file changed, 1 insertion(+), 1 deletion(-)

> 

> diff --git a/lib/librte_cryptodev/rte_crypto.h

> b/lib/librte_cryptodev/rte_crypto.h

> index 3d672fe7d..dc6e91d1d 100644

> --- a/lib/librte_cryptodev/rte_crypto.h

> +++ b/lib/librte_cryptodev/rte_crypto.h

> @@ -123,7 +123,7 @@ struct rte_crypto_op {

> 

>  	RTE_STD_C11

>  	union {

> -		struct rte_crypto_sym_op sym[0];

> +		struct rte_crypto_sym_op *sym;


This would add extra 64 bits that are not necessary,
as the rte_crypto_sym_op structure is always placed after rte_crypto_op
(this is just a marker).

Is there any other way to fix this error? Which compiler are you using?

Thanks,
Pablo
  
Nélio Laranjeiro Nov. 22, 2017, 10:35 a.m. UTC | #2
Hi Pablo,

On Wed, Nov 22, 2017 at 09:48:47AM +0000, De Lara Guarch, Pablo wrote:
> Hi Nelio,
> 
> > -----Original Message-----
> > From: Nelio Laranjeiro [mailto:nelio.laranjeiro@6wind.com]
> > Sent: Wednesday, November 22, 2017 8:10 AM
> > To: Akhil Goyal <akhil.goyal@nxp.com>; Doherty, Declan
> > <declan.doherty@intel.com>
> > Cc: dev@dpdk.org; De Lara Guarch, Pablo
> > <pablo.de.lara.guarch@intel.com>; stable@dpdk.org
> > Subject: [PATCH 2/3] crypto: fix pedentic compilation errors
> > 
> >  /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_crypto.h:126:28:
> > error: ISO C forbids zero-size array ‘sym’ [-Werror=pedantic]
> >    struct rte_crypto_sym_op sym[0];
> >                             ^~~
> > 
> > Fixes: d2a4223c4c6d ("cryptodev: do not store pointer to op specific
> > params")
> > Cc: pablo.de.lara.guarch@intel.com
> > Cc: stable@dpdk.org
> > 
> > Signed-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
> > ---
> >  lib/librte_cryptodev/rte_crypto.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/lib/librte_cryptodev/rte_crypto.h
> > b/lib/librte_cryptodev/rte_crypto.h
> > index 3d672fe7d..dc6e91d1d 100644
> > --- a/lib/librte_cryptodev/rte_crypto.h
> > +++ b/lib/librte_cryptodev/rte_crypto.h
> > @@ -123,7 +123,7 @@ struct rte_crypto_op {
> > 
> >  	RTE_STD_C11
> >  	union {
> > -		struct rte_crypto_sym_op sym[0];
> > +		struct rte_crypto_sym_op *sym;
> 
> This would add extra 64 bits that are not necessary,
> as the rte_crypto_sym_op structure is always placed after rte_crypto_op
> (this is just a marker).
> 
> Is there any other way to fix this error?

Indeed it is not the correct solution, the point here is RTE_STD_C11 is
wrongly used because even in C11 arrays with size of 0 are not
allowed.  If it was the last attribute of the structure it could have
been replaced with empty brackets but as it is inside an union, it
cannot.  The correct solution is to replace the RTE_STD_C11 by
__extension__.

> Which compiler are you using?

It occurs with any compiler when you enable the pedantic flag under C11.
All DPDK headers have been fix to avoid such issue [1].

Thanks,

[1] http://dpdk.org/ml/archives/dev/2016-April/037051.html
  
Neil Horman Nov. 22, 2017, 1:56 p.m. UTC | #3
On Wed, Nov 22, 2017 at 09:10:17AM +0100, Nelio Laranjeiro wrote:
>  /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_crypto.h:126:28: error: ISO C forbids zero-size array ‘sym’ [-Werror=pedantic]
>    struct rte_crypto_sym_op sym[0];
>                             ^~~
> 
> Fixes: d2a4223c4c6d ("cryptodev: do not store pointer to op specific params")
> Cc: pablo.de.lara.guarch@intel.com
> Cc: stable@dpdk.org
> 
> Signed-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
> ---
>  lib/librte_cryptodev/rte_crypto.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/librte_cryptodev/rte_crypto.h b/lib/librte_cryptodev/rte_crypto.h
> index 3d672fe7d..dc6e91d1d 100644
> --- a/lib/librte_cryptodev/rte_crypto.h
> +++ b/lib/librte_cryptodev/rte_crypto.h
> @@ -123,7 +123,7 @@ struct rte_crypto_op {
>  
>  	RTE_STD_C11
>  	union {
> -		struct rte_crypto_sym_op sym[0];
> +		struct rte_crypto_sym_op *sym;
>  		/**< Symmetric operation parameters */
>  	}; /**< operation specific parameters */
>  };
> -- 
> 2.11.0
> 
> 
As Laura notes, this isn't the right solution.  In addition to adding a 64 bit
pointer, it I think also results in incorrect semantics.  That is to say, the
allocation path for this structure allocates the rte_crypto_op and additional
memory for the sym array contiguously, which the sym[0] syntax correctly
interprets to mean the storage for the array is inline with the structure.
Changing to a pointer means you are using the first elements of the array
storage as your pointer, which could be filled with any old value, leading to
corruption.

If you can't use zero length array semantics (which I assume you cant, as I
don't think clang supports that), a better soution might be to remove the sym
variable entirely, and replace it with a macro that access the sym array as an
offset from the start of the pointer.  That would seem to be an ABI change, but
if you went through that process you would wind up with the same sized struct,
which would be nice

Neil
  
Gaëtan Rivet Nov. 22, 2017, 2:31 p.m. UTC | #4
On Wed, Nov 22, 2017 at 08:56:14AM -0500, Neil Horman wrote:
> On Wed, Nov 22, 2017 at 09:10:17AM +0100, Nelio Laranjeiro wrote:
> >  /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_crypto.h:126:28: error: ISO C forbids zero-size array ‘sym’ [-Werror=pedantic]
> >    struct rte_crypto_sym_op sym[0];
> >                             ^~~
> > 
> > Fixes: d2a4223c4c6d ("cryptodev: do not store pointer to op specific params")
> > Cc: pablo.de.lara.guarch@intel.com
> > Cc: stable@dpdk.org
> > 
> > Signed-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
> > ---
> >  lib/librte_cryptodev/rte_crypto.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/lib/librte_cryptodev/rte_crypto.h b/lib/librte_cryptodev/rte_crypto.h
> > index 3d672fe7d..dc6e91d1d 100644
> > --- a/lib/librte_cryptodev/rte_crypto.h
> > +++ b/lib/librte_cryptodev/rte_crypto.h
> > @@ -123,7 +123,7 @@ struct rte_crypto_op {
> >  
> >  	RTE_STD_C11
> >  	union {
> > -		struct rte_crypto_sym_op sym[0];
> > +		struct rte_crypto_sym_op *sym;
> >  		/**< Symmetric operation parameters */
> >  	}; /**< operation specific parameters */
> >  };
> > -- 
> > 2.11.0
> > 
> > 
> As Laura notes, this isn't the right solution.  In addition to adding a 64 bit
> pointer, it I think also results in incorrect semantics.  That is to say, the
> allocation path for this structure allocates the rte_crypto_op and additional
> memory for the sym array contiguously, which the sym[0] syntax correctly
> interprets to mean the storage for the array is inline with the structure.
> Changing to a pointer means you are using the first elements of the array
> storage as your pointer, which could be filled with any old value, leading to
> corruption.
> 
> If you can't use zero length array semantics (which I assume you cant, as I
> don't think clang supports that), a better soution might be to remove the sym
> variable entirely, and replace it with a macro that access the sym array as an
> offset from the start of the pointer.  That would seem to be an ABI change, but
> if you went through that process you would wind up with the same sized struct,
> which would be nice
> 
> Neil
> 

ISO C forbids zero-size arrays, but ISO C99 allows flexible arrays.
Why is this symbole within a union? Why not remove the union, change
sym[0] to sym[]?
  
De Lara Guarch, Pablo Nov. 22, 2017, 4:50 p.m. UTC | #5
> -----Original Message-----

> From: Gaëtan Rivet [mailto:gaetan.rivet@6wind.com]

> Sent: Wednesday, November 22, 2017 2:32 PM

> To: Neil Horman <nhorman@tuxdriver.com>

> Cc: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>; Akhil Goyal

> <akhil.goyal@nxp.com>; Doherty, Declan <declan.doherty@intel.com>;

> dev@dpdk.org; De Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>;

> stable@dpdk.org

> Subject: Re: [dpdk-dev] [PATCH 2/3] crypto: fix pedentic compilation errors

> 

> On Wed, Nov 22, 2017 at 08:56:14AM -0500, Neil Horman wrote:

> > On Wed, Nov 22, 2017 at 09:10:17AM +0100, Nelio Laranjeiro wrote:

> > >  /root/dpdk/x86_64-native-linuxapp-gcc/include/rte_crypto.h:126:28:

> error: ISO C forbids zero-size array ‘sym’ [-Werror=pedantic]

> > >    struct rte_crypto_sym_op sym[0];

> > >                             ^~~

> > >

> > > Fixes: d2a4223c4c6d ("cryptodev: do not store pointer to op specific

> > > params")

> > > Cc: pablo.de.lara.guarch@intel.com

> > > Cc: stable@dpdk.org

> > >

> > > Signed-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>

> > > ---

> > >  lib/librte_cryptodev/rte_crypto.h | 2 +-

> > >  1 file changed, 1 insertion(+), 1 deletion(-)

> > >

> > > diff --git a/lib/librte_cryptodev/rte_crypto.h

> > > b/lib/librte_cryptodev/rte_crypto.h

> > > index 3d672fe7d..dc6e91d1d 100644

> > > --- a/lib/librte_cryptodev/rte_crypto.h

> > > +++ b/lib/librte_cryptodev/rte_crypto.h

> > > @@ -123,7 +123,7 @@ struct rte_crypto_op {

> > >

> > >  	RTE_STD_C11

> > >  	union {

> > > -		struct rte_crypto_sym_op sym[0];

> > > +		struct rte_crypto_sym_op *sym;

> > >  		/**< Symmetric operation parameters */

> > >  	}; /**< operation specific parameters */  };

> > > --

> > > 2.11.0

> > >

> > >

> > As Laura notes, this isn't the right solution.  In addition to adding a 64 bit

> > pointer, it I think also results in incorrect semantics.  That is to say, the

> > allocation path for this structure allocates the rte_crypto_op and

> additional

> > memory for the sym array contiguously, which the sym[0] syntax

> correctly

> > interprets to mean the storage for the array is inline with the structure.

> > Changing to a pointer means you are using the first elements of the array

> > storage as your pointer, which could be filled with any old value, leading

> to

> > corruption.

> >

> > If you can't use zero length array semantics (which I assume you cant, as I

> > don't think clang supports that), a better soution might be to remove the

> sym

> > variable entirely, and replace it with a macro that access the sym array as

> an

> > offset from the start of the pointer.  That would seem to be an ABI

> change, but

> > if you went through that process you would wind up with the same sized

> struct,

> > which would be nice

> >

> > Neil

> >

> 

> ISO C forbids zero-size arrays, but ISO C99 allows flexible arrays.

> Why is this symbole within a union? Why not remove the union, change

> sym[0] to sym[]?


It is a union because there were going to be other types of crypto operations (might still happen in the future).
For instance:

union{
	struct rte_crypto_sym_op sym[0];
	struct rte_crypto_asym_op asym[0];
}

Thanks,
Pablo
> 

> --

> Gaëtan Rivet

> 6WIND
  

Patch

diff --git a/lib/librte_cryptodev/rte_crypto.h b/lib/librte_cryptodev/rte_crypto.h
index 3d672fe7d..dc6e91d1d 100644
--- a/lib/librte_cryptodev/rte_crypto.h
+++ b/lib/librte_cryptodev/rte_crypto.h
@@ -123,7 +123,7 @@  struct rte_crypto_op {
 
 	RTE_STD_C11
 	union {
-		struct rte_crypto_sym_op sym[0];
+		struct rte_crypto_sym_op *sym;
 		/**< Symmetric operation parameters */
 	}; /**< operation specific parameters */
 };