@@ -67,6 +67,8 @@ static int debug = -1;
67
67
module_param (debug , int , 0444 );
68
68
MODULE_PARM_DESC (debug , "Debug level (0=none,...,16=all)" );
69
69
70
+ static LIST_HEAD (netvsc_dev_list );
71
+
70
72
static void netvsc_change_rx_flags (struct net_device * net , int change )
71
73
{
72
74
struct net_device_context * ndev_ctx = netdev_priv (net );
@@ -1781,13 +1783,10 @@ static void netvsc_link_change(struct work_struct *w)
1781
1783
1782
1784
static struct net_device * get_netvsc_bymac (const u8 * mac )
1783
1785
{
1784
- struct net_device * dev ;
1785
-
1786
- ASSERT_RTNL ();
1786
+ struct net_device_context * ndev_ctx ;
1787
1787
1788
- for_each_netdev (& init_net , dev ) {
1789
- if (dev -> netdev_ops != & device_ops )
1790
- continue ; /* not a netvsc device */
1788
+ list_for_each_entry (ndev_ctx , & netvsc_dev_list , list ) {
1789
+ struct net_device * dev = hv_get_drvdata (ndev_ctx -> device_ctx );
1791
1790
1792
1791
if (ether_addr_equal (mac , dev -> perm_addr ))
1793
1792
return dev ;
@@ -1798,25 +1797,18 @@ static struct net_device *get_netvsc_bymac(const u8 *mac)
1798
1797
1799
1798
static struct net_device * get_netvsc_byref (struct net_device * vf_netdev )
1800
1799
{
1800
+ struct net_device_context * net_device_ctx ;
1801
1801
struct net_device * dev ;
1802
1802
1803
- ASSERT_RTNL ();
1804
-
1805
- for_each_netdev (& init_net , dev ) {
1806
- struct net_device_context * net_device_ctx ;
1803
+ dev = netdev_master_upper_dev_get (vf_netdev );
1804
+ if (!dev || dev -> netdev_ops != & device_ops )
1805
+ return NULL ; /* not a netvsc device */
1807
1806
1808
- if (dev -> netdev_ops != & device_ops )
1809
- continue ; /* not a netvsc device */
1807
+ net_device_ctx = netdev_priv (dev );
1808
+ if (!rtnl_dereference (net_device_ctx -> nvdev ))
1809
+ return NULL ; /* device is removed */
1810
1810
1811
- net_device_ctx = netdev_priv (dev );
1812
- if (!rtnl_dereference (net_device_ctx -> nvdev ))
1813
- continue ; /* device is removed */
1814
-
1815
- if (rtnl_dereference (net_device_ctx -> vf_netdev ) == vf_netdev )
1816
- return dev ; /* a match */
1817
- }
1818
-
1819
- return NULL ;
1811
+ return dev ;
1820
1812
}
1821
1813
1822
1814
/* Called when VF is injecting data into network stack.
@@ -2093,15 +2085,19 @@ static int netvsc_probe(struct hv_device *dev,
2093
2085
else
2094
2086
net -> max_mtu = ETH_DATA_LEN ;
2095
2087
2096
- ret = register_netdev (net );
2088
+ rtnl_lock ();
2089
+ ret = register_netdevice (net );
2097
2090
if (ret != 0 ) {
2098
2091
pr_err ("Unable to register netdev.\n" );
2099
2092
goto register_failed ;
2100
2093
}
2101
2094
2102
- return ret ;
2095
+ list_add (& net_device_ctx -> list , & netvsc_dev_list );
2096
+ rtnl_unlock ();
2097
+ return 0 ;
2103
2098
2104
2099
register_failed :
2100
+ rtnl_unlock ();
2105
2101
rndis_filter_device_remove (dev , nvdev );
2106
2102
rndis_failed :
2107
2103
free_percpu (net_device_ctx -> vf_stats );
@@ -2147,6 +2143,7 @@ static int netvsc_remove(struct hv_device *dev)
2147
2143
rndis_filter_device_remove (dev , nvdev );
2148
2144
2149
2145
unregister_netdevice (net );
2146
+ list_del (& ndev_ctx -> list );
2150
2147
2151
2148
rtnl_unlock ();
2152
2149
rcu_read_unlock ();
0 commit comments