187cbacde0d222effdb0550997710bc67f247937
[oweals/openwrt.git] / target / linux / ipq806x / patches-5.4 / 701-stmmac-fix-notifier-registration.patch
1 From 474a31e13a4e9749fb3ee55794d69d0f17ee0998 Mon Sep 17 00:00:00 2001
2 From: Aaro Koskinen <aaro.koskinen@nokia.com>
3 Date: Wed, 26 Feb 2020 18:49:01 +0200
4 Subject: net: stmmac: fix notifier registration
5
6 We cannot register the same netdev notifier multiple times when probing
7 stmmac devices. Register the notifier only once in module init, and also
8 make debugfs creation/deletion safe against simultaneous notifier call.
9
10 Fixes: 481a7d154cbb ("stmmac: debugfs entry name is not be changed when udev rename device name.")
11 Signed-off-by: Aaro Koskinen <aaro.koskinen@nokia.com>
12 Signed-off-by: David S. Miller <davem@davemloft.net>
13 ---
14  drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 13 ++++++++-----
15  1 file changed, 8 insertions(+), 5 deletions(-)
16
17 (limited to 'drivers/net/ethernet/stmicro/stmmac')
18
19 diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
20 index 5836b21edd7e..7da18c9afa01 100644
21 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
22 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
23 @@ -4405,6 +4405,8 @@ static void stmmac_init_fs(struct net_device *dev)
24  {
25         struct stmmac_priv *priv = netdev_priv(dev);
26  
27 +       rtnl_lock();
28 +
29         /* Create per netdev entries */
30         priv->dbgfs_dir = debugfs_create_dir(dev->name, stmmac_fs_dir);
31  
32 @@ -4416,14 +4418,13 @@ static void stmmac_init_fs(struct net_device *dev)
33         debugfs_create_file("dma_cap", 0444, priv->dbgfs_dir, dev,
34                             &stmmac_dma_cap_fops);
35  
36 -       register_netdevice_notifier(&stmmac_notifier);
37 +       rtnl_unlock();
38  }
39  
40  static void stmmac_exit_fs(struct net_device *dev)
41  {
42         struct stmmac_priv *priv = netdev_priv(dev);
43  
44 -       unregister_netdevice_notifier(&stmmac_notifier);
45         debugfs_remove_recursive(priv->dbgfs_dir);
46  }
47  #endif /* CONFIG_DEBUG_FS */
48 @@ -4940,14 +4941,14 @@ int stmmac_dvr_remove(struct device *dev)
49  
50         netdev_info(priv->dev, "%s: removing driver", __func__);
51  
52 -#ifdef CONFIG_DEBUG_FS
53 -       stmmac_exit_fs(ndev);
54 -#endif
55         stmmac_stop_all_dma(priv);
56  
57         stmmac_mac_set(priv, priv->ioaddr, false);
58         netif_carrier_off(ndev);
59         unregister_netdev(ndev);
60 +#ifdef CONFIG_DEBUG_FS
61 +       stmmac_exit_fs(ndev);
62 +#endif
63         phylink_destroy(priv->phylink);
64         if (priv->plat->stmmac_rst)
65                 reset_control_assert(priv->plat->stmmac_rst);
66 @@ -5166,6 +5167,7 @@ static int __init stmmac_init(void)
67         /* Create debugfs main directory if it doesn't exist yet */
68         if (!stmmac_fs_dir)
69                 stmmac_fs_dir = debugfs_create_dir(STMMAC_RESOURCE_NAME, NULL);
70 +       register_netdevice_notifier(&stmmac_notifier);
71  #endif
72  
73         return 0;
74 @@ -5174,6 +5176,7 @@ static int __init stmmac_init(void)
75  static void __exit stmmac_exit(void)
76  {
77  #ifdef CONFIG_DEBUG_FS
78 +       unregister_netdevice_notifier(&stmmac_notifier);
79         debugfs_remove_recursive(stmmac_fs_dir);
80  #endif
81  }
82 -- 
83 cgit 1.2-0.3.lf.el7
84