Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: dsa: store CPU switch structure in the tree

Store a dsa_switch pointer to the CPU switch in the tree instead of only
its index. This avoids the need to initialize it to -1.

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Vivien Didelot and committed by
David S. Miller
b22de490 e33c2ef1

+9 -11
+4 -4
include/net/dsa.h
··· 124 124 /* 125 125 * The switch and port to which the CPU is attached. 126 126 */ 127 - s8 cpu_switch; 127 + struct dsa_switch *cpu_switch; 128 128 s8 cpu_port; 129 129 130 130 /* ··· 204 204 205 205 static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p) 206 206 { 207 - return !!(ds->index == ds->dst->cpu_switch && p == ds->dst->cpu_port); 207 + return !!(ds == ds->dst->cpu_switch && p == ds->dst->cpu_port); 208 208 } 209 209 210 210 static inline bool dsa_is_dsa_port(struct dsa_switch *ds, int p) ··· 227 227 * Else return the (DSA) port number that connects to the 228 228 * switch that is one hop closer to the cpu. 229 229 */ 230 - if (dst->cpu_switch == ds->index) 230 + if (dst->cpu_switch == ds) 231 231 return dst->cpu_port; 232 232 else 233 - return ds->rtable[dst->cpu_switch]; 233 + return ds->rtable[dst->cpu_switch->index]; 234 234 } 235 235 236 236 struct switchdev_trans;
+3 -4
net/dsa/dsa.c
··· 225 225 continue; 226 226 227 227 if (!strcmp(name, "cpu")) { 228 - if (dst->cpu_switch != -1) { 228 + if (!dst->cpu_switch) { 229 229 netdev_err(dst->master_netdev, 230 230 "multiple cpu ports?!\n"); 231 231 return -EINVAL; 232 232 } 233 - dst->cpu_switch = index; 233 + dst->cpu_switch = ds; 234 234 dst->cpu_port = i; 235 235 ds->cpu_port_mask |= 1 << i; 236 236 } else if (!strcmp(name, "dsa")) { ··· 254 254 * tagging protocol to the preferred tagging format of this 255 255 * switch. 256 256 */ 257 - if (dst->cpu_switch == index) { 257 + if (dst->cpu_switch == ds) { 258 258 enum dsa_tag_protocol tag_protocol; 259 259 260 260 tag_protocol = ops->get_tag_protocol(ds); ··· 757 757 758 758 dst->pd = pd; 759 759 dst->master_netdev = dev; 760 - dst->cpu_switch = -1; 761 760 dst->cpu_port = -1; 762 761 763 762 for (i = 0; i < pd->nr_chips; i++) {
+2 -3
net/dsa/dsa2.c
··· 57 57 if (!dst) 58 58 return NULL; 59 59 dst->tree = tree; 60 - dst->cpu_switch = -1; 61 60 INIT_LIST_HEAD(&dst->list); 62 61 list_add_tail(&dsa_switch_trees, &dst->list); 63 62 kref_init(&dst->refcount); ··· 447 448 if (!dst->master_netdev) 448 449 dst->master_netdev = ethernet_dev; 449 450 450 - if (dst->cpu_switch == -1) { 451 - dst->cpu_switch = ds->index; 451 + if (!dst->cpu_switch) { 452 + dst->cpu_switch = ds; 452 453 dst->cpu_port = index; 453 454 } 454 455