Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 14 May 2016 06:07:15 +0000 (UTC)
From:      Kristof Provost <kp@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r299725 - head/sys/dev/virtio/network
Message-ID:  <201605140607.u4E67F1u067100@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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:	novel@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;
 		}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605140607.u4E67F1u067100>