Commit 9bfc7b99 authored by Alexey Dobriyan's avatar Alexey Dobriyan Committed by David S. Miller

netns: add dummy struct inside "struct net_generic"

This is precursor to fixing "[id - 1]" bloat inside net_generic().

Name "s" is chosen to complement name "u" often used for dummy unions.
Signed-off-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1a9a0592
...@@ -25,8 +25,10 @@ ...@@ -25,8 +25,10 @@
*/ */
struct net_generic { struct net_generic {
struct {
unsigned int len; unsigned int len;
struct rcu_head rcu; struct rcu_head rcu;
} s;
void *ptr[0]; void *ptr[0];
}; };
......
...@@ -50,7 +50,7 @@ static struct net_generic *net_alloc_generic(void) ...@@ -50,7 +50,7 @@ static struct net_generic *net_alloc_generic(void)
ng = kzalloc(generic_size, GFP_KERNEL); ng = kzalloc(generic_size, GFP_KERNEL);
if (ng) if (ng)
ng->len = max_gen_ptrs; ng->s.len = max_gen_ptrs;
return ng; return ng;
} }
...@@ -64,7 +64,7 @@ static int net_assign_generic(struct net *net, unsigned int id, void *data) ...@@ -64,7 +64,7 @@ static int net_assign_generic(struct net *net, unsigned int id, void *data)
old_ng = rcu_dereference_protected(net->gen, old_ng = rcu_dereference_protected(net->gen,
lockdep_is_held(&net_mutex)); lockdep_is_held(&net_mutex));
if (old_ng->len >= id) { if (old_ng->s.len >= id) {
old_ng->ptr[id - 1] = data; old_ng->ptr[id - 1] = data;
return 0; return 0;
} }
...@@ -84,11 +84,11 @@ static int net_assign_generic(struct net *net, unsigned int id, void *data) ...@@ -84,11 +84,11 @@ static int net_assign_generic(struct net *net, unsigned int id, void *data)
* the old copy for kfree after a grace period. * the old copy for kfree after a grace period.
*/ */
memcpy(&ng->ptr, &old_ng->ptr, old_ng->len * sizeof(void*)); memcpy(&ng->ptr, &old_ng->ptr, old_ng->s.len * sizeof(void*));
ng->ptr[id - 1] = data; ng->ptr[id - 1] = data;
rcu_assign_pointer(net->gen, ng); rcu_assign_pointer(net->gen, ng);
kfree_rcu(old_ng, rcu); kfree_rcu(old_ng, s.rcu);
return 0; return 0;
} }
......
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