aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFiro Yang <firogm@gmail.com>2015-06-07 23:54:51 -0400
committerDavid S. Miller <davem@davemloft.net>2015-06-08 02:45:40 -0400
commitf38b24c90528c888915ef6e3bc320bdb30b14cf2 (patch)
treefb9220fc44e94ead33fa8165c5bc2cf1301e8618
parentcbab1510afbb140f7a51d996eafc525ac316c667 (diff)
fib_trie: coding style: Use pointer after check
As Alexander Duyck pointed out that: struct tnode { ... struct key_vector kv[1]; } The kv[1] member of struct tnode is an arry that refernced by a null pointer will not crash the system, like this: struct tnode *p = NULL; struct key_vector *kv = p->kv; As such p->kv doesn't actually dereference anything, it is simply a means for getting the offset to the array from the pointer p. This patch make the code more regular to avoid making people feel odd when they look at the code. Signed-off-by: Firo Yang <firogm@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/ipv4/fib_trie.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 01bce1506cd7..3c699c4e90a4 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -325,13 +325,15 @@ static inline void empty_child_dec(struct key_vector *n)
325 325
326static struct key_vector *leaf_new(t_key key, struct fib_alias *fa) 326static struct key_vector *leaf_new(t_key key, struct fib_alias *fa)
327{ 327{
328 struct tnode *kv = kmem_cache_alloc(trie_leaf_kmem, GFP_KERNEL); 328 struct key_vector *l;
329 struct key_vector *l = kv->kv; 329 struct tnode *kv;
330 330
331 kv = kmem_cache_alloc(trie_leaf_kmem, GFP_KERNEL);
331 if (!kv) 332 if (!kv)
332 return NULL; 333 return NULL;
333 334
334 /* initialize key vector */ 335 /* initialize key vector */
336 l = kv->kv;
335 l->key = key; 337 l->key = key;
336 l->pos = 0; 338 l->pos = 0;
337 l->bits = 0; 339 l->bits = 0;
@@ -346,24 +348,26 @@ static struct key_vector *leaf_new(t_key key, struct fib_alias *fa)
346 348
347static struct key_vector *tnode_new(t_key key, int pos, int bits) 349static struct key_vector *tnode_new(t_key key, int pos, int bits)
348{ 350{
349 struct tnode *tnode = tnode_alloc(bits);
350 unsigned int shift = pos + bits; 351 unsigned int shift = pos + bits;
351 struct key_vector *tn = tnode->kv; 352 struct key_vector *tn;
353 struct tnode *tnode;
352 354
353 /* verify bits and pos their msb bits clear and values are valid */ 355 /* verify bits and pos their msb bits clear and values are valid */
354 BUG_ON(!bits || (shift > KEYLENGTH)); 356 BUG_ON(!bits || (shift > KEYLENGTH));
355 357
356 pr_debug("AT %p s=%zu %zu\n", tnode, TNODE_SIZE(0), 358 tnode = tnode_alloc(bits);
357 sizeof(struct key_vector *) << bits);
358
359 if (!tnode) 359 if (!tnode)
360 return NULL; 360 return NULL;
361 361
362 pr_debug("AT %p s=%zu %zu\n", tnode, TNODE_SIZE(0),
363 sizeof(struct key_vector *) << bits);
364
362 if (bits == KEYLENGTH) 365 if (bits == KEYLENGTH)
363 tnode->full_children = 1; 366 tnode->full_children = 1;
364 else 367 else
365 tnode->empty_children = 1ul << bits; 368 tnode->empty_children = 1ul << bits;
366 369
370 tn = tnode->kv;
367 tn->key = (shift < KEYLENGTH) ? (key >> shift) << shift : 0; 371 tn->key = (shift < KEYLENGTH) ? (key >> shift) << shift : 0;
368 tn->pos = pos; 372 tn->pos = pos;
369 tn->bits = bits; 373 tn->bits = bits;
@@ -2054,11 +2058,12 @@ static struct key_vector *fib_trie_get_next(struct fib_trie_iter *iter)
2054static struct key_vector *fib_trie_get_first(struct fib_trie_iter *iter, 2058static struct key_vector *fib_trie_get_first(struct fib_trie_iter *iter,
2055 struct trie *t) 2059 struct trie *t)
2056{ 2060{
2057 struct key_vector *n, *pn = t->kv; 2061 struct key_vector *n, *pn;
2058 2062
2059 if (!t) 2063 if (!t)
2060 return NULL; 2064 return NULL;
2061 2065
2066 pn = t->kv;
2062 n = rcu_dereference(pn->tnode[0]); 2067 n = rcu_dereference(pn->tnode[0]);
2063 if (!n) 2068 if (!n)
2064 return NULL; 2069 return NULL;