diff options
author | Florian Fainelli <f.fainelli@gmail.com> | 2015-03-09 17:31:21 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-03-09 23:50:21 -0400 |
commit | 769a020289bc8f68b7e48faf8fee970346d71a3b (patch) | |
tree | 3e57589f3c8b06b02e895e2428a82433f5cb8bda | |
parent | aa836df958886e57ff0d43fb3d79d1af4aec0cc8 (diff) |
net: dsa: utilize of_find_net_device_by_node
Using of_find_device_by_node() restricts the search to platform_device that
match the specified device_node pointer. This is not even remotely true for
network devices backed by a pci_device for instance.
of_find_net_device_by_node() allows us to do a more thorough lookup to find the
struct net_device corresponding to a particular device_node pointer.
For symetry with the non-OF code path, we hold the net_device pointer in
dsa_probe() just like what dev_to_net_dev() does when we call this
function.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/net/dsa.h | 1 | ||||
-rw-r--r-- | net/dsa/dsa.c | 16 |
2 files changed, 12 insertions, 5 deletions
diff --git a/include/net/dsa.h b/include/net/dsa.h index b525ac516559..47917e5e1e12 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h | |||
@@ -72,6 +72,7 @@ struct dsa_platform_data { | |||
72 | * to the root switch chip of the tree. | 72 | * to the root switch chip of the tree. |
73 | */ | 73 | */ |
74 | struct device *netdev; | 74 | struct device *netdev; |
75 | struct net_device *of_netdev; | ||
75 | 76 | ||
76 | /* | 77 | /* |
77 | * Info structs describing each of the switch chips | 78 | * Info structs describing each of the switch chips |
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index b40f11bb419c..899772108ee3 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/of.h> | 20 | #include <linux/of.h> |
21 | #include <linux/of_mdio.h> | 21 | #include <linux/of_mdio.h> |
22 | #include <linux/of_platform.h> | 22 | #include <linux/of_platform.h> |
23 | #include <linux/of_net.h> | ||
23 | #include <linux/sysfs.h> | 24 | #include <linux/sysfs.h> |
24 | #include "dsa_priv.h" | 25 | #include "dsa_priv.h" |
25 | 26 | ||
@@ -583,7 +584,7 @@ static int dsa_of_probe(struct device *dev) | |||
583 | struct device_node *np = dev->of_node; | 584 | struct device_node *np = dev->of_node; |
584 | struct device_node *child, *mdio, *ethernet, *port, *link; | 585 | struct device_node *child, *mdio, *ethernet, *port, *link; |
585 | struct mii_bus *mdio_bus; | 586 | struct mii_bus *mdio_bus; |
586 | struct platform_device *ethernet_dev; | 587 | struct net_device *ethernet_dev; |
587 | struct dsa_platform_data *pd; | 588 | struct dsa_platform_data *pd; |
588 | struct dsa_chip_data *cd; | 589 | struct dsa_chip_data *cd; |
589 | const char *port_name; | 590 | const char *port_name; |
@@ -604,7 +605,7 @@ static int dsa_of_probe(struct device *dev) | |||
604 | if (!ethernet) | 605 | if (!ethernet) |
605 | return -EINVAL; | 606 | return -EINVAL; |
606 | 607 | ||
607 | ethernet_dev = of_find_device_by_node(ethernet); | 608 | ethernet_dev = of_find_net_device_by_node(ethernet); |
608 | if (!ethernet_dev) | 609 | if (!ethernet_dev) |
609 | return -EPROBE_DEFER; | 610 | return -EPROBE_DEFER; |
610 | 611 | ||
@@ -613,7 +614,7 @@ static int dsa_of_probe(struct device *dev) | |||
613 | return -ENOMEM; | 614 | return -ENOMEM; |
614 | 615 | ||
615 | dev->platform_data = pd; | 616 | dev->platform_data = pd; |
616 | pd->netdev = ðernet_dev->dev; | 617 | pd->of_netdev = ethernet_dev; |
617 | pd->nr_chips = of_get_available_child_count(np); | 618 | pd->nr_chips = of_get_available_child_count(np); |
618 | if (pd->nr_chips > DSA_MAX_SWITCHES) | 619 | if (pd->nr_chips > DSA_MAX_SWITCHES) |
619 | pd->nr_chips = DSA_MAX_SWITCHES; | 620 | pd->nr_chips = DSA_MAX_SWITCHES; |
@@ -771,10 +772,15 @@ static int dsa_probe(struct platform_device *pdev) | |||
771 | pd = pdev->dev.platform_data; | 772 | pd = pdev->dev.platform_data; |
772 | } | 773 | } |
773 | 774 | ||
774 | if (pd == NULL || pd->netdev == NULL) | 775 | if (pd == NULL || (pd->netdev == NULL && pd->of_netdev == NULL)) |
775 | return -EINVAL; | 776 | return -EINVAL; |
776 | 777 | ||
777 | dev = dev_to_net_device(pd->netdev); | 778 | if (pd->of_netdev) { |
779 | dev = pd->of_netdev; | ||
780 | dev_hold(dev); | ||
781 | } else { | ||
782 | dev = dev_to_net_device(pd->netdev); | ||
783 | } | ||
778 | if (dev == NULL) { | 784 | if (dev == NULL) { |
779 | ret = -EPROBE_DEFER; | 785 | ret = -EPROBE_DEFER; |
780 | goto out; | 786 | goto out; |