netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fib_trie: Fix potential null pointer dereference
@ 2015-06-06 11:35 Firo Yang
  2015-06-06 12:05 ` Eric Dumazet
  2015-06-06 13:39 ` walter harms
  0 siblings, 2 replies; 12+ messages in thread
From: Firo Yang @ 2015-06-06 11:35 UTC (permalink / raw)
  To: davem; +Cc: kuznet, jmorris, yoshfuji, kaber, netdev, kernel-janitors,
	Firo Yang

A smatch warning.
When kmem_cache_alloc() failed to alloc memory, a null pointer
will be returned. Redeference null pointer will generate
an unnecessary oops. So, use it after check.

Signed-off-by: Firo Yang <firogm@gmail.com>
---
 net/ipv4/fib_trie.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 01bce15..34094c7 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -326,12 +326,13 @@ static inline void empty_child_dec(struct key_vector *n)
 static struct key_vector *leaf_new(t_key key, struct fib_alias *fa)
 {
 	struct tnode *kv = kmem_cache_alloc(trie_leaf_kmem, GFP_KERNEL);
-	struct key_vector *l = kv->kv;
+	struct key_vector *l;
 
 	if (!kv)
 		return NULL;
 
 	/* initialize key vector */
+	l = kv->kv;
 	l->key = key;
 	l->pos = 0;
 	l->bits = 0;
-- 
2.4.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2015-06-07 16:36 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-06 11:35 [PATCH] fib_trie: Fix potential null pointer dereference Firo Yang
2015-06-06 12:05 ` Eric Dumazet
2015-06-07  3:20   ` Alexander Duyck
     [not found]   ` <5573B7A2.4010607@gmail.com>
2015-06-07  4:46     ` Firo Yang
2015-06-07  6:01   ` Firo Yang
2015-06-07  6:36     ` Julia Lawall
2015-06-07 13:19       ` Firo Yang
2015-06-07 13:23         ` Julia Lawall
2015-06-07 13:42           ` Firo Yang
2015-06-07 16:36           ` Alexander Duyck
2015-06-06 13:39 ` walter harms
2015-06-07  4:52   ` Firo Yang

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).