Commit 606c2175 authored by Andrey Shvetsov's avatar Andrey Shvetsov Committed by Greg Kroah-Hartman

staging: most: net: make net device lifetime obvious

The function aim_probe_channel calls only one of the functions
alloc_netdev and register_netdev per run.

Correspondingly, the function aim_disconnect_channel calls only one of
the functions unregister_netdev and free_netdev per run.

This patch makes it obvious by using the 'else' part of the 'if'
statement.
Signed-off-by: default avatarAndrey Shvetsov <andrey.shvetsov@k2l.de>
Signed-off-by: default avatarChristian Gromm <christian.gromm@microchip.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 3c1746ed
...@@ -287,6 +287,7 @@ static int aim_probe_channel(struct most_interface *iface, int channel_idx, ...@@ -287,6 +287,7 @@ static int aim_probe_channel(struct most_interface *iface, int channel_idx,
{ {
struct net_dev_context *nd; struct net_dev_context *nd;
struct net_dev_channel *ch; struct net_dev_channel *ch;
struct net_device *dev;
unsigned long flags; unsigned long flags;
if (!iface) if (!iface)
...@@ -298,8 +299,6 @@ static int aim_probe_channel(struct most_interface *iface, int channel_idx, ...@@ -298,8 +299,6 @@ static int aim_probe_channel(struct most_interface *iface, int channel_idx,
nd = get_net_dev_context(iface); nd = get_net_dev_context(iface);
if (!nd) { if (!nd) {
struct net_device *dev;
dev = alloc_netdev(sizeof(struct net_dev_context), "meth%d", dev = alloc_netdev(sizeof(struct net_dev_context), "meth%d",
NET_NAME_UNKNOWN, most_nd_setup); NET_NAME_UNKNOWN, most_nd_setup);
if (!dev) if (!dev)
...@@ -312,20 +311,24 @@ static int aim_probe_channel(struct most_interface *iface, int channel_idx, ...@@ -312,20 +311,24 @@ static int aim_probe_channel(struct most_interface *iface, int channel_idx,
spin_lock_irqsave(&list_lock, flags); spin_lock_irqsave(&list_lock, flags);
list_add(&nd->list, &net_devices); list_add(&nd->list, &net_devices);
spin_unlock_irqrestore(&list_lock, flags); spin_unlock_irqrestore(&list_lock, flags);
}
ch = ccfg->direction == MOST_CH_TX ? &nd->tx : &nd->rx; ch = ccfg->direction == MOST_CH_TX ? &nd->tx : &nd->rx;
if (ch->linked) { ch->ch_id = channel_idx;
pr_err("only one channel per instance & direction allowed\n"); ch->linked = true;
return -EINVAL; } else {
} ch = ccfg->direction == MOST_CH_TX ? &nd->tx : &nd->rx;
if (ch->linked) {
pr_err("direction is allocated\n");
return -EINVAL;
}
ch->ch_id = channel_idx; ch->ch_id = channel_idx;
ch->linked = true; ch->linked = true;
if (nd->tx.linked && nd->rx.linked && register_netdev(nd->dev)) { if (register_netdev(nd->dev)) {
pr_err("register_netdev() failed\n"); pr_err("register_netdev() failed\n");
ch->linked = false; ch->linked = false;
return -EINVAL; return -EINVAL;
}
} }
return 0; return 0;
...@@ -349,18 +352,18 @@ static int aim_disconnect_channel(struct most_interface *iface, ...@@ -349,18 +352,18 @@ static int aim_disconnect_channel(struct most_interface *iface,
else else
return -EINVAL; return -EINVAL;
/* if (nd->rx.linked && nd->tx.linked) {
* do not call most_stop_channel() here, because channels are /*
* going to be closed in ndo_stop() after unregister_netdev() * do not call most_stop_channel() here, because channels are
*/ * going to be closed in ndo_stop() after unregister_netdev()
if (nd->rx.linked && nd->tx.linked) */
unregister_netdev(nd->dev); unregister_netdev(nd->dev);
ch->linked = false;
ch->linked = false; } else {
if (!nd->rx.linked && !nd->tx.linked) {
spin_lock_irqsave(&list_lock, flags); spin_lock_irqsave(&list_lock, flags);
list_del(&nd->list); list_del(&nd->list);
spin_unlock_irqrestore(&list_lock, flags); spin_unlock_irqrestore(&list_lock, flags);
free_netdev(nd->dev); free_netdev(nd->dev);
} }
......
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