Author: kp
Date: Sat May 14 06:07:15 2016
New Revision: 299725
URL: https://svnweb.freebsd.org/changeset/base/299725

Log:
  vtnet: fix panic on unload
  
  Since r276367 added the virtio_mmio support vtnet_modevent() gets called 
twice.
  This resulted in a memory leak during load and a panic on unload.
  
  Count the loads so we only initialise once (just like cxgbe(4)), and only 
clean
  up in the final unload.
  
  PR:           209428
  Submitted by: no...@freebsd.org
  MFC after:    1 week

Modified:
  head/sys/dev/virtio/network/if_vtnet.c

Modified: head/sys/dev/virtio/network/if_vtnet.c
==============================================================================
--- head/sys/dev/virtio/network/if_vtnet.c      Sat May 14 06:06:48 2016        
(r299724)
+++ head/sys/dev/virtio/network/if_vtnet.c      Sat May 14 06:07:15 2016        
(r299725)
@@ -311,21 +311,22 @@ MODULE_DEPEND(vtnet, netmap, 1, 1, 1);
 static int
 vtnet_modevent(module_t mod, int type, void *unused)
 {
-       int error;
-
-       error = 0;
+       int error = 0;
+       static int loaded = 0;
 
        switch (type) {
        case MOD_LOAD:
-               vtnet_tx_header_zone = uma_zcreate("vtnet_tx_hdr",
-                   sizeof(struct vtnet_tx_header),
-                   NULL, NULL, NULL, NULL, 0, 0);
+               if (loaded++ == 0)
+                       vtnet_tx_header_zone = uma_zcreate("vtnet_tx_hdr",
+                               sizeof(struct vtnet_tx_header),
+                               NULL, NULL, NULL, NULL, 0, 0);
                break;
        case MOD_QUIESCE:
-       case MOD_UNLOAD:
                if (uma_zone_get_cur(vtnet_tx_header_zone) > 0)
                        error = EBUSY;
-               else if (type == MOD_UNLOAD) {
+               break;
+       case MOD_UNLOAD:
+               if (--loaded == 0) {
                        uma_zdestroy(vtnet_tx_header_zone);
                        vtnet_tx_header_zone = NULL;
                }
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to