From: Patrick McHardy <kaber@trash.net>
To: netdev@vger.kernel.org
Cc: Patrick McHardy <kaber@trash.net>
Subject: [RFC VLAN 02/08]: Remove unregister_vlan_dev wrapper
Date: Tue, 5 Jun 2007 16:23:32 +0200 (MEST) [thread overview]
Message-ID: <20070605142331.20372.55373.sendpatchset@localhost.localdomain> (raw)
In-Reply-To: <20070605142327.20372.18108.sendpatchset@localhost.localdomain>
[VLAN]: Remove unregister_vlan_dev wrapper
Remove the now useless unregister_vlan_dev wrapper by moving the final
unregister_netdev to unregister_vlan_dev itself. Also replace a few
impossible conditions by BUG_ON and don't try to handle them as valid.
Signed-off-by: Patrick McHardy <kaber@trash.net>
---
commit 7286bd4222a1a9722b1d3b80988078b0af973a67
tree e9a21434dc634051d99513432b051b3e18c5e5c7
parent b2981f2b9c99d414e9ea990cda7ca31c5bef2420
author Patrick McHardy <kaber@trash.net> Tue, 29 May 2007 15:48:16 +0200
committer Patrick McHardy <kaber@trash.net> Tue, 29 May 2007 15:48:16 +0200
net/8021q/vlan.c | 140 +++++++++++++++++++-----------------------------------
1 files changed, 48 insertions(+), 92 deletions(-)
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index 0d95388..87de961 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -51,7 +51,7 @@ static char vlan_buggyright[] = "David S. Miller <davem@redhat.com>";
static int vlan_device_event(struct notifier_block *, unsigned long, void *);
static int vlan_ioctl_handler(void __user *);
-static int unregister_vlan_dev(struct net_device *, unsigned short );
+static int unregister_vlan_dev(struct net_device *);
static struct notifier_block vlan_notifier_block = {
.notifier_call = vlan_device_event,
@@ -118,12 +118,8 @@ static void __exit vlan_cleanup_devices(void)
rtnl_lock();
for_each_netdev_safe(dev, nxt) {
- if (dev->priv_flags & IFF_802_1Q_VLAN) {
- unregister_vlan_dev(VLAN_DEV_INFO(dev)->real_dev,
- VLAN_DEV_INFO(dev)->vlan_id);
-
- unregister_netdevice(dev);
- }
+ if (dev->priv_flags & IFF_802_1Q_VLAN)
+ unregister_vlan_dev(dev);
}
rtnl_unlock();
}
@@ -202,94 +198,61 @@ static void vlan_rcu_free(struct rcu_head *rcu)
vlan_group_free(container_of(rcu, struct vlan_group, rcu));
}
-
-/* This returns 0 if everything went fine.
- * It will return 1 if the group was killed as a result.
- * A negative return indicates failure.
- *
- * The RTNL lock must be held.
+/* Destroy a VLAN device. Returns 1 if the device destroyed was the
+ * last one on the underlying device and the group was destroyed,
+ * 0 otherwise.
*/
-static int unregister_vlan_dev(struct net_device *real_dev,
- unsigned short vlan_id)
+static int unregister_vlan_dev(struct net_device *dev)
{
- struct net_device *dev = NULL;
- int real_dev_ifindex = real_dev->ifindex;
+ struct net_device *real_dev = VLAN_DEV_INFO(dev)->real_dev;
+ unsigned short vlan_id = VLAN_DEV_INFO(dev)->vlan_id;
struct vlan_group *grp;
- int i, ret;
+ int i, ret = 0;
#ifdef VLAN_DEBUG
printk(VLAN_DBG "%s: VID: %i\n", __FUNCTION__, vlan_id);
#endif
+ ASSERT_RTNL();
- /* sanity check */
- if (vlan_id >= VLAN_VID_MASK)
- return -EINVAL;
+ grp = __vlan_find_group(real_dev->ifindex);
- ASSERT_RTNL();
- grp = __vlan_find_group(real_dev_ifindex);
-
- ret = 0;
-
- if (grp) {
- dev = vlan_group_get_device(grp, vlan_id);
- if (dev) {
- /* Remove proc entry */
- vlan_proc_rem_dev(dev);
-
- /* Take it out of our own structures, but be sure to
- * interlock with HW accelerating devices or SW vlan
- * input packet processing.
- */
- if (real_dev->features &
- (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER)) {
- real_dev->vlan_rx_kill_vid(real_dev, vlan_id);
- }
-
- vlan_group_set_device(grp, vlan_id, NULL);
- synchronize_net();
-
-
- /* Caller unregisters (and if necessary, puts)
- * VLAN device, but we get rid of the reference to
- * real_dev here.
- */
- dev_put(real_dev);
-
- /* If the group is now empty, kill off the
- * group.
- */
- for (i = 0; i < VLAN_VID_MASK; i++)
- if (vlan_group_get_device(grp, i))
- break;
-
- if (i == VLAN_VID_MASK) {
- if (real_dev->features & NETIF_F_HW_VLAN_RX)
- real_dev->vlan_rx_register(real_dev, NULL);
-
- hlist_del_rcu(&grp->hlist);
-
- /* Free the group, after all cpu's are done. */
- call_rcu(&grp->rcu, vlan_rcu_free);
-
- grp = NULL;
- ret = 1;
- }
- }
- }
+ BUG_ON(!grp);
+ BUG_ON(vlan_id >= VLAN_VID_MASK);
+ BUG_ON(vlan_group_get_device(grp, vlan_id) != dev);
- return ret;
-}
+ /* Remove proc entry */
+ vlan_proc_rem_dev(dev);
-static int unregister_vlan_device(struct net_device *dev)
-{
- int ret;
+ /* Take it out of our own structures, but be sure to interlock with
+ * HW accelerating devices or SW vlan input packet processing.
+ */
+ if (real_dev->features &
+ (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER))
+ real_dev->vlan_rx_kill_vid(real_dev, vlan_id);
- ret = unregister_vlan_dev(VLAN_DEV_INFO(dev)->real_dev,
- VLAN_DEV_INFO(dev)->vlan_id);
- unregister_netdevice(dev);
+ vlan_group_set_device(grp, vlan_id, NULL);
+ synchronize_net();
+
+ /* Get rid of the reference to real_dev in struct vlan_dev_info */
+ dev_put(real_dev);
+
+ /* If the group is now empty, kill off the group. */
+ for (i = 0; i < VLAN_VID_MASK; i++)
+ if (vlan_group_get_device(grp, i))
+ break;
+
+ if (i == VLAN_VID_MASK) {
+ if (real_dev->features & NETIF_F_HW_VLAN_RX)
+ real_dev->vlan_rx_register(real_dev, NULL);
- if (ret == 1)
- ret = 0;
+ hlist_del_rcu(&grp->hlist);
+
+ /* Free the group, after all cpu's are done. */
+ call_rcu(&grp->rcu, vlan_rcu_free);
+ ret = 1;
+
+ }
+ unregister_netdevice(dev);
return ret;
}
@@ -623,19 +586,12 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
case NETDEV_UNREGISTER:
/* Delete all VLANs for this dev. */
for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
- int ret;
-
vlandev = vlan_group_get_device(grp, i);
if (!vlandev)
continue;
- ret = unregister_vlan_dev(dev,
- VLAN_DEV_INFO(vlandev)->vlan_id);
-
- unregister_netdevice(vlandev);
-
- /* Group was destroyed? */
- if (ret == 1)
+ if (unregister_vlan_dev(vlandev))
+ /* Group was destroyed? */
break;
}
break;
@@ -749,7 +705,7 @@ static int vlan_ioctl_handler(void __user *arg)
err = -EPERM;
if (!capable(CAP_NET_ADMIN))
break;
- err = unregister_vlan_device(dev);
+ err = unregister_vlan_dev(dev);
break;
case GET_VLAN_INGRESS_PRIORITY_CMD:
next prev parent reply other threads:[~2007-06-05 14:23 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-05 14:23 [RFC VLAN 00/08]: VLAN netlink support Patrick McHardy
2007-06-05 14:23 ` [RFC VLAN 01/08]: Move device lookup to ioctl handler Patrick McHardy
2007-06-05 14:23 ` Patrick McHardy [this message]
2007-06-05 14:23 ` [RFC VLAN 03/08]: Add device init callback Patrick McHardy
2007-06-05 14:23 ` [RFC VLAN 04/08]: Move vlan_group allocation to seperate function Patrick McHardy
2007-06-05 14:23 ` [RFC VLAN 05/08]: Split up device creation Patrick McHardy
2007-06-05 14:23 ` [RFC VLAN 06/08]: Use 32 bit value for skb->priority mapping Patrick McHardy
2007-06-05 14:23 ` [RFC VLAN 07/08]: Keep track of number of QoS mappings Patrick McHardy
2007-06-05 14:23 ` [RFC VLAN 08/08]: Use rtnl_link API Patrick McHardy
2007-06-05 14:26 ` [RFC IPROUTE]: VLAN support Patrick McHardy
2007-06-05 14:33 ` [RFC VLAN 00/08]: VLAN netlink support Patrick McHardy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070605142331.20372.55373.sendpatchset@localhost.localdomain \
--to=kaber@trash.net \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).