2012-05-14 21:56:00

by Sasha Levin

[permalink] [raw]
Subject: [PATCH v2] net: codel: fix build errors

Fix the following build error:

net/sched/sch_fq_codel.c: In function 'fq_codel_dump_stats':
net/sched/sch_fq_codel.c:464:3: error: unknown field 'qdisc_stats' specified in initializer
net/sched/sch_fq_codel.c:464:3: warning: missing braces around initializer
net/sched/sch_fq_codel.c:464:3: warning: (near initialization for 'st.<anonymous>')
net/sched/sch_fq_codel.c:465:3: error: unknown field 'qdisc_stats' specified in initializer
net/sched/sch_fq_codel.c:465:3: warning: excess elements in struct initializer
net/sched/sch_fq_codel.c:465:3: warning: (near initialization for 'st')
net/sched/sch_fq_codel.c:466:3: error: unknown field 'qdisc_stats' specified in initializer
net/sched/sch_fq_codel.c:466:3: warning: excess elements in struct initializer
net/sched/sch_fq_codel.c:466:3: warning: (near initialization for 'st')
net/sched/sch_fq_codel.c:467:3: error: unknown field 'qdisc_stats' specified in initializer
net/sched/sch_fq_codel.c:467:3: warning: excess elements in struct initializer
net/sched/sch_fq_codel.c:467:3: warning: (near initialization for 'st')
make[1]: *** [net/sched/sch_fq_codel.o] Error 1

Signed-off-by: Sasha Levin <[email protected]>
---
net/sched/sch_fq_codel.c | 9 +++++----
1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/net/sched/sch_fq_codel.c b/net/sched/sch_fq_codel.c
index a7b3754..337ff20 100644
--- a/net/sched/sch_fq_codel.c
+++ b/net/sched/sch_fq_codel.c
@@ -461,13 +461,14 @@ static int fq_codel_dump_stats(struct Qdisc *sch, struct gnet_dump *d)
struct fq_codel_sched_data *q = qdisc_priv(sch);
struct tc_fq_codel_xstats st = {
.type = TCA_FQ_CODEL_XSTATS_QDISC,
- .qdisc_stats.maxpacket = q->cstats.maxpacket,
- .qdisc_stats.drop_overlimit = q->drop_overlimit,
- .qdisc_stats.ecn_mark = q->cstats.ecn_mark,
- .qdisc_stats.new_flow_count = q->new_flow_count,
};
struct list_head *pos;

+ st.qdisc_stats.maxpacket = q->cstats.maxpacket;
+ st.qdisc_stats.drop_overlimit = q->drop_overlimit;
+ st.qdisc_stats.ecn_mark = q->cstats.ecn_mark;
+ st.qdisc_stats.new_flow_count = q->new_flow_count;
+
list_for_each(pos, &q->new_flows)
st.qdisc_stats.new_flows_len++;

--
1.7.8.6


2012-05-14 22:00:28

by David Miller

[permalink] [raw]
Subject: Re: [PATCH v2] net: codel: fix build errors

From: Sasha Levin <[email protected]>
Date: Mon, 14 May 2012 23:57:06 +0200

> Fix the following build error:
...
> Signed-off-by: Sasha Levin <[email protected]>

Applied, but:

> struct tc_fq_codel_xstats st = {
> .type = TCA_FQ_CODEL_XSTATS_QDISC,
> - .qdisc_stats.maxpacket = q->cstats.maxpacket,
> - .qdisc_stats.drop_overlimit = q->drop_overlimit,
> - .qdisc_stats.ecn_mark = q->cstats.ecn_mark,
> - .qdisc_stats.new_flow_count = q->new_flow_count,
> };
> struct list_head *pos;
>
> + st.qdisc_stats.maxpacket = q->cstats.maxpacket;
> + st.qdisc_stats.drop_overlimit = q->drop_overlimit;
> + st.qdisc_stats.ecn_mark = q->cstats.ecn_mark;
> + st.qdisc_stats.new_flow_count = q->new_flow_count;
> +

This is now a very inefficient initialization of this structure.

GCC is going to fill all the non-explictly-initialized fields with
zero, then we'll write to the same fields again in the st.qdisc*
assignments.

Eric please resolve this, I hate knowing we have code like this :-)

2012-05-14 22:00:46

by Eric Dumazet

[permalink] [raw]
Subject: Re: [PATCH v2] net: codel: fix build errors

On Mon, 2012-05-14 at 23:57 +0200, Sasha Levin wrote:
> Fix the following build error:
>
> net/sched/sch_fq_codel.c: In function 'fq_codel_dump_stats':
> net/sched/sch_fq_codel.c:464:3: error: unknown field 'qdisc_stats' specified in initializer
> net/sched/sch_fq_codel.c:464:3: warning: missing braces around initializer
> net/sched/sch_fq_codel.c:464:3: warning: (near initialization for 'st.<anonymous>')
> net/sched/sch_fq_codel.c:465:3: error: unknown field 'qdisc_stats' specified in initializer
> net/sched/sch_fq_codel.c:465:3: warning: excess elements in struct initializer
> net/sched/sch_fq_codel.c:465:3: warning: (near initialization for 'st')
> net/sched/sch_fq_codel.c:466:3: error: unknown field 'qdisc_stats' specified in initializer
> net/sched/sch_fq_codel.c:466:3: warning: excess elements in struct initializer
> net/sched/sch_fq_codel.c:466:3: warning: (near initialization for 'st')
> net/sched/sch_fq_codel.c:467:3: error: unknown field 'qdisc_stats' specified in initializer
> net/sched/sch_fq_codel.c:467:3: warning: excess elements in struct initializer
> net/sched/sch_fq_codel.c:467:3: warning: (near initialization for 'st')
> make[1]: *** [net/sched/sch_fq_codel.o] Error 1
>
> Signed-off-by: Sasha Levin <[email protected]>
> ---

Acked-by: Eric Dumazet <[email protected]>

2012-05-14 22:05:49

by Stephen Hemminger

[permalink] [raw]
Subject: Re: [PATCH v2] net: codel: fix build errors

On Mon, 14 May 2012 23:57:06 +0200
Sasha Levin <[email protected]> wrote:

> Fix the following build error:
>
> net/sched/sch_fq_codel.c: In function 'fq_codel_dump_stats':
> net/sched/sch_fq_codel.c:464:3: error: unknown field 'qdisc_stats' specified in initializer
> net/sched/sch_fq_codel.c:464:3: warning: missing braces around initializer
> net/sched/sch_fq_codel.c:464:3: warning: (near initialization for 'st.<anonymous>')
> net/sched/sch_fq_codel.c:465:3: error: unknown field 'qdisc_stats' specified in initializer
> net/sched/sch_fq_codel.c:465:3: warning: excess elements in struct initializer
> net/sched/sch_fq_codel.c:465:3: warning: (near initialization for 'st')
> net/sched/sch_fq_codel.c:466:3: error: unknown field 'qdisc_stats' specified in initializer
> net/sched/sch_fq_codel.c:466:3: warning: excess elements in struct initializer
> net/sched/sch_fq_codel.c:466:3: warning: (near initialization for 'st')
> net/sched/sch_fq_codel.c:467:3: error: unknown field 'qdisc_stats' specified in initializer
> net/sched/sch_fq_codel.c:467:3: warning: excess elements in struct initializer
> net/sched/sch_fq_codel.c:467:3: warning: (near initialization for 'st')
> make[1]: *** [net/sched/sch_fq_codel.o] Error 1
>
> Signed-off-by: Sasha Levin <[email protected]>
> ---
> net/sched/sch_fq_codel.c | 9 +++++----
> 1 files changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/net/sched/sch_fq_codel.c b/net/sched/sch_fq_codel.c
> index a7b3754..337ff20 100644
> --- a/net/sched/sch_fq_codel.c
> +++ b/net/sched/sch_fq_codel.c
> @@ -461,13 +461,14 @@ static int fq_codel_dump_stats(struct Qdisc *sch, struct gnet_dump *d)
> struct fq_codel_sched_data *q = qdisc_priv(sch);
> struct tc_fq_codel_xstats st = {
> .type = TCA_FQ_CODEL_XSTATS_QDISC,
> - .qdisc_stats.maxpacket = q->cstats.maxpacket,
> - .qdisc_stats.drop_overlimit = q->drop_overlimit,
> - .qdisc_stats.ecn_mark = q->cstats.ecn_mark,
> - .qdisc_stats.new_flow_count = q->new_flow_count,
> };
> struct list_head *pos;
>
> + st.qdisc_stats.maxpacket = q->cstats.maxpacket;
> + st.qdisc_stats.drop_overlimit = q->drop_overlimit;
> + st.qdisc_stats.ecn_mark = q->cstats.ecn_mark;
> + st.qdisc_stats.new_flow_count = q->new_flow_count;
> +
> list_for_each(pos, &q->new_flows)
> st.qdisc_stats.new_flows_len++;
>

Cleaner and simpler to just use nested initialization.
struct tc_fq_codel_xstats st = {
.type = TCA_FQ_CODEL_XSTATS_QDISC,
.qdisc_stats = {
.maxpacket = q->cstats.maxpacket,
.drop_overlimit = q->drop_overlimit,
.ecn_mark = q->cstats.ecn_mark,
.new_flow_count = q->new_flow_count,
},
};

2012-05-14 22:10:12

by Sasha Levin

[permalink] [raw]
Subject: Re: [PATCH v2] net: codel: fix build errors

On Tue, May 15, 2012 at 12:05 AM, Stephen Hemminger
<[email protected]> wrote:
> On Mon, 14 May 2012 23:57:06 +0200
> Sasha Levin <[email protected]> wrote:
>
>> Fix the following build error:
>>
>> net/sched/sch_fq_codel.c: In function 'fq_codel_dump_stats':
>> net/sched/sch_fq_codel.c:464:3: error: unknown field 'qdisc_stats' specified in initializer
>> net/sched/sch_fq_codel.c:464:3: warning: missing braces around initializer
>> net/sched/sch_fq_codel.c:464:3: warning: (near initialization for 'st.<anonymous>')
>> net/sched/sch_fq_codel.c:465:3: error: unknown field 'qdisc_stats' specified in initializer
>> net/sched/sch_fq_codel.c:465:3: warning: excess elements in struct initializer
>> net/sched/sch_fq_codel.c:465:3: warning: (near initialization for 'st')
>> net/sched/sch_fq_codel.c:466:3: error: unknown field 'qdisc_stats' specified in initializer
>> net/sched/sch_fq_codel.c:466:3: warning: excess elements in struct initializer
>> net/sched/sch_fq_codel.c:466:3: warning: (near initialization for 'st')
>> net/sched/sch_fq_codel.c:467:3: error: unknown field 'qdisc_stats' specified in initializer
>> net/sched/sch_fq_codel.c:467:3: warning: excess elements in struct initializer
>> net/sched/sch_fq_codel.c:467:3: warning: (near initialization for 'st')
>> make[1]: *** [net/sched/sch_fq_codel.o] Error 1
>>
>> Signed-off-by: Sasha Levin <[email protected]>
>> ---
>> ?net/sched/sch_fq_codel.c | ? ?9 +++++----
>> ?1 files changed, 5 insertions(+), 4 deletions(-)
>>
>> diff --git a/net/sched/sch_fq_codel.c b/net/sched/sch_fq_codel.c
>> index a7b3754..337ff20 100644
>> --- a/net/sched/sch_fq_codel.c
>> +++ b/net/sched/sch_fq_codel.c
>> @@ -461,13 +461,14 @@ static int fq_codel_dump_stats(struct Qdisc *sch, struct gnet_dump *d)
>> ? ? ? struct fq_codel_sched_data *q = qdisc_priv(sch);
>> ? ? ? struct tc_fq_codel_xstats st = {
>> ? ? ? ? ? ? ? .type ? ? ? ? ? ? ? ? ? ? ? ? ? = TCA_FQ_CODEL_XSTATS_QDISC,
>> - ? ? ? ? ? ? .qdisc_stats.maxpacket ? ? ? ? ?= q->cstats.maxpacket,
>> - ? ? ? ? ? ? .qdisc_stats.drop_overlimit ? ? = q->drop_overlimit,
>> - ? ? ? ? ? ? .qdisc_stats.ecn_mark ? ? ? ? ? = q->cstats.ecn_mark,
>> - ? ? ? ? ? ? .qdisc_stats.new_flow_count ? ? = q->new_flow_count,
>> ? ? ? };
>> ? ? ? struct list_head *pos;
>>
>> + ? ? st.qdisc_stats.maxpacket = q->cstats.maxpacket;
>> + ? ? st.qdisc_stats.drop_overlimit = q->drop_overlimit;
>> + ? ? st.qdisc_stats.ecn_mark = q->cstats.ecn_mark;
>> + ? ? st.qdisc_stats.new_flow_count = q->new_flow_count;
>> +
>> ? ? ? list_for_each(pos, &q->new_flows)
>> ? ? ? ? ? ? ? st.qdisc_stats.new_flows_len++;
>>
>
> Cleaner and simpler to just use nested initialization.
> ? ? ? ?struct tc_fq_codel_xstats st = {
> ? ? ? ? ? ? ? ?.type ? ? ? ? ? ? ? ? ? ? ? ? ? = TCA_FQ_CODEL_XSTATS_QDISC,
> ? ? ? ? ? ? ? ?.qdisc_stats = {
> ? ? ? ? ? ? ? ? ? ? ? ?.maxpacket ? ? ?= q->cstats.maxpacket,
> ? ? ? ? ? ? ? ? ? ? ? ?.drop_overlimit = q->drop_overlimit,
> ? ? ? ? ? ? ? ? ? ? ? ?.ecn_mark ? ? ? = q->cstats.ecn_mark,
> ? ? ? ? ? ? ? ? ? ? ? ?.new_flow_count = q->new_flow_count,
> ? ? ? ? ? ? ? ?},
> ? ? ? ?};

You'll get the same errors. You can't directly initialize members that
are in an anonymous union.