net/sch_generic.h: use sizeof_member() and get rid of unused variable
Subsystems (5)
PATCH 1/1 net/sch_generic.h: use sizeof_member() and get rid of unused variable
Compiling with -Wunused triggers the following warning:
./include/net/sch_generic.h: In function ‘qdisc_cb_private_validate’:./include/net/sch_generic.h:464:23: warning: unused variable ‘qcb’ [-Wunused-variable]
464 | struct qdisc_skb_cb *qcb;
| ^~~
as the qcb variable is only used to compute the sizeof one of its members.
Get rid of the warning by using the provided sizeof_member() macro and avoid having a variable at all.
At the same time use sizeof_member() also for computing the sizeof skb->cb, thus avoiding ‘qdisc_cb_private_validate’ to have an skb argument at all.
---
Affected code has been compile-tested on x86_64
include/net/codel_qdisc.h | 2 +- include/net/pie.h | 2 +- include/net/sch_generic.h | 9 ++++----- net/sched/sch_cake.c | 2 +- net/sched/sch_choke.c | 2 +- net/sched/sch_fq.c | 2 +- net/sched/sch_netem.c | 2 +- net/sched/sch_sfb.c | 2 +- 8 files changed, 11 insertions(+), 12 deletions(-)
include/net/codel_qdisc.h +1 -1
@@ -57,7 +57,7 @@ struct codel_skb_cb {static struct codel_skb_cb *get_codel_cb (const struct sk_buff *skb) { -qdisc_cb_private_validate (skb,sizeof (struct codel_skb_cb )); +qdisc_cb_private_validate (sizeof (struct codel_skb_cb ));return (struct codel_skb_cb *)qdisc_skb_cb (skb)->data; }
include/net/pie.h +1 -1
@@ -109,7 +109,7 @@ static inline void pie_vars_init(struct pie_vars *vars)static inline struct pie_skb_cb *get_pie_cb (const struct sk_buff *skb) { -qdisc_cb_private_validate (skb,sizeof (struct pie_skb_cb )); +qdisc_cb_private_validate (sizeof (struct pie_skb_cb ));return (struct pie_skb_cb *)qdisc_skb_cb (skb)->data; }
include/net/sch_generic.h +4 -5
@@ -459,12 +459,11 @@ static inline bool lockdep_tcf_proto_is_locked(struct tcf_proto *tp)#define tcf_proto_dereference (p, tp) \ rcu_dereference_protected(p, lockdep_tcf_proto_is_locked(tp)) -static inline void qdisc_cb_private_validate (const struct sk_buff *skb,int sz) +static inline void qdisc_cb_private_validate (int sz) { -struct qdisc_skb_cb *qcb; - -BUILD_BUG_ON (sizeof (skb->cb) < offsetof(struct qdisc_skb_cb , data) + sz); -BUILD_BUG_ON (sizeof (qcb->data) < sz); + BUILD_BUG_ON(sizeof_field(struct sk_buff, cb) < + offsetof(struct qdisc_skb_cb, data) + sz); + BUILD_BUG_ON(sizeof_field(struct qdisc_skb_cb, data) < sz); }static inline int qdisc_qlen_cpu (const struct Qdisc *q)
net/sched/sch_cake.c +1 -1
@@ -281,7 +281,7 @@ static u64 us_to_ns(u64 us)static struct cobalt_skb_cb *get_cobalt_cb (const struct sk_buff *skb) { -qdisc_cb_private_validate (skb,sizeof (struct cobalt_skb_cb )); +qdisc_cb_private_validate (sizeof (struct cobalt_skb_cb ));return (struct cobalt_skb_cb *)qdisc_skb_cb (skb)->data; }
net/sched/sch_choke.c +1 -1
@@ -137,7 +137,7 @@ struct choke_skb_cb {static inline struct choke_skb_cb *choke_skb_cb (const struct sk_buff *skb) { -qdisc_cb_private_validate (skb,sizeof (struct choke_skb_cb )); +qdisc_cb_private_validate (sizeof (struct choke_skb_cb ));return (struct choke_skb_cb *)qdisc_skb_cb (skb)->data; }
net/sched/sch_fq.c +1 -1
@@ -56,7 +56,7 @@ struct fq_skb_cb {static inline struct fq_skb_cb *fq_skb_cb (struct sk_buff *skb) { -qdisc_cb_private_validate (skb,sizeof (struct fq_skb_cb )); +qdisc_cb_private_validate (sizeof (struct fq_skb_cb ));return (struct fq_skb_cb *)qdisc_skb_cb (skb)->data; }
net/sched/sch_netem.c +1 -1
@@ -161,7 +161,7 @@ struct netem_skb_cb {static inline struct netem_skb_cb *netem_skb_cb (struct sk_buff *skb) {/* we assume we can use skb next/prev/tstamp as storage for rb_node */ -qdisc_cb_private_validate (skb,sizeof (struct netem_skb_cb )); +qdisc_cb_private_validate (sizeof (struct netem_skb_cb ));return (struct netem_skb_cb *)qdisc_skb_cb (skb)->data; }
net/sched/sch_sfb.c +1 -1
@@ -91,7 +91,7 @@ struct sfb_skb_cb {static inline struct sfb_skb_cb *sfb_skb_cb (const struct sk_buff *skb) { -qdisc_cb_private_validate (skb,sizeof (struct sfb_skb_cb )); +qdisc_cb_private_validate (sizeof (struct sfb_skb_cb ));return (struct sfb_skb_cb *)qdisc_skb_cb (skb)->data; }
Signature · 1 line
2.26.2
David Miller
maintainerFrom: Antonio Quartulli <[email protected]>
Date: Tue, 19 May 2020 11:13:33 +0200
Quoted 8 lines
Compiling with -Wunused triggers the following warning:
./include/net/sch_generic.h: In function ‘qdisc_cb_private_validate’:./include/net/sch_generic.h:464:23: warning: unused variable ‘qcb’ [-Wunused-variable]
464 | structqdisc_skb_cb*qcb;
| ^~~as the qcb variable is only used to compute the sizeof one of its members.
It's referenced in the code, therefore it is not "unused".
If in some configuration BUILD_BUG_ON() does not reference it's arguments, that's the bug that needs to be fixed.
Hi David,
Quoted 5 lines · David Miller
From: Antonio Quartulli <[email protected]>
Date: Tue, 19 May 2020 11:13:33 +0200Quoted 2 lines
Compiling with -Wunused triggers the following warning:
Quoted 8 lines
Quoted 6 lines
./include/net/sch_generic.h: In function ‘qdisc_cb_private_validate’:./include/net/sch_generic.h:464:23: warning: unused variable ‘qcb’ [-Wunused-variable]
464 | structqdisc_skb_cb*qcb;
| ^~~as the qcb variable is only used to compute the sizeof one of its members.
It's referenced in the code, therefore it is not "unused".
True.
Quoted 4 lines
If in some configuration
BUILD_BUG_ON()does not reference it's arguments, that's the bug that needs to be fixed.
I don't think it's BUILD_BUG_ON()'s fault, because qcb->data is passed to sizeof() first.
My best guess is that gcc is somewhat optimizing the sizeof(gcb->data) and thus leaving the gcb variable unused.
This said, I think it's better for the code style (and for the compiler) if we used sizeof_member().
Should I resend the patch with a commit message that does not mention the "unused" warning?
Thanks a lot.
Best Regards,
Signature · 1 line
Antonio Quartulli
David Miller
maintainerFrom: Antonio Quartulli <[email protected]>
Date: Wed, 20 May 2020 10:39:33 +0200
Quoted 5 lines
I don't think it's BUILD_BUG_ON()'s fault, because
qcb->datais passed tosizeof()first.My best guess is that gcc is somewhat optimizing the
sizeof(gcb->data)and thus leaving the gcb variable unused.
If you remove the argument from the function but leave the BUILD_BUG_ON() calls the same, the compilation will fail.
Any such optimization is therefore unreasonable.
The variable is used otherwise compilation would not fail when you remove it right?
Quoted 9 lines · David Miller
From: Antonio Quartulli <[email protected]>
Date: Wed, 20 May 2020 10:39:33 +0200Quoted 5 lines
I don't think it's BUILD_BUG_ON()'s fault, because
qcb->datais passed tosizeof()first.My best guess is that gcc is somewhat optimizing the
sizeof(gcb->data)and thus leaving the gcb variable unused.
Quoted 7 lines
If you remove the argument from the function but leave the
BUILD_BUG_ON()calls the same, the compilation will fail.Any such optimization is therefore unreasonable.
The variable is used otherwise compilation would not fail when you remove it right?
You're correct.
I guess this should be reported to gcc then.
Regards,
Signature · 1 line
Antonio Quartulli