netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: ethernet: mscc: fix missing brace warning for old compilers
@ 2020-11-02 13:41 Pujin Shi
  2020-11-02 13:56 ` Vladimir Oltean
  0 siblings, 1 reply; 5+ messages in thread
From: Pujin Shi @ 2020-11-02 13:41 UTC (permalink / raw)
  To: Jakub Kicinski, David S . Miller
  Cc: Microchip Linux Driver Support, Vladimir Oltean, Claudiu Manoil,
	Alexandre Belloni, Xiaoliang Yang, netdev, linux-kernel,
	Pujin Shi

For older versions of gcc, the array = {0}; will cause warnings:

drivers/net/ethernet/mscc/ocelot_vcap.c: In function 'is1_entry_set':
drivers/net/ethernet/mscc/ocelot_vcap.c:755:11: warning: missing braces around initializer [-Wmissing-braces]
    struct ocelot_vcap_u16 etype = {0};
           ^
drivers/net/ethernet/mscc/ocelot_vcap.c:755:11: warning: (near initialization for 'etype.value') [-Wmissing-braces]

1 warnings generated

Fixes: 75944fda1dfe ("net: mscc: ocelot: offload ingress skbedit and vlan actions to VCAP IS1")
Signed-off-by: Pujin Shi <shipujin.t@gmail.com>
---
 drivers/net/ethernet/mscc/ocelot_vcap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mscc/ocelot_vcap.c b/drivers/net/ethernet/mscc/ocelot_vcap.c
index d8c778ee6f1b..b96eab4583e7 100644
--- a/drivers/net/ethernet/mscc/ocelot_vcap.c
+++ b/drivers/net/ethernet/mscc/ocelot_vcap.c
@@ -752,7 +752,7 @@ static void is1_entry_set(struct ocelot *ocelot, int ix,
 					     dport);
 		} else {
 			/* IPv4 "other" frame */
-			struct ocelot_vcap_u16 etype = {0};
+			struct ocelot_vcap_u16 etype = {};
 
 			/* Overloaded field */
 			etype.value[0] = proto.value[0];
-- 
2.18.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: ethernet: mscc: fix missing brace warning for old compilers
  2020-11-02 13:41 [PATCH] net: ethernet: mscc: fix missing brace warning for old compilers Pujin Shi
@ 2020-11-02 13:56 ` Vladimir Oltean
  2020-11-02 17:32   ` David Sterba
  2020-11-02 22:08   ` Jakub Kicinski
  0 siblings, 2 replies; 5+ messages in thread
From: Vladimir Oltean @ 2020-11-02 13:56 UTC (permalink / raw)
  To: Pujin Shi
  Cc: Jakub Kicinski, David S . Miller, Microchip Linux Driver Support,
	Claudiu Manoil, Alexandre Belloni, Xiaoliang Yang,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org

On Mon, Nov 02, 2020 at 09:41:36PM +0800, Pujin Shi wrote:
> For older versions of gcc, the array = {0}; will cause warnings:
> 
> drivers/net/ethernet/mscc/ocelot_vcap.c: In function 'is1_entry_set':
> drivers/net/ethernet/mscc/ocelot_vcap.c:755:11: warning: missing braces around initializer [-Wmissing-braces]
>     struct ocelot_vcap_u16 etype = {0};
>            ^
> drivers/net/ethernet/mscc/ocelot_vcap.c:755:11: warning: (near initialization for 'etype.value') [-Wmissing-braces]
> 
> 1 warnings generated
> 
> Fixes: 75944fda1dfe ("net: mscc: ocelot: offload ingress skbedit and vlan actions to VCAP IS1")
> Signed-off-by: Pujin Shi <shipujin.t@gmail.com>
> ---
>  drivers/net/ethernet/mscc/ocelot_vcap.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/mscc/ocelot_vcap.c b/drivers/net/ethernet/mscc/ocelot_vcap.c
> index d8c778ee6f1b..b96eab4583e7 100644
> --- a/drivers/net/ethernet/mscc/ocelot_vcap.c
> +++ b/drivers/net/ethernet/mscc/ocelot_vcap.c
> @@ -752,7 +752,7 @@ static void is1_entry_set(struct ocelot *ocelot, int ix,
>  					     dport);
>  		} else {
>  			/* IPv4 "other" frame */
> -			struct ocelot_vcap_u16 etype = {0};
> +			struct ocelot_vcap_u16 etype = {};
>  
>  			/* Overloaded field */
>  			etype.value[0] = proto.value[0];
> -- 
> 2.18.1
> 

Sorry, I don't understand what the problem is, or why your patch fixes
it. What version of gcc are you testing with?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: ethernet: mscc: fix missing brace warning for old compilers
  2020-11-02 13:56 ` Vladimir Oltean
@ 2020-11-02 17:32   ` David Sterba
  2020-11-02 22:08   ` Jakub Kicinski
  1 sibling, 0 replies; 5+ messages in thread
From: David Sterba @ 2020-11-02 17:32 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: Pujin Shi, Jakub Kicinski, David S . Miller,
	Microchip Linux Driver Support, Claudiu Manoil, Alexandre Belloni,
	Xiaoliang Yang, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org

On Mon, Nov 02, 2020 at 01:56:55PM +0000, Vladimir Oltean wrote:
> On Mon, Nov 02, 2020 at 09:41:36PM +0800, Pujin Shi wrote:
> > For older versions of gcc, the array = {0}; will cause warnings:
> > 
> > drivers/net/ethernet/mscc/ocelot_vcap.c: In function 'is1_entry_set':
> > drivers/net/ethernet/mscc/ocelot_vcap.c:755:11: warning: missing braces around initializer [-Wmissing-braces]
> >     struct ocelot_vcap_u16 etype = {0};
> >            ^
> > drivers/net/ethernet/mscc/ocelot_vcap.c:755:11: warning: (near initialization for 'etype.value') [-Wmissing-braces]
> > 
> > 1 warnings generated
> > 
> > Fixes: 75944fda1dfe ("net: mscc: ocelot: offload ingress skbedit and vlan actions to VCAP IS1")
> > Signed-off-by: Pujin Shi <shipujin.t@gmail.com>
> > ---
> >  drivers/net/ethernet/mscc/ocelot_vcap.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/net/ethernet/mscc/ocelot_vcap.c b/drivers/net/ethernet/mscc/ocelot_vcap.c
> > index d8c778ee6f1b..b96eab4583e7 100644
> > --- a/drivers/net/ethernet/mscc/ocelot_vcap.c
> > +++ b/drivers/net/ethernet/mscc/ocelot_vcap.c
> > @@ -752,7 +752,7 @@ static void is1_entry_set(struct ocelot *ocelot, int ix,
> >  					     dport);
> >  		} else {
> >  			/* IPv4 "other" frame */
> > -			struct ocelot_vcap_u16 etype = {0};
> > +			struct ocelot_vcap_u16 etype = {};
> >  
> >  			/* Overloaded field */
> >  			etype.value[0] = proto.value[0];
> 
> Sorry, I don't understand what the problem is, or why your patch fixes
> it. What version of gcc are you testing with?

Nothing wrong and { 0 } is the right initializer, the reports must be
from some ancient gcc but we weren't told which one either.

https://lore.kernel.org/linux-btrfs/fbddb15a-6e46-3f21-23ba-b18f66e3448a@suse.com/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: ethernet: mscc: fix missing brace warning for old compilers
  2020-11-02 13:56 ` Vladimir Oltean
  2020-11-02 17:32   ` David Sterba
@ 2020-11-02 22:08   ` Jakub Kicinski
  2020-11-02 23:19     ` Vladimir Oltean
  1 sibling, 1 reply; 5+ messages in thread
From: Jakub Kicinski @ 2020-11-02 22:08 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: Pujin Shi, David S . Miller, Microchip Linux Driver Support,
	Claudiu Manoil, Alexandre Belloni, Xiaoliang Yang,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org

On Mon, 2 Nov 2020 13:56:55 +0000 Vladimir Oltean wrote:
> On Mon, Nov 02, 2020 at 09:41:36PM +0800, Pujin Shi wrote:
> > For older versions of gcc, the array = {0}; will cause warnings:
> > 
> > drivers/net/ethernet/mscc/ocelot_vcap.c: In function 'is1_entry_set':
> > drivers/net/ethernet/mscc/ocelot_vcap.c:755:11: warning: missing braces around initializer [-Wmissing-braces]
> >     struct ocelot_vcap_u16 etype = {0};
> >            ^
> > drivers/net/ethernet/mscc/ocelot_vcap.c:755:11: warning: (near initialization for 'etype.value') [-Wmissing-braces]
> > 
> > 1 warnings generated
> > 
> > Fixes: 75944fda1dfe ("net: mscc: ocelot: offload ingress skbedit and vlan actions to VCAP IS1")
> > Signed-off-by: Pujin Shi <shipujin.t@gmail.com>
> > ---
> >  drivers/net/ethernet/mscc/ocelot_vcap.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/net/ethernet/mscc/ocelot_vcap.c b/drivers/net/ethernet/mscc/ocelot_vcap.c
> > index d8c778ee6f1b..b96eab4583e7 100644
> > --- a/drivers/net/ethernet/mscc/ocelot_vcap.c
> > +++ b/drivers/net/ethernet/mscc/ocelot_vcap.c
> > @@ -752,7 +752,7 @@ static void is1_entry_set(struct ocelot *ocelot, int ix,
> >  					     dport);
> >  		} else {
> >  			/* IPv4 "other" frame */
> > -			struct ocelot_vcap_u16 etype = {0};
> > +			struct ocelot_vcap_u16 etype = {};
> >  
> 
> Sorry, I don't understand what the problem is, or why your patch fixes
> it. What version of gcc are you testing with?

Old GCC does not like the 0, if the members of struct are not scalars.

struct ocelot_vcap_u16 {                                                        
        u8 value[2];                                                            
        u8 mask[2];                                                             
};

In this case the first member is an array.

It wants us to add another curly brace:

struct ocelot_vcap_u16 etype = {{0}};

... or we can just skip the 0.

That's just FWIW. I don't remember which versions of GCC behave like
that, I just know we get a constant stream of this sort of fixes.
I think clang may generate a similar warning.

Pujin, please specify the version of GCC you're using and repost.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: ethernet: mscc: fix missing brace warning for old compilers
  2020-11-02 22:08   ` Jakub Kicinski
@ 2020-11-02 23:19     ` Vladimir Oltean
  0 siblings, 0 replies; 5+ messages in thread
From: Vladimir Oltean @ 2020-11-02 23:19 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Pujin Shi, David S . Miller, Microchip Linux Driver Support,
	Claudiu Manoil, Alexandre Belloni, Xiaoliang Yang,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org

On Mon, Nov 02, 2020 at 02:08:08PM -0800, Jakub Kicinski wrote:
> Old GCC does not like the 0, if the members of struct are not scalars.
>
> struct ocelot_vcap_u16 {
>         u8 value[2];
>         u8 mask[2];
> };
>
> In this case the first member is an array.
>
> It wants us to add another curly brace:
>
> struct ocelot_vcap_u16 etype = {{0}};
>
> ... or we can just skip the 0.

I am reading that the empty set initializer is a GNU extension. I would
not like to see yet another patch from clang folks coming as a follow-up
to this one.

> That's just FWIW. I don't remember which versions of GCC behave like
> that, I just know we get a constant stream of this sort of fixes.
> I think clang may generate a similar warning.
>
> Pujin, please specify the version of GCC you're using and repost.

If the initializer really has to be changed, I would prefer to see a memset.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-11-02 23:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-02 13:41 [PATCH] net: ethernet: mscc: fix missing brace warning for old compilers Pujin Shi
2020-11-02 13:56 ` Vladimir Oltean
2020-11-02 17:32   ` David Sterba
2020-11-02 22:08   ` Jakub Kicinski
2020-11-02 23:19     ` Vladimir Oltean

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