diff --git a/net/ipv4/multipath_wrandom.c b/net/ipv4/multipath_wrandom.c
index 92b0482..45bfd20 100644
--- a/net/ipv4/multipath_wrandom.c
+++ b/net/ipv4/multipath_wrandom.c
@@ -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;
+ }
+