404389dc482bf6eb5e5d92ed6ca1006cb28fd2c6
[openwrt/staging/jogo.git] /
1 From d12e1c4649883e8ca5e8ff341e1948b3b6313259 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Thu, 2 Sep 2021 10:30:51 +0200
4 Subject: [PATCH] net: dsa: b53: Set correct number of ports in the DSA struct
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Setting DSA_MAX_PORTS caused DSA to call b53 callbacks (e.g.
10 b53_disable_port() during dsa_register_switch()) for invalid
11 (non-existent) ports. That made b53 modify unrelated registers and is
12 one of reasons for a broken BCM5301x support.
13
14 This problem exists for years but DSA_MAX_PORTS usage has changed few
15 times. It seems the most accurate to reference commit dropping
16 dsa_switch_alloc() in the Fixes tag.
17
18 Fixes: 7e99e3470172 ("net: dsa: remove dsa_switch_alloc helper")
19 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
20 Signed-off-by: David S. Miller <davem@davemloft.net>
21 ---
22 drivers/net/dsa/b53/b53_common.c | 3 ++-
23 1 file changed, 2 insertions(+), 1 deletion(-)
24
25 --- a/drivers/net/dsa/b53/b53_common.c
26 +++ b/drivers/net/dsa/b53/b53_common.c
27 @@ -2559,6 +2559,8 @@ static int b53_switch_init(struct b53_de
28 dev->enabled_ports |= BIT(dev->cpu_port);
29 dev->num_ports = fls(dev->enabled_ports);
30
31 + dev->ds->num_ports = min_t(unsigned int, dev->num_ports, DSA_MAX_PORTS);
32 +
33 /* Include non standard CPU port built-in PHYs to be probed */
34 if (is539x(dev) || is531x5(dev)) {
35 for (i = 0; i < dev->num_ports; i++) {
36 @@ -2603,7 +2605,6 @@ struct b53_device *b53_switch_alloc(stru
37 return NULL;
38
39 ds->dev = base;
40 - ds->num_ports = DSA_MAX_PORTS;
41
42 dev = devm_kzalloc(base, sizeof(*dev), GFP_KERNEL);
43 if (!dev)