svn commit: r299725 - head/sys/dev/virtio/network
Kristof Provost
kp at FreeBSD.org
Sat May 14 06:07:16 UTC 2016
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 at 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;
}
More information about the svn-src-head
mailing list