summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVivien Didelot <vivien.didelot@savoirfairelinux.com>2017-02-03 13:20:16 -0500
committerDavid S. Miller <davem@davemloft.net>2017-02-06 16:53:28 -0500
commit88e4f0ca4e4e7760e4aad544789c5408219886d5 (patch)
treee25b7133b1eb9de8523fbda5e0dc0f91422cf0dc
parent321fa4ffd94e333657e54037d2511c862ec92f6f (diff)
net: dsa: move netdevice notifier registration
Move the netdevice notifier block register code in slave.c and provide helpers for dsa.c to register and unregister it. At the same time, check for errors since (un)register_netdevice_notifier may fail. Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/dsa/dsa.c10
-rw-r--r--net/dsa/dsa_priv.h4
-rw-r--r--net/dsa/slave.c22
3 files changed, 26 insertions, 10 deletions
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 619e57a44d1d..beb79ccf0f59 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -903,10 +903,6 @@ static struct packet_type dsa_pack_type __read_mostly = {
903 .func = dsa_switch_rcv, 903 .func = dsa_switch_rcv,
904}; 904};
905 905
906static struct notifier_block dsa_netdevice_nb __read_mostly = {
907 .notifier_call = dsa_slave_netdevice_event,
908};
909
910#ifdef CONFIG_PM_SLEEP 906#ifdef CONFIG_PM_SLEEP
911static int dsa_suspend(struct device *d) 907static int dsa_suspend(struct device *d)
912{ 908{
@@ -964,7 +960,9 @@ static int __init dsa_init_module(void)
964{ 960{
965 int rc; 961 int rc;
966 962
967 register_netdevice_notifier(&dsa_netdevice_nb); 963 rc = dsa_slave_register_notifier();
964 if (rc)
965 return rc;
968 966
969 rc = platform_driver_register(&dsa_driver); 967 rc = platform_driver_register(&dsa_driver);
970 if (rc) 968 if (rc)
@@ -978,7 +976,7 @@ module_init(dsa_init_module);
978 976
979static void __exit dsa_cleanup_module(void) 977static void __exit dsa_cleanup_module(void)
980{ 978{
981 unregister_netdevice_notifier(&dsa_netdevice_nb); 979 dsa_slave_unregister_notifier();
982 dev_remove_pack(&dsa_pack_type); 980 dev_remove_pack(&dsa_pack_type);
983 platform_driver_unregister(&dsa_driver); 981 platform_driver_unregister(&dsa_driver);
984} 982}
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index a5509b765fc0..591a40aea9ca 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -63,8 +63,8 @@ int dsa_slave_create(struct dsa_switch *ds, struct device *parent,
63void dsa_slave_destroy(struct net_device *slave_dev); 63void dsa_slave_destroy(struct net_device *slave_dev);
64int dsa_slave_suspend(struct net_device *slave_dev); 64int dsa_slave_suspend(struct net_device *slave_dev);
65int dsa_slave_resume(struct net_device *slave_dev); 65int dsa_slave_resume(struct net_device *slave_dev);
66int dsa_slave_netdevice_event(struct notifier_block *unused, 66int dsa_slave_register_notifier(void);
67 unsigned long event, void *ptr); 67void dsa_slave_unregister_notifier(void);
68 68
69/* tag_dsa.c */ 69/* tag_dsa.c */
70extern const struct dsa_device_ops dsa_netdev_ops; 70extern const struct dsa_device_ops dsa_netdev_ops;
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 09fc3e9462c1..949644c1dac2 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -1524,8 +1524,8 @@ static int dsa_slave_port_event(struct net_device *dev, unsigned long event,
1524 return NOTIFY_DONE; 1524 return NOTIFY_DONE;
1525} 1525}
1526 1526
1527int dsa_slave_netdevice_event(struct notifier_block *unused, 1527static int dsa_slave_netdevice_event(struct notifier_block *nb,
1528 unsigned long event, void *ptr) 1528 unsigned long event, void *ptr)
1529{ 1529{
1530 struct net_device *dev = netdev_notifier_info_to_dev(ptr); 1530 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
1531 1531
@@ -1534,3 +1534,21 @@ int dsa_slave_netdevice_event(struct notifier_block *unused,
1534 1534
1535 return NOTIFY_DONE; 1535 return NOTIFY_DONE;
1536} 1536}
1537
1538static struct notifier_block dsa_slave_nb __read_mostly = {
1539 .notifier_call = dsa_slave_netdevice_event,
1540};
1541
1542int dsa_slave_register_notifier(void)
1543{
1544 return register_netdevice_notifier(&dsa_slave_nb);
1545}
1546
1547void dsa_slave_unregister_notifier(void)
1548{
1549 int err;
1550
1551 err = unregister_netdevice_notifier(&dsa_slave_nb);
1552 if (err)
1553 pr_err("DSA: failed to unregister slave notifier (%d)\n", err);
1554}