Commit 8a8ee9af authored by Eric W. Biederman's avatar Eric W. Biederman Committed by David S. Miller

net caif: Register properly as a pernet subsystem.

caif is a subsystem and as such it needs to register with
register_pernet_subsys instead of register_pernet_device.

Among other problems using register_pernet_device was resulting in
net_generic being called before the caif_net structure was allocated.
Which has been causing net_generic to fail with either BUG_ON's or by
return NULL pointers.

A more ugly problem that could be caused is packets in flight why the
subsystem is shutting down.

To remove confusion also remove the cruft cause by inappropriately
trying to fix this bug.

With the aid of the previous patch I have tested this patch and
confirmed that using register_pernet_subsys makes the failure go away as
it should.
Signed-off-by: default avatarEric W. Biederman <ebiederm@xmission.com>
Acked-by: default avatarSjur Brændeland <sjur.brandeland@stericsson.com>
Tested-by: default avatarSasha Levin <levinsasha928@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 5ee4433e
...@@ -59,8 +59,6 @@ struct cfcnfg *get_cfcnfg(struct net *net) ...@@ -59,8 +59,6 @@ struct cfcnfg *get_cfcnfg(struct net *net)
{ {
struct caif_net *caifn; struct caif_net *caifn;
caifn = net_generic(net, caif_net_id); caifn = net_generic(net, caif_net_id);
if (!caifn)
return NULL;
return caifn->cfg; return caifn->cfg;
} }
EXPORT_SYMBOL(get_cfcnfg); EXPORT_SYMBOL(get_cfcnfg);
...@@ -69,8 +67,6 @@ static struct caif_device_entry_list *caif_device_list(struct net *net) ...@@ -69,8 +67,6 @@ static struct caif_device_entry_list *caif_device_list(struct net *net)
{ {
struct caif_net *caifn; struct caif_net *caifn;
caifn = net_generic(net, caif_net_id); caifn = net_generic(net, caif_net_id);
if (!caifn)
return NULL;
return &caifn->caifdevs; return &caifn->caifdevs;
} }
...@@ -99,8 +95,6 @@ static struct caif_device_entry *caif_device_alloc(struct net_device *dev) ...@@ -99,8 +95,6 @@ static struct caif_device_entry *caif_device_alloc(struct net_device *dev)
struct caif_device_entry *caifd; struct caif_device_entry *caifd;
caifdevs = caif_device_list(dev_net(dev)); caifdevs = caif_device_list(dev_net(dev));
if (!caifdevs)
return NULL;
caifd = kzalloc(sizeof(*caifd), GFP_KERNEL); caifd = kzalloc(sizeof(*caifd), GFP_KERNEL);
if (!caifd) if (!caifd)
...@@ -120,8 +114,6 @@ static struct caif_device_entry *caif_get(struct net_device *dev) ...@@ -120,8 +114,6 @@ static struct caif_device_entry *caif_get(struct net_device *dev)
struct caif_device_entry_list *caifdevs = struct caif_device_entry_list *caifdevs =
caif_device_list(dev_net(dev)); caif_device_list(dev_net(dev));
struct caif_device_entry *caifd; struct caif_device_entry *caifd;
if (!caifdevs)
return NULL;
list_for_each_entry_rcu(caifd, &caifdevs->list, list) { list_for_each_entry_rcu(caifd, &caifdevs->list, list) {
if (caifd->netdev == dev) if (caifd->netdev == dev)
...@@ -321,8 +313,6 @@ void caif_enroll_dev(struct net_device *dev, struct caif_dev_common *caifdev, ...@@ -321,8 +313,6 @@ void caif_enroll_dev(struct net_device *dev, struct caif_dev_common *caifdev,
struct caif_device_entry_list *caifdevs; struct caif_device_entry_list *caifdevs;
caifdevs = caif_device_list(dev_net(dev)); caifdevs = caif_device_list(dev_net(dev));
if (!cfg || !caifdevs)
return;
caifd = caif_device_alloc(dev); caifd = caif_device_alloc(dev);
if (!caifd) if (!caifd)
return; return;
...@@ -374,8 +364,6 @@ static int caif_device_notify(struct notifier_block *me, unsigned long what, ...@@ -374,8 +364,6 @@ static int caif_device_notify(struct notifier_block *me, unsigned long what,
cfg = get_cfcnfg(dev_net(dev)); cfg = get_cfcnfg(dev_net(dev));
caifdevs = caif_device_list(dev_net(dev)); caifdevs = caif_device_list(dev_net(dev));
if (!cfg || !caifdevs)
return 0;
caifd = caif_get(dev); caifd = caif_get(dev);
if (caifd == NULL && dev->type != ARPHRD_CAIF) if (caifd == NULL && dev->type != ARPHRD_CAIF)
...@@ -507,9 +495,6 @@ static struct notifier_block caif_device_notifier = { ...@@ -507,9 +495,6 @@ static struct notifier_block caif_device_notifier = {
static int caif_init_net(struct net *net) static int caif_init_net(struct net *net)
{ {
struct caif_net *caifn = net_generic(net, caif_net_id); struct caif_net *caifn = net_generic(net, caif_net_id);
if (WARN_ON(!caifn))
return -EINVAL;
INIT_LIST_HEAD(&caifn->caifdevs.list); INIT_LIST_HEAD(&caifn->caifdevs.list);
mutex_init(&caifn->caifdevs.lock); mutex_init(&caifn->caifdevs.lock);
...@@ -527,9 +512,6 @@ static void caif_exit_net(struct net *net) ...@@ -527,9 +512,6 @@ static void caif_exit_net(struct net *net)
caif_device_list(net); caif_device_list(net);
struct cfcnfg *cfg = get_cfcnfg(net); struct cfcnfg *cfg = get_cfcnfg(net);
if (!cfg || !caifdevs)
return;
rtnl_lock(); rtnl_lock();
mutex_lock(&caifdevs->lock); mutex_lock(&caifdevs->lock);
...@@ -569,7 +551,7 @@ static int __init caif_device_init(void) ...@@ -569,7 +551,7 @@ static int __init caif_device_init(void)
{ {
int result; int result;
result = register_pernet_device(&caif_net_ops); result = register_pernet_subsys(&caif_net_ops);
if (result) if (result)
return result; return result;
...@@ -582,7 +564,7 @@ static int __init caif_device_init(void) ...@@ -582,7 +564,7 @@ static int __init caif_device_init(void)
static void __exit caif_device_exit(void) static void __exit caif_device_exit(void)
{ {
unregister_pernet_device(&caif_net_ops); unregister_pernet_subsys(&caif_net_ops);
unregister_netdevice_notifier(&caif_device_notifier); unregister_netdevice_notifier(&caif_device_notifier);
dev_remove_pack(&caif_packet_type); dev_remove_pack(&caif_packet_type);
} }
......
...@@ -309,7 +309,6 @@ int caif_connect_client(struct net *net, struct caif_connect_request *conn_req, ...@@ -309,7 +309,6 @@ int caif_connect_client(struct net *net, struct caif_connect_request *conn_req,
int err; int err;
struct cfctrl_link_param param; struct cfctrl_link_param param;
struct cfcnfg *cfg = get_cfcnfg(net); struct cfcnfg *cfg = get_cfcnfg(net);
caif_assert(cfg != NULL);
rcu_read_lock(); rcu_read_lock();
err = caif_connect_req_to_link_param(cfg, conn_req, &param); err = caif_connect_req_to_link_param(cfg, conn_req, &param);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment