1775bfb32ce2b473e41b6701bd8f4f2eb2969de0
[openwrt/staging/yousong.git] /
1 From 0452800f6db4ed0a42ffb15867c0acfd68829f6a Mon Sep 17 00:00:00 2001
2 From: Chuanhong Guo <gch981213@gmail.com>
3 Date: Fri, 3 Apr 2020 19:28:24 +0800
4 Subject: net: dsa: mt7530: fix null pointer dereferencing in port5 setup
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 The 2nd gmac of mediatek soc ethernet may not be connected to a PHY
10 and a phy-handle isn't always available.
11 Unfortunately, mt7530 dsa driver assumes that the 2nd gmac is always
12 connected to switch port 5 and setup mt7530 according to phy address
13 of 2nd gmac node, causing null pointer dereferencing when phy-handle
14 isn't defined in dts.
15 This commit fix this setup code by checking return value of
16 of_parse_phandle before using it.
17
18 Fixes: 38f790a80560 ("net: dsa: mt7530: Add support for port 5")
19 Signed-off-by: Chuanhong Guo <gch981213@gmail.com>
20 Reviewed-by: Vivien Didelot <vivien.didelot@gmail.com>
21 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
22 Tested-by: René van Dorst <opensource@vdorst.com>
23 Signed-off-by: David S. Miller <davem@davemloft.net>
24 ---
25 drivers/net/dsa/mt7530.c | 3 +++
26 1 file changed, 3 insertions(+)
27
28 --- a/drivers/net/dsa/mt7530.c
29 +++ b/drivers/net/dsa/mt7530.c
30 @@ -1411,6 +1411,9 @@ mt7530_setup(struct dsa_switch *ds)
31 continue;
32
33 phy_node = of_parse_phandle(mac_np, "phy-handle", 0);
34 + if (!phy_node)
35 + continue;
36 +
37 if (phy_node->parent == priv->dev->of_node->parent) {
38 interface = of_get_phy_mode(mac_np);
39 id = of_mdio_parse_addr(ds->dev, phy_node);