Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 90406
b: refs/heads/master
c: 6772718
h: refs/heads/master
v: v3
  • Loading branch information
Pavel Emelyanov authored and David S. Miller committed Mar 26, 2008
1 parent 33ba7cd commit 9057390
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 789e41e6f496022ac1639aaae38ea1943606a9d0
refs/heads/master: 67727184f28c38d06013c6659560bb046c1d9f9c
2 changes: 1 addition & 1 deletion trunk/include/linux/if_vlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static inline struct net_device *vlan_group_get_device(struct vlan_group *vg,
{
struct net_device **array;
array = vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
return array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN];
return array ? array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] : NULL;
}

static inline void vlan_group_set_device(struct vlan_group *vg,
Expand Down
36 changes: 23 additions & 13 deletions trunk/net/8021q/vlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,29 +106,35 @@ static void vlan_group_free(struct vlan_group *grp)
static struct vlan_group *vlan_group_alloc(int ifindex)
{
struct vlan_group *grp;
unsigned int size;
unsigned int i;

grp = kzalloc(sizeof(struct vlan_group), GFP_KERNEL);
if (!grp)
return NULL;

size = sizeof(struct net_device *) * VLAN_GROUP_ARRAY_PART_LEN;

for (i = 0; i < VLAN_GROUP_ARRAY_SPLIT_PARTS; i++) {
grp->vlan_devices_arrays[i] = kzalloc(size, GFP_KERNEL);
if (!grp->vlan_devices_arrays[i])
goto err;
}

grp->real_dev_ifindex = ifindex;
hlist_add_head_rcu(&grp->hlist,
&vlan_group_hash[vlan_grp_hashfn(ifindex)]);
return grp;
}

err:
vlan_group_free(grp);
return NULL;
static int vlan_group_prealloc_vid(struct vlan_group *vg, int vid)
{
struct net_device **array;
unsigned int size;

ASSERT_RTNL();

array = vg->vlan_devices_arrays[vid / VLAN_GROUP_ARRAY_PART_LEN];
if (array != NULL)
return 0;

size = sizeof(struct net_device *) * VLAN_GROUP_ARRAY_PART_LEN;
array = kzalloc(size, GFP_KERNEL);
if (array == NULL)
return -ENOBUFS;

vg->vlan_devices_arrays[vid / VLAN_GROUP_ARRAY_PART_LEN] = array;
return 0;
}

static void vlan_rcu_free(struct rcu_head *rcu)
Expand Down Expand Up @@ -247,6 +253,10 @@ int register_vlan_dev(struct net_device *dev)
return -ENOBUFS;
}

err = vlan_group_prealloc_vid(grp, vlan_id);
if (err < 0)
goto out_free_group;

err = register_netdevice(dev);
if (err < 0)
goto out_free_group;
Expand Down

0 comments on commit 9057390

Please sign in to comment.