Skip to contentSkip to conversation

net/ipv4/multipath_wrandom.c: check kmalloc() return value.

PATCH In review Amit Choudhary 2 participants 2 messages Oct 23, 2006 Networking

lore
Share & tools
lore
#0 lore raw

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.

net/ipv4/multipath_wrandom.c +10 -0
index 92b0482..45bfd20 100644
@@ -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;
#1 lore raw
Quoted 17 lines · Amit Choudhary
net/ipv4/multipath_wrandom.c +5 -0
index 92b0482..45bfd20 100644
@@ -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].