diff mbox

[net] vti: remove duplicated code to fix a memory leak

Message ID 1372482057-12412-1-git-send-email-amwang@redhat.com
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Amerigo Wang June 29, 2013, 5 a.m. UTC
From: Cong Wang <amwang@redhat.com>

vti module allocates dev->tstats twice: in vti_fb_tunnel_init()
and in vti_tunnel_init(), this lead to a memory leak of 
dev->tstats.

Just remove the duplicated operations in vti_fb_tunnel_init().

(candidate for -stable)

Cc: Stephen Hemminger <stephen@networkplumber.org>
Cc: Saurabh Mohan <saurabh.mohan@vyatta.com>
Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Cong Wang <amwang@redhat.com>

---
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Stephen Hemminger June 29, 2013, 5:18 a.m. UTC | #1
On Sat, 29 Jun 2013 13:00:57 +0800
Cong Wang <amwang@redhat.com> wrote:

> From: Cong Wang <amwang@redhat.com>
> 
> vti module allocates dev->tstats twice: in vti_fb_tunnel_init()
> and in vti_tunnel_init(), this lead to a memory leak of 
> dev->tstats.
> 
> Just remove the duplicated operations in vti_fb_tunnel_init().
> 
> (candidate for -stable)
> 
> Cc: Stephen Hemminger <stephen@networkplumber.org>
> Cc: Saurabh Mohan <saurabh.mohan@vyatta.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Signed-off-by: Cong Wang <amwang@redhat.com>
> 
> ---
> diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
> index c118f6b..17cc0ff 100644
> --- a/net/ipv4/ip_vti.c
> +++ b/net/ipv4/ip_vti.c
> @@ -606,17 +606,10 @@ static int __net_init vti_fb_tunnel_init(struct net_device *dev)
>  	struct iphdr *iph = &tunnel->parms.iph;
>  	struct vti_net *ipn = net_generic(dev_net(dev), vti_net_id);
>  
> -	tunnel->dev = dev;
> -	strcpy(tunnel->parms.name, dev->name);
> -
>  	iph->version		= 4;
>  	iph->protocol		= IPPROTO_IPIP;
>  	iph->ihl		= 5;
>  
> -	dev->tstats = alloc_percpu(struct pcpu_tstats);
> -	if (!dev->tstats)
> -		return -ENOMEM;
> -
>  	dev_hold(dev);
>  	rcu_assign_pointer(ipn->tunnels_wc[0], tunnel);
>  	return 0;

The fix looks correct, looks like an oversight when the generic tunnel infratructure
was added.

Acked-by: Stephen Hemminger <stephen@networkplumber.org>
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Amerigo Wang June 29, 2013, 6:20 a.m. UTC | #2
On Fri, 2013-06-28 at 22:18 -0700, Stephen Hemminger wrote:
> 
> The fix looks correct, looks like an oversight when the generic tunnel infratructure
> was added.

Yeah, I am trying to switch vti tunnel using generic tunnel code.

Thanks!

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
index c118f6b..17cc0ff 100644
--- a/net/ipv4/ip_vti.c
+++ b/net/ipv4/ip_vti.c
@@ -606,17 +606,10 @@  static int __net_init vti_fb_tunnel_init(struct net_device *dev)
 	struct iphdr *iph = &tunnel->parms.iph;
 	struct vti_net *ipn = net_generic(dev_net(dev), vti_net_id);
 
-	tunnel->dev = dev;
-	strcpy(tunnel->parms.name, dev->name);
-
 	iph->version		= 4;
 	iph->protocol		= IPPROTO_IPIP;
 	iph->ihl		= 5;
 
-	dev->tstats = alloc_percpu(struct pcpu_tstats);
-	if (!dev->tstats)
-		return -ENOMEM;
-
 	dev_hold(dev);
 	rcu_assign_pointer(ipn->tunnels_wc[0], tunnel);
 	return 0;