public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2.6.19-rc2] net/ipv4/multipath_wrandom.c: check kmalloc() return value.
@ 2006-10-23  6:20 Amit Choudhary
  2006-10-23  6:41 ` Pekka Enberg
  0 siblings, 1 reply; 2+ messages in thread
From: Amit Choudhary @ 2006-10-23  6:20 UTC (permalink / raw)
  To: Linux Kernel

Description: Check the return value of kmalloc() in function wrandom_set_nhinfo(), in file net/ipv4/multipath_wrandom.c.

Signed-off-by: Amit Choudhary <amit2030@gmail.com>

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;
+		}
+
 		target_dest->nh_info = nh;
 		target_dest->network = network;
 		target_dest->netmask = netmask;

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

* Re: [PATCH 2.6.19-rc2] net/ipv4/multipath_wrandom.c: check kmalloc() return value.
  2006-10-23  6:20 [PATCH 2.6.19-rc2] net/ipv4/multipath_wrandom.c: check kmalloc() return value Amit Choudhary
@ 2006-10-23  6:41 ` Pekka Enberg
  0 siblings, 0 replies; 2+ messages in thread
From: Pekka Enberg @ 2006-10-23  6:41 UTC (permalink / raw)
  To: Amit Choudhary; +Cc: Linux Kernel

On 10/23/06, Amit Choudhary <amit2030@gmail.com> wrote:
> 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;
> +               }
> +

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
netdev@vger.kernel.org.

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

end of thread, other threads:[~2006-10-23  6:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-23  6:20 [PATCH 2.6.19-rc2] net/ipv4/multipath_wrandom.c: check kmalloc() return value Amit Choudhary
2006-10-23  6:41 ` Pekka Enberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox