aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYan Markman <ymarkman@marvell.com>2017-09-25 08:59:47 -0400
committerDavid S. Miller <davem@davemloft.net>2017-09-28 12:33:51 -0400
commit6bf69a1d6334bed776875c5ca852594ab4e5b209 (patch)
tree581254768cf0eaf49676b15eda140e38a3cb1600
parentaff3da39211105a42b2108b8af79bf8e16f670fd (diff)
net: mvpp2: fix port list indexing
The private port_list array has a list of pointers to mvpp2_port instances. This list is allocated given the number of ports enabled in the device tree, but the pointers are set using the port-id property. If on a single port is enabled, the port_list array will be of size 1, but when registering the port, if its id is not 0 the driver will crash. Other crashes were encountered in various situations. This fixes the issue by using an index not equal to the value of the port-id property. Fixes: 3f518509dedc ("ethernet: Add new driver for Marvell Armada 375 network unit") Signed-off-by: Antoine Tenart <antoine.tenart@free-electrons.com> Signed-off-by: Yan Markman <ymarkman@marvell.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/ethernet/marvell/mvpp2.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/drivers/net/ethernet/marvell/mvpp2.c b/drivers/net/ethernet/marvell/mvpp2.c
index da04939a2748..b2f99df81e9c 100644
--- a/drivers/net/ethernet/marvell/mvpp2.c
+++ b/drivers/net/ethernet/marvell/mvpp2.c
@@ -7504,7 +7504,7 @@ static void mvpp2_port_copy_mac_addr(struct net_device *dev, struct mvpp2 *priv,
7504/* Ports initialization */ 7504/* Ports initialization */
7505static int mvpp2_port_probe(struct platform_device *pdev, 7505static int mvpp2_port_probe(struct platform_device *pdev,
7506 struct device_node *port_node, 7506 struct device_node *port_node,
7507 struct mvpp2 *priv) 7507 struct mvpp2 *priv, int index)
7508{ 7508{
7509 struct device_node *phy_node; 7509 struct device_node *phy_node;
7510 struct phy *comphy; 7510 struct phy *comphy;
@@ -7678,7 +7678,7 @@ static int mvpp2_port_probe(struct platform_device *pdev,
7678 } 7678 }
7679 netdev_info(dev, "Using %s mac address %pM\n", mac_from, dev->dev_addr); 7679 netdev_info(dev, "Using %s mac address %pM\n", mac_from, dev->dev_addr);
7680 7680
7681 priv->port_list[id] = port; 7681 priv->port_list[index] = port;
7682 return 0; 7682 return 0;
7683 7683
7684err_free_port_pcpu: 7684err_free_port_pcpu:
@@ -8013,10 +8013,12 @@ static int mvpp2_probe(struct platform_device *pdev)
8013 } 8013 }
8014 8014
8015 /* Initialize ports */ 8015 /* Initialize ports */
8016 i = 0;
8016 for_each_available_child_of_node(dn, port_node) { 8017 for_each_available_child_of_node(dn, port_node) {
8017 err = mvpp2_port_probe(pdev, port_node, priv); 8018 err = mvpp2_port_probe(pdev, port_node, priv, i);
8018 if (err < 0) 8019 if (err < 0)
8019 goto err_mg_clk; 8020 goto err_mg_clk;
8021 i++;
8020 } 8022 }
8021 8023
8022 platform_set_drvdata(pdev, priv); 8024 platform_set_drvdata(pdev, priv);