WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 4/6] netfront: use free_netdev and other unwinds

To: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH 4/6] netfront: use free_netdev and other unwinds
From: Stephen Hemminger <shemminger@xxxxxxxx>
Date: Wed, 17 May 2006 14:31:25 -0700
Cc: xen-devel@xxxxxxxxxxxxxxxxxxx
Delivery-date: Wed, 17 May 2006 14:33:56 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
In-reply-to: <20060517142648.439befd9@xxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Organization: OSDL
References: <20060517142648.439befd9@xxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User shemminger@xxxxxxxxxxxxxxxxxxxxx
# Node ID 06cea5a9cbae9af028300e470849bc034beaff75
# Parent  44ad0558e50c91ad66a155c017d6df0cb36e007d
Network devices need to be freed by free_netdev not kfree.
Also, fix some missing unwinds in error path.
Still not convinced there aren't some lurking double free's in the error
paths here.

Signed-off-by: Stephen Hemminger <shemminger@xxxxxxxx>

diff -r 44ad0558e50c -r 06cea5a9cbae 
linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c
--- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c      Wed May 17 
20:44:25 2006
+++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c      Wed May 17 
20:48:41 2006
@@ -229,7 +229,8 @@
 
        err = talk_to_backend(dev, info);
        if (err) {
-               kfree(info);
+               unregister_netdev(netdev);
+               free_netdev(netdev);
                dev->data = NULL;
                return err;
        }
@@ -1119,11 +1120,11 @@
        struct net_device *netdev = NULL;
        struct netfront_info *np = NULL;
 
-       if ((netdev = alloc_etherdev(sizeof(struct netfront_info))) == NULL) {
+       netdev = alloc_etherdev(sizeof(struct netfront_info));
+       if (!netdev) {
                printk(KERN_WARNING "%s> alloc_etherdev failed.\n",
                       __FUNCTION__);
-               err = -ENOMEM;
-               goto exit;
+               return -ENOMEM;
        }
 
        np                = netdev_priv(netdev);
@@ -1168,7 +1169,7 @@
                printk(KERN_ALERT "#### netfront can't alloc rx grant refs\n");
                gnttab_free_grant_references(np->gref_tx_head);
                err = -ENOMEM;
-               goto exit;
+               goto exit_free_tx;
        }
 
        netdev->open            = network_open;
@@ -1197,18 +1198,19 @@
        }
 
        np->netdev = netdev;
-
+       if (val)
+               *val = netdev;
+
+       return 0;
+
+
+ exit_free_grefs:
+       gnttab_free_grant_references(np->gref_rx_head);
+ exit_free_tx:
+       gnttab_free_grant_references(np->gref_tx_head);
  exit:
-       if (err != 0)
-               kfree(netdev);
-       else if (val != NULL)
-               *val = netdev;
+       free_netdev(netdev);
        return err;
-
- exit_free_grefs:
-       gnttab_free_grant_references(np->gref_tx_head);
-       gnttab_free_grant_references(np->gref_rx_head);
-       goto exit;
 }
 
 /*

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel