mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-20 11:11:24 +00:00
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
This commit is contained in:
parent
8a53d16bd7
commit
3fcb1aaef1
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=299725
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user