Skip to contentSkip to conversation

net: bridge: add compile-time assert for cb struct size

PATCH Superseded Florian Westphal 2 participants 2 messages Mar 3, 2015

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: bridge: add compile-time assert for cb struct size

make build fail if struct doesn't fit into ->cb storage area.

---
 net/bridge/br.c | 3 +++
 1 file changed, 3 insertions(+)
net/bridge/br.c +3 -0
index fb57ab6..9542c53 100644
@@ -188,8 +188,11 @@ static const struct stp_proto br_stp_proto = {
 
 static int __init br_init(void)
 {
+	struct sk_buff *skb;
 	int err;
 
+	BUILD_BUG_ON(sizeof(struct br_input_skb_cb) > sizeof(skb->cb));
+
 	err = stp_proto_register(&br_stp_proto);
 	if (err < 0) {
 		pr_err("bridge: can't register sap for STP\n");
Signature · 1 line
2.0.5
maintainer
#1 lore raw

From: Florian Westphal <[email protected]>
Date: Tue, 3 Mar 2015 03:50:22 +0100

net/bridge/br.c static const struct stp_proto br_stp_proto = { · line 198

Quoted 12 lines
net/bridge/br.c +3 -0
@@ -188,8 +188,11 @@ static const struct stp_proto br_stp_proto = {
 
 static int __init br_init(void)
 {
+	struct sk_buff *skb;
 	int err;
 
+	BUILD_BUG_ON(sizeof(struct br_input_skb_cb) > sizeof(skb->cb));
+
 	err = stp_proto_register(&br_stp_proto);
 	if (err < 0) {
 		pr_err("bridge: can't register sap for STP\n");

The canonical way to do this, unless you needed the 'skb' variable for another reason, is to use FIELD_SIZEOF().