net/ipv4/multipath_wrandom.c: check kmalloc() return value.
PATCH 1/1 net/ipv4/multipath_wrandom.c: check kmalloc() return value.
Description: Check the return value of kmalloc() in function wrandom_set_nhinfo(), in file net/ipv4/multipath_wrandom.c.
Signed-off-by Amit Choudhary <[email protected]>
net/ipv4/multipath_wrandom.c +10 -0
@@ -242,6 +242,11 @@ static void wrandom_set_nhinfo(__be32 ne target_route = (struct multipath_route *)kmalloc (size_rt,GFP_ATOMIC ); +if (!target_route) { +spin_unlock_bh (&state[state_idx].lock); +return ; + } + target_route->gw = nh->nh_gw; target_route->oif = nh->nh_oif;memset (&target_route->rcu,0 ,sizeof (struct rcu_head ));
@@ -263,6 +268,11 @@ static void wrandom_set_nhinfo(__be32 ne target_dest = (struct multipath_dest *)kmalloc (size_dst,GFP_ATOMIC ); +if (!target_dest) { +spin_unlock_bh (&state[state_idx].lock); +return ; + } + target_dest->nh_info = nh; target_dest->network = network; target_dest->netmask = netmask;
Quoted 17 lines · Amit Choudhary
net/ipv4/multipath_wrandom.c +5
-0@@ -242,6 +242,11 @@ static void wrandom_set_nhinfo(__be32 ne target_route = (struct multipath_route *)kmalloc (size_rt,GFP_ATOMIC ); +if (!target_route) { +spin_unlock_bh (&state[state_idx].lock); +return ; + } + target_route->gw = nh->nh_gw; target_route->oif = nh->nh_oif;memset (&target_route->rcu,0 ,sizeof (struct rcu_head ));
net/ipv4/multipath_wrandom.c static void wrandom_set_nhinfo(__be32 ne · line 275
Quoted 8 lines
net/ipv4/multipath_wrandom.c +5
-0@@ -263,6 +268,11 @@ static void wrandom_set_nhinfo(__be32 ne target_dest = (struct multipath_dest *)kmalloc (size_dst,GFP_ATOMIC ); +if (!target_dest) { +spin_unlock_bh (&state[state_idx].lock); +return ; + } +
You probably want to use goto here so you don't need to duplicate spin_unlock_bh(). Otherwise looks good. Send this to akpm and cc [email protected].