From: Chuanhong Guo <gch981213@gmail.com>
To: netdev@vger.kernel.org
Cc: "Andrew Lunn" <andrew@lunn.ch>,
"Florian Fainelli" <f.fainelli@gmail.com>,
"Sean Wang" <sean.wang@mediatek.com>,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
"David S. Miller" <davem@davemloft.net>,
"René van Dorst" <opensource@vdorst.com>,
"Russell King" <rmk+kernel@armlinux.org.uk>,
linux-mediatek@lists.infradead.org,
"Matthias Brugger" <matthias.bgg@gmail.com>,
"Chuanhong Guo" <gch981213@gmail.com>,
"Vivien Didelot" <vivien.didelot@gmail.com>,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH] net: dsa: mt7530: fix null pointer dereferencing in port5 setup
Date: Fri, 3 Apr 2020 19:28:24 +0800 [thread overview]
Message-ID: <20200403112830.505720-1-gch981213@gmail.com> (raw)
The 2nd gmac of mediatek soc ethernet may not be connected to a PHY
and a phy-handle isn't always available.
Unfortunately, mt7530 dsa driver assumes that the 2nd gmac is always
connected to switch port 5 and setup mt7530 according to phy address
of 2nd gmac node, causing null pointer dereferencing when phy-handle
isn't defined in dts.
This commit fix this setup code by checking return value of
of_parse_phandle before using it.
Fixes: 38f790a80560 ("net: dsa: mt7530: Add support for port 5")
Signed-off-by: Chuanhong Guo <gch981213@gmail.com>
Cc: stable@vger.kernel.org
---
mt7530 is available as a standalone chip and we should not make it
tightly coupled with a specific type of ethernet dt binding in the
first place.
A proper fix is to replace this port detection logic with a dt
property under mt7530 node, but that's too much for linux-stable.
drivers/net/dsa/mt7530.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index 6e91fe2f4b9a..1d53a4ebcd5a 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -1414,6 +1414,9 @@ mt7530_setup(struct dsa_switch *ds)
continue;
phy_node = of_parse_phandle(mac_np, "phy-handle", 0);
+ if (!phy_node)
+ continue;
+
if (phy_node->parent == priv->dev->of_node->parent) {
ret = of_get_phy_mode(mac_np, &interface);
if (ret && ret != -ENODEV)
--
2.25.1
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
next reply other threads:[~2020-04-03 11:30 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-03 11:28 Chuanhong Guo [this message]
2020-04-03 17:03 ` [PATCH] net: dsa: mt7530: fix null pointer dereferencing in port5 setup Vivien Didelot
2020-04-03 17:43 ` Florian Fainelli
2020-04-03 18:09 ` René van Dorst
2020-04-04 3:19 ` Chuanhong Guo
2020-04-04 15:08 ` Andrew Lunn
2020-04-04 15:34 ` Chuanhong Guo
2020-04-03 23:11 ` David Miller
2020-04-04 3:37 ` Chuanhong Guo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200403112830.505720-1-gch981213@gmail.com \
--to=gch981213@gmail.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=opensource@vdorst.com \
--cc=rmk+kernel@armlinux.org.uk \
--cc=sean.wang@mediatek.com \
--cc=stable@vger.kernel.org \
--cc=vivien.didelot@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).