Skip to content

Commit b15dc38

Browse files
bcopelandjmberg-intel
authored andcommitted
mac80211: mesh: factor out common mesh path allocation code
Remove duplicate code to allocate and initialize a mesh path or mesh proxy path. Signed-off-by: Bob Copeland <[email protected]> Signed-off-by: Johannes Berg <[email protected]>
1 parent 4439548 commit b15dc38

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

net/mac80211/mesh_pathtbl.c

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,31 @@ int mesh_gate_num(struct ieee80211_sub_if_data *sdata)
501501
return sdata->u.mesh.num_gates;
502502
}
503503

504+
static
505+
struct mesh_path *mesh_path_new(struct ieee80211_sub_if_data *sdata,
506+
const u8 *dst, gfp_t gfp_flags)
507+
{
508+
struct mesh_path *new_mpath;
509+
510+
new_mpath = kzalloc(sizeof(struct mesh_path), gfp_flags);
511+
if (!new_mpath)
512+
return NULL;
513+
514+
memcpy(new_mpath->dst, dst, ETH_ALEN);
515+
eth_broadcast_addr(new_mpath->rann_snd_addr);
516+
new_mpath->is_root = false;
517+
new_mpath->sdata = sdata;
518+
new_mpath->flags = 0;
519+
skb_queue_head_init(&new_mpath->frame_queue);
520+
new_mpath->timer.data = (unsigned long) new_mpath;
521+
new_mpath->timer.function = mesh_path_timer;
522+
new_mpath->exp_time = jiffies;
523+
spin_lock_init(&new_mpath->state_lock);
524+
init_timer(&new_mpath->timer);
525+
526+
return new_mpath;
527+
}
528+
504529
/**
505530
* mesh_path_add - allocate and add a new path to the mesh path table
506531
* @dst: destination address of the path (ETH_ALEN length)
@@ -548,27 +573,15 @@ struct mesh_path *mesh_path_add(struct ieee80211_sub_if_data *sdata,
548573
}
549574

550575
err = -ENOMEM;
551-
new_mpath = kzalloc(sizeof(struct mesh_path), GFP_ATOMIC);
576+
new_mpath = mesh_path_new(sdata, dst, GFP_ATOMIC);
552577
if (!new_mpath)
553578
goto err_path_alloc;
554579

555580
new_node = kmalloc(sizeof(struct mpath_node), GFP_ATOMIC);
556581
if (!new_node)
557582
goto err_node_alloc;
558583

559-
memcpy(new_mpath->dst, dst, ETH_ALEN);
560-
eth_broadcast_addr(new_mpath->rann_snd_addr);
561-
new_mpath->is_root = false;
562-
new_mpath->sdata = sdata;
563-
new_mpath->flags = 0;
564-
skb_queue_head_init(&new_mpath->frame_queue);
565584
new_node->mpath = new_mpath;
566-
new_mpath->timer.data = (unsigned long) new_mpath;
567-
new_mpath->timer.function = mesh_path_timer;
568-
new_mpath->exp_time = jiffies;
569-
spin_lock_init(&new_mpath->state_lock);
570-
init_timer(&new_mpath->timer);
571-
572585
hlist_add_head_rcu(&new_node->list, bucket);
573586
if (atomic_inc_return(&tbl->entries) >=
574587
MEAN_CHAIN_LEN * (tbl->hash_mask + 1))
@@ -664,25 +677,17 @@ int mpp_path_add(struct ieee80211_sub_if_data *sdata,
664677
return -ENOTSUPP;
665678

666679
err = -ENOMEM;
667-
new_mpath = kzalloc(sizeof(struct mesh_path), GFP_ATOMIC);
680+
new_mpath = mesh_path_new(sdata, dst, GFP_ATOMIC);
668681
if (!new_mpath)
669682
goto err_path_alloc;
670683

671684
new_node = kmalloc(sizeof(struct mpath_node), GFP_ATOMIC);
672685
if (!new_node)
673686
goto err_node_alloc;
674687

675-
read_lock_bh(&sdata->u.mesh.pathtbl_resize_lock);
676-
memcpy(new_mpath->dst, dst, ETH_ALEN);
677688
memcpy(new_mpath->mpp, mpp, ETH_ALEN);
678-
new_mpath->sdata = sdata;
679-
new_mpath->flags = 0;
680-
skb_queue_head_init(&new_mpath->frame_queue);
681689
new_node->mpath = new_mpath;
682-
init_timer(&new_mpath->timer);
683-
new_mpath->exp_time = jiffies;
684-
spin_lock_init(&new_mpath->state_lock);
685-
690+
read_lock_bh(&sdata->u.mesh.pathtbl_resize_lock);
686691
tbl = resize_dereference_mpp_paths(sdata);
687692

688693
hash_idx = mesh_table_hash(dst, tbl);

0 commit comments

Comments
 (0)