aboutsummaryrefslogtreecommitdiffstats
path: root/net/caif/caif_dev.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/caif/caif_dev.c')
-rw-r--r--net/caif/caif_dev.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/net/caif/caif_dev.c b/net/caif/caif_dev.c
index 682c0fedf36..842d6e0402f 100644
--- a/net/caif/caif_dev.c
+++ b/net/caif/caif_dev.c
@@ -11,7 +11,6 @@
11 11
12#define pr_fmt(fmt) KBUILD_MODNAME ":%s(): " fmt, __func__ 12#define pr_fmt(fmt) KBUILD_MODNAME ":%s(): " fmt, __func__
13 13
14#include <linux/version.h>
15#include <linux/kernel.h> 14#include <linux/kernel.h>
16#include <linux/if_arp.h> 15#include <linux/if_arp.h>
17#include <linux/net.h> 16#include <linux/net.h>
@@ -53,7 +52,6 @@ struct cfcnfg *get_cfcnfg(struct net *net)
53 struct caif_net *caifn; 52 struct caif_net *caifn;
54 BUG_ON(!net); 53 BUG_ON(!net);
55 caifn = net_generic(net, caif_net_id); 54 caifn = net_generic(net, caif_net_id);
56 BUG_ON(!caifn);
57 return caifn->cfg; 55 return caifn->cfg;
58} 56}
59EXPORT_SYMBOL(get_cfcnfg); 57EXPORT_SYMBOL(get_cfcnfg);
@@ -63,7 +61,6 @@ static struct caif_device_entry_list *caif_device_list(struct net *net)
63 struct caif_net *caifn; 61 struct caif_net *caifn;
64 BUG_ON(!net); 62 BUG_ON(!net);
65 caifn = net_generic(net, caif_net_id); 63 caifn = net_generic(net, caif_net_id);
66 BUG_ON(!caifn);
67 return &caifn->caifdevs; 64 return &caifn->caifdevs;
68} 65}
69 66
@@ -92,12 +89,15 @@ static struct caif_device_entry *caif_device_alloc(struct net_device *dev)
92 struct caif_device_entry *caifd; 89 struct caif_device_entry *caifd;
93 90
94 caifdevs = caif_device_list(dev_net(dev)); 91 caifdevs = caif_device_list(dev_net(dev));
95 BUG_ON(!caifdevs);
96 92
97 caifd = kzalloc(sizeof(*caifd), GFP_ATOMIC); 93 caifd = kzalloc(sizeof(*caifd), GFP_KERNEL);
98 if (!caifd) 94 if (!caifd)
99 return NULL; 95 return NULL;
100 caifd->pcpu_refcnt = alloc_percpu(int); 96 caifd->pcpu_refcnt = alloc_percpu(int);
97 if (!caifd->pcpu_refcnt) {
98 kfree(caifd);
99 return NULL;
100 }
101 caifd->netdev = dev; 101 caifd->netdev = dev;
102 dev_hold(dev); 102 dev_hold(dev);
103 return caifd; 103 return caifd;
@@ -108,7 +108,7 @@ static struct caif_device_entry *caif_get(struct net_device *dev)
108 struct caif_device_entry_list *caifdevs = 108 struct caif_device_entry_list *caifdevs =
109 caif_device_list(dev_net(dev)); 109 caif_device_list(dev_net(dev));
110 struct caif_device_entry *caifd; 110 struct caif_device_entry *caifd;
111 BUG_ON(!caifdevs); 111
112 list_for_each_entry_rcu(caifd, &caifdevs->list, list) { 112 list_for_each_entry_rcu(caifd, &caifdevs->list, list) {
113 if (caifd->netdev == dev) 113 if (caifd->netdev == dev)
114 return caifd; 114 return caifd;
@@ -209,8 +209,7 @@ static int caif_device_notify(struct notifier_block *me, unsigned long what,
209 enum cfcnfg_phy_preference pref; 209 enum cfcnfg_phy_preference pref;
210 enum cfcnfg_phy_type phy_type; 210 enum cfcnfg_phy_type phy_type;
211 struct cfcnfg *cfg; 211 struct cfcnfg *cfg;
212 struct caif_device_entry_list *caifdevs = 212 struct caif_device_entry_list *caifdevs;
213 caif_device_list(dev_net(dev));
214 213
215 if (dev->type != ARPHRD_CAIF) 214 if (dev->type != ARPHRD_CAIF)
216 return 0; 215 return 0;
@@ -219,6 +218,8 @@ static int caif_device_notify(struct notifier_block *me, unsigned long what,
219 if (cfg == NULL) 218 if (cfg == NULL)
220 return 0; 219 return 0;
221 220
221 caifdevs = caif_device_list(dev_net(dev));
222
222 switch (what) { 223 switch (what) {
223 case NETDEV_REGISTER: 224 case NETDEV_REGISTER:
224 caifd = caif_device_alloc(dev); 225 caifd = caif_device_alloc(dev);
@@ -348,7 +349,7 @@ static struct notifier_block caif_device_notifier = {
348static int caif_init_net(struct net *net) 349static int caif_init_net(struct net *net)
349{ 350{
350 struct caif_net *caifn = net_generic(net, caif_net_id); 351 struct caif_net *caifn = net_generic(net, caif_net_id);
351 BUG_ON(!caifn); 352
352 INIT_LIST_HEAD(&caifn->caifdevs.list); 353 INIT_LIST_HEAD(&caifn->caifdevs.list);
353 mutex_init(&caifn->caifdevs.lock); 354 mutex_init(&caifn->caifdevs.lock);
354 355
@@ -413,7 +414,7 @@ static int __init caif_device_init(void)
413{ 414{
414 int result; 415 int result;
415 416
416 result = register_pernet_device(&caif_net_ops); 417 result = register_pernet_subsys(&caif_net_ops);
417 418
418 if (result) 419 if (result)
419 return result; 420 return result;
@@ -426,7 +427,7 @@ static int __init caif_device_init(void)
426 427
427static void __exit caif_device_exit(void) 428static void __exit caif_device_exit(void)
428{ 429{
429 unregister_pernet_device(&caif_net_ops); 430 unregister_pernet_subsys(&caif_net_ops);
430 unregister_netdevice_notifier(&caif_device_notifier); 431 unregister_netdevice_notifier(&caif_device_notifier);
431 dev_remove_pack(&caif_packet_type); 432 dev_remove_pack(&caif_packet_type);
432} 433}