Commit ae50b2747f77944faa79eb914272b54eb30b63b3
Committed by
Anthony Liguori
1 parent
d026fb6d
Don't leak VLANClientState on PCI hot remove
destroy_nic() requires that NICInfo::private by a PCIDevice pointer, but then goes on to require that the same pointer matches VLANClientState::opaque. That is no longer the case for virtio-net since qdev and wasn't previously the case for rtl8139, ne2k_pci or eepro100. Make the situation a lot more clear by maintaining a VLANClientState pointer in NICInfo. Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing
9 changed files
with
25 additions
and
27 deletions
hw/device-hotplug.c
... | ... | @@ -55,12 +55,7 @@ void destroy_nic(dev_match_fn *match_fn, void *arg) |
55 | 55 | nic = &nd_table[i]; |
56 | 56 | if (nic->used) { |
57 | 57 | if (nic->private && match_fn(nic->private, arg)) { |
58 | - if (nic->vlan) { | |
59 | - VLANClientState *vc; | |
60 | - vc = qemu_find_vlan_client(nic->vlan, nic->private); | |
61 | - if (vc) | |
62 | - qemu_del_vlan_client(vc); | |
63 | - } | |
58 | + qemu_del_vlan_client(nic->vc); | |
64 | 59 | net_client_uninit(nic); |
65 | 60 | } |
66 | 61 | } | ... | ... |
hw/dp8393x.c
... | ... | @@ -890,8 +890,9 @@ void dp83932_init(NICInfo *nd, target_phys_addr_t base, int it_shift, |
890 | 890 | s->watchdog = qemu_new_timer(vm_clock, dp8393x_watchdog, s); |
891 | 891 | s->regs[SONIC_SR] = 0x0004; /* only revision recognized by Linux */ |
892 | 892 | |
893 | - s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, nic_can_receive, | |
894 | - nic_receive, NULL, nic_cleanup, s); | |
893 | + s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, | |
894 | + nic_can_receive, nic_receive, NULL, | |
895 | + nic_cleanup, s); | |
895 | 896 | |
896 | 897 | qemu_format_nic_info_str(s->vc, nd->macaddr); |
897 | 898 | qemu_register_reset(nic_reset, s); | ... | ... |
hw/etraxfs_eth.c
... | ... | @@ -590,9 +590,9 @@ void *etraxfs_eth_init(NICInfo *nd, target_phys_addr_t base, int phyaddr) |
590 | 590 | eth->ethregs = cpu_register_io_memory(eth_read, eth_write, eth); |
591 | 591 | cpu_register_physical_memory (base, 0x5c, eth->ethregs); |
592 | 592 | |
593 | - eth->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, | |
594 | - eth_can_receive, eth_receive, NULL, | |
595 | - eth_cleanup, eth); | |
593 | + eth->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, | |
594 | + eth_can_receive, eth_receive, | |
595 | + NULL, eth_cleanup, eth); | |
596 | 596 | eth->vc->opaque = eth; |
597 | 597 | eth->vc->link_status_changed = eth_set_link; |
598 | 598 | ... | ... |
hw/mcf_fec.c
... | ... | @@ -462,9 +462,9 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq) |
462 | 462 | mcf_fec_writefn, s); |
463 | 463 | cpu_register_physical_memory(base, 0x400, s->mmio_index); |
464 | 464 | |
465 | - s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, | |
466 | - mcf_fec_can_receive, mcf_fec_receive, NULL, | |
467 | - mcf_fec_cleanup, s); | |
465 | + s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, | |
466 | + mcf_fec_can_receive, mcf_fec_receive, | |
467 | + NULL, mcf_fec_cleanup, s); | |
468 | 468 | memcpy(s->macaddr, nd->macaddr, 6); |
469 | 469 | qemu_format_nic_info_str(s->vc, s->macaddr); |
470 | 470 | } | ... | ... |
hw/mipsnet.c
... | ... | @@ -263,9 +263,9 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd) |
263 | 263 | s->io_base = base; |
264 | 264 | s->irq = irq; |
265 | 265 | if (nd && nd->vlan) { |
266 | - s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, | |
267 | - mipsnet_can_receive, mipsnet_receive, NULL, | |
268 | - mipsnet_cleanup, s); | |
266 | + s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, | |
267 | + mipsnet_can_receive, mipsnet_receive, | |
268 | + NULL, mipsnet_cleanup, s); | |
269 | 269 | } else { |
270 | 270 | s->vc = NULL; |
271 | 271 | } | ... | ... |
hw/ne2000.c
... | ... | @@ -759,9 +759,9 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd) |
759 | 759 | |
760 | 760 | ne2000_reset(s); |
761 | 761 | |
762 | - s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, | |
763 | - ne2000_can_receive, ne2000_receive, NULL, | |
764 | - isa_ne2000_cleanup, s); | |
762 | + s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, | |
763 | + ne2000_can_receive, ne2000_receive, | |
764 | + NULL, isa_ne2000_cleanup, s); | |
765 | 765 | |
766 | 766 | qemu_format_nic_info_str(s->vc, s->macaddr); |
767 | 767 | ... | ... |
hw/qdev.c
... | ... | @@ -250,8 +250,9 @@ VLANClientState *qdev_get_vlan_client(DeviceState *dev, |
250 | 250 | { |
251 | 251 | NICInfo *nd = dev->nd; |
252 | 252 | assert(nd); |
253 | - return qemu_new_vlan_client(nd->vlan, nd->model, nd->name, can_receive, | |
254 | - receive, receive_iov, cleanup, opaque); | |
253 | + nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, can_receive, | |
254 | + receive, receive_iov, cleanup, opaque); | |
255 | + return nd->vc; | |
255 | 256 | } |
256 | 257 | |
257 | 258 | ... | ... |
hw/usb-net.c
... | ... | @@ -1458,11 +1458,11 @@ USBDevice *usb_net_init(NICInfo *nd) |
1458 | 1458 | |
1459 | 1459 | pstrcpy(s->dev.devname, sizeof(s->dev.devname), |
1460 | 1460 | "QEMU USB Network Interface"); |
1461 | - s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, | |
1462 | - usbnet_can_receive, | |
1463 | - usbnet_receive, | |
1464 | - NULL, | |
1465 | - usbnet_cleanup, s); | |
1461 | + s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, | |
1462 | + usbnet_can_receive, | |
1463 | + usbnet_receive, | |
1464 | + NULL, | |
1465 | + usbnet_cleanup, s); | |
1466 | 1466 | |
1467 | 1467 | qemu_format_nic_info_str(s->vc, s->mac); |
1468 | 1468 | ... | ... |