Author: royger
Date: Mon Oct 19 14:47:37 2015
New Revision: 289589
URL: https://svnweb.freebsd.org/changeset/base/289589

Log:
  xen-netfront: fix netfront create_dev error path
  
  The failure path for allocating rx grant refs should not try to free tx
  grant refs because tx grant refs were allocated after that. Also fix the
  error path for xen_net_read_mac.
  
  Submitted by:         Wei Liu <[email protected]>
  Reviewed by:          royger
  Differential Revision:        https://reviews.freebsd.org/D3891
  Sponsored by:         Citrix Systems R&D

Modified:
  head/sys/dev/xen/netfront/netfront.c

Modified: head/sys/dev/xen/netfront/netfront.c
==============================================================================
--- head/sys/dev/xen/netfront/netfront.c        Mon Oct 19 14:37:17 2015        
(r289588)
+++ head/sys/dev/xen/netfront/netfront.c        Mon Oct 19 14:47:37 2015        
(r289589)
@@ -1885,7 +1885,7 @@ create_netdev(device_t dev)
                                          &np->gref_tx_head) != 0) {
                IPRINTK("#### netfront can't alloc tx grant refs\n");
                err = ENOMEM;
-               goto exit;
+               goto error;
        }
        /* A grant for every rx ring slot */
        if (gnttab_alloc_grant_references(RX_MAX_TARGET,
@@ -1893,12 +1893,15 @@ create_netdev(device_t dev)
                WPRINTK("#### netfront can't alloc rx grant refs\n");
                gnttab_free_grant_references(np->gref_tx_head);
                err = ENOMEM;
-               goto exit;
+               goto error;
        }
 
        err = xen_net_read_mac(dev, np->mac);
-       if (err)
-               goto out;
+       if (err) {
+               gnttab_free_grant_references(np->gref_rx_head);
+               gnttab_free_grant_references(np->gref_tx_head);
+               goto error;
+       }
 
        /* Set up ifnet structure */
        ifp = np->xn_ifp = if_alloc(IFT_ETHER);
@@ -1925,9 +1928,8 @@ create_netdev(device_t dev)
 
        return (0);
 
-exit:
-       gnttab_free_grant_references(np->gref_tx_head);
-out:
+error:
+       KASSERT(err != 0, ("Error path with no error code specified"));
        return (err);
 }
 
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to