From 57407ea44cc0a3d630b9b89a2be011f1955ce5c1 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 23 Dec 2014 17:53:19 +0100 Subject: net: remove all cleanup methods from NIC NetClientInfos All NICs have a cleanup function that, in most cases, zeroes the pointer to the NICState. In some cases, it frees data belonging to the NIC. However, this function is never called except when exiting from QEMU. It is not necessary to NULL pointers and free data here; the right place to do that would be in the device's unrealize function, after calling qemu_del_nic. Zeroing the NIC multiple times is also wrong for multiqueue devices. This cleanup function gets in the way of making the NetClientStates for the NIC hold an object_ref reference to the object, so get rid of it. Signed-off-by: Paolo Bonzini Signed-off-by: Stefan Hajnoczi --- hw/net/allwinner_emac.c | 8 -------- hw/net/cadence_gem.c | 9 --------- hw/net/dp8393x.c | 11 ----------- hw/net/e1000.c | 9 --------- hw/net/eepro100.c | 8 -------- hw/net/etraxfs_eth.c | 13 ------------- hw/net/fsl_etsec/etsec.c | 6 ------ hw/net/lan9118.c | 8 -------- hw/net/lance.c | 8 -------- hw/net/mcf_fec.c | 8 -------- hw/net/milkymist-minimac2.c | 8 -------- hw/net/mipsnet.c | 8 -------- hw/net/ne2000-isa.c | 8 -------- hw/net/ne2000.c | 8 -------- hw/net/opencores_eth.c | 5 ----- hw/net/pcnet-pci.c | 8 -------- hw/net/pcnet.c | 5 ----- hw/net/pcnet.h | 1 - hw/net/rtl8139.c | 8 -------- hw/net/smc91c111.c | 8 -------- hw/net/spapr_llan.c | 8 -------- hw/net/stellaris_enet.c | 8 -------- hw/net/virtio-net.c | 8 -------- hw/net/vmxnet3.c | 7 ------- hw/net/xgmac.c | 8 -------- hw/net/xilinx_axienet.c | 9 --------- hw/net/xilinx_ethlite.c | 8 -------- 27 files changed, 211 deletions(-) diff --git a/hw/net/allwinner_emac.c b/hw/net/allwinner_emac.c index d780ba0..0407dee 100644 --- a/hw/net/allwinner_emac.c +++ b/hw/net/allwinner_emac.c @@ -218,13 +218,6 @@ static ssize_t aw_emac_receive(NetClientState *nc, const uint8_t *buf, return size; } -static void aw_emac_cleanup(NetClientState *nc) -{ - AwEmacState *s = qemu_get_nic_opaque(nc); - - s->nic = NULL; -} - static void aw_emac_reset(DeviceState *dev) { AwEmacState *s = AW_EMAC(dev); @@ -433,7 +426,6 @@ static NetClientInfo net_aw_emac_info = { .size = sizeof(NICState), .can_receive = aw_emac_can_receive, .receive = aw_emac_receive, - .cleanup = aw_emac_cleanup, .link_status_changed = aw_emac_set_link, }; diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c index de26609..55b6293 100644 --- a/hw/net/cadence_gem.c +++ b/hw/net/cadence_gem.c @@ -1209,14 +1209,6 @@ static const MemoryRegionOps gem_ops = { .endianness = DEVICE_LITTLE_ENDIAN, }; -static void gem_cleanup(NetClientState *nc) -{ - GemState *s = qemu_get_nic_opaque(nc); - - DB_PRINT("\n"); - s->nic = NULL; -} - static void gem_set_link(NetClientState *nc) { DB_PRINT("\n"); @@ -1228,7 +1220,6 @@ static NetClientInfo net_gem_info = { .size = sizeof(NICState), .can_receive = gem_can_receive, .receive = gem_receive, - .cleanup = gem_cleanup, .link_status_changed = gem_set_link, }; diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c index 7eab7ad..7ce13d2 100644 --- a/hw/net/dp8393x.c +++ b/hw/net/dp8393x.c @@ -859,22 +859,11 @@ static void nic_reset(void *opaque) dp8393x_update_irq(s); } -static void nic_cleanup(NetClientState *nc) -{ - dp8393xState *s = qemu_get_nic_opaque(nc); - - timer_del(s->watchdog); - timer_free(s->watchdog); - - g_free(s); -} - static NetClientInfo net_dp83932_info = { .type = NET_CLIENT_OPTIONS_KIND_NIC, .size = sizeof(NICState), .can_receive = nic_can_receive, .receive = nic_receive, - .cleanup = nic_cleanup, }; void dp83932_init(NICInfo *nd, hwaddr base, int it_shift, diff --git a/hw/net/e1000.c b/hw/net/e1000.c index 89c5788..a207e21 100644 --- a/hw/net/e1000.c +++ b/hw/net/e1000.c @@ -1503,14 +1503,6 @@ e1000_mmio_setup(E1000State *d) } static void -e1000_cleanup(NetClientState *nc) -{ - E1000State *s = qemu_get_nic_opaque(nc); - - s->nic = NULL; -} - -static void pci_e1000_uninit(PCIDevice *dev) { E1000State *d = E1000(dev); @@ -1528,7 +1520,6 @@ static NetClientInfo net_e1000_info = { .can_receive = e1000_can_receive, .receive = e1000_receive, .receive_iov = e1000_receive_iov, - .cleanup = e1000_cleanup, .link_status_changed = e1000_set_link_status, }; diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c index 4877bfd..7a4f9f8 100644 --- a/hw/net/eepro100.c +++ b/hw/net/eepro100.c @@ -1832,13 +1832,6 @@ static const VMStateDescription vmstate_eepro100 = { } }; -static void nic_cleanup(NetClientState *nc) -{ - EEPRO100State *s = qemu_get_nic_opaque(nc); - - s->nic = NULL; -} - static void pci_nic_uninit(PCIDevice *pci_dev) { EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev); @@ -1853,7 +1846,6 @@ static NetClientInfo net_eepro100_info = { .size = sizeof(NICState), .can_receive = nic_can_receive, .receive = nic_receive, - .cleanup = nic_cleanup, }; static int e100_nic_init(PCIDevice *pci_dev) diff --git a/hw/net/etraxfs_eth.c b/hw/net/etraxfs_eth.c index 6a3c86d..4773dea 100644 --- a/hw/net/etraxfs_eth.c +++ b/hw/net/etraxfs_eth.c @@ -581,24 +581,11 @@ static const MemoryRegionOps eth_ops = { } }; -static void eth_cleanup(NetClientState *nc) -{ - ETRAXFSEthState *eth = qemu_get_nic_opaque(nc); - - /* Disconnect the client. */ - eth->dma_out->client.push = NULL; - eth->dma_out->client.opaque = NULL; - eth->dma_in->client.opaque = NULL; - eth->dma_in->client.pull = NULL; - g_free(eth); -} - static NetClientInfo net_etraxfs_info = { .type = NET_CLIENT_OPTIONS_KIND_NIC, .size = sizeof(NICState), .can_receive = eth_can_receive, .receive = eth_receive, - .cleanup = eth_cleanup, .link_status_changed = eth_set_link, }; diff --git a/hw/net/fsl_etsec/etsec.c b/hw/net/fsl_etsec/etsec.c index d4b4429..2fbbc6c 100644 --- a/hw/net/fsl_etsec/etsec.c +++ b/hw/net/fsl_etsec/etsec.c @@ -338,11 +338,6 @@ static void etsec_reset(DeviceState *d) MII_SR_100X_FD_CAPS | MII_SR_100T4_CAPS; } -static void etsec_cleanup(NetClientState *nc) -{ - /* qemu_log("eTSEC cleanup\n"); */ -} - static int etsec_can_receive(NetClientState *nc) { eTSEC *etsec = qemu_get_nic_opaque(nc); @@ -377,7 +372,6 @@ static NetClientInfo net_etsec_info = { .size = sizeof(NICState), .can_receive = etsec_can_receive, .receive = etsec_receive, - .cleanup = etsec_cleanup, .link_status_changed = etsec_set_link_status, }; diff --git a/hw/net/lan9118.c b/hw/net/lan9118.c index e528290..f169c38 100644 --- a/hw/net/lan9118.c +++ b/hw/net/lan9118.c @@ -1309,19 +1309,11 @@ static const MemoryRegionOps lan9118_16bit_mem_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static void lan9118_cleanup(NetClientState *nc) -{ - lan9118_state *s = qemu_get_nic_opaque(nc); - - s->nic = NULL; -} - static NetClientInfo net_lan9118_info = { .type = NET_CLIENT_OPTIONS_KIND_NIC, .size = sizeof(NICState), .can_receive = lan9118_can_receive, .receive = lan9118_receive, - .cleanup = lan9118_cleanup, .link_status_changed = lan9118_set_link, }; diff --git a/hw/net/lance.c b/hw/net/lance.c index a1c49f1..ff7e789 100644 --- a/hw/net/lance.c +++ b/hw/net/lance.c @@ -91,20 +91,12 @@ static const MemoryRegionOps lance_mem_ops = { }, }; -static void lance_cleanup(NetClientState *nc) -{ - PCNetState *d = qemu_get_nic_opaque(nc); - - pcnet_common_cleanup(d); -} - static NetClientInfo net_lance_info = { .type = NET_CLIENT_OPTIONS_KIND_NIC, .size = sizeof(NICState), .can_receive = pcnet_can_receive, .receive = pcnet_receive, .link_status_changed = pcnet_set_link_status, - .cleanup = lance_cleanup, }; static const VMStateDescription vmstate_lance = { diff --git a/hw/net/mcf_fec.c b/hw/net/mcf_fec.c index 22cd7cf..0255612 100644 --- a/hw/net/mcf_fec.c +++ b/hw/net/mcf_fec.c @@ -439,19 +439,11 @@ static const MemoryRegionOps mcf_fec_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static void mcf_fec_cleanup(NetClientState *nc) -{ - mcf_fec_state *s = qemu_get_nic_opaque(nc); - - g_free(s); -} - static NetClientInfo net_mcf_fec_info = { .type = NET_CLIENT_OPTIONS_KIND_NIC, .size = sizeof(NICState), .can_receive = mcf_fec_can_receive, .receive = mcf_fec_receive, - .cleanup = mcf_fec_cleanup, }; void mcf_fec_init(MemoryRegion *sysmem, NICInfo *nd, diff --git a/hw/net/milkymist-minimac2.c b/hw/net/milkymist-minimac2.c index c632672..f06afaa 100644 --- a/hw/net/milkymist-minimac2.c +++ b/hw/net/milkymist-minimac2.c @@ -425,13 +425,6 @@ static int minimac2_can_rx(NetClientState *nc) return 0; } -static void minimac2_cleanup(NetClientState *nc) -{ - MilkymistMinimac2State *s = qemu_get_nic_opaque(nc); - - s->nic = NULL; -} - static void milkymist_minimac2_reset(DeviceState *d) { MilkymistMinimac2State *s = MILKYMIST_MINIMAC2(d); @@ -454,7 +447,6 @@ static NetClientInfo net_milkymist_minimac2_info = { .size = sizeof(NICState), .can_receive = minimac2_can_rx, .receive = minimac2_rx, - .cleanup = minimac2_cleanup, }; static int milkymist_minimac2_init(SysBusDevice *sbd) diff --git a/hw/net/mipsnet.c b/hw/net/mipsnet.c index b26c369..c813e0c 100644 --- a/hw/net/mipsnet.c +++ b/hw/net/mipsnet.c @@ -211,19 +211,11 @@ static const VMStateDescription vmstate_mipsnet = { } }; -static void mipsnet_cleanup(NetClientState *nc) -{ - MIPSnetState *s = qemu_get_nic_opaque(nc); - - s->nic = NULL; -} - static NetClientInfo net_mipsnet_info = { .type = NET_CLIENT_OPTIONS_KIND_NIC, .size = sizeof(NICState), .can_receive = mipsnet_can_receive, .receive = mipsnet_receive, - .cleanup = mipsnet_cleanup, }; static const MemoryRegionOps mipsnet_ioport_ops = { diff --git a/hw/net/ne2000-isa.c b/hw/net/ne2000-isa.c index 82e2ba1..17e7199 100644 --- a/hw/net/ne2000-isa.c +++ b/hw/net/ne2000-isa.c @@ -41,19 +41,11 @@ typedef struct ISANE2000State { NE2000State ne2000; } ISANE2000State; -static void isa_ne2000_cleanup(NetClientState *nc) -{ - NE2000State *s = qemu_get_nic_opaque(nc); - - s->nic = NULL; -} - static NetClientInfo net_ne2000_isa_info = { .type = NET_CLIENT_OPTIONS_KIND_NIC, .size = sizeof(NICState), .can_receive = ne2000_can_receive, .receive = ne2000_receive, - .cleanup = isa_ne2000_cleanup, }; static const VMStateDescription vmstate_isa_ne2000 = { diff --git a/hw/net/ne2000.c b/hw/net/ne2000.c index 3ab2d03..4dea701 100644 --- a/hw/net/ne2000.c +++ b/hw/net/ne2000.c @@ -702,19 +702,11 @@ void ne2000_setup_io(NE2000State *s, DeviceState *dev, unsigned size) memory_region_init_io(&s->io, OBJECT(dev), &ne2000_ops, s, "ne2000", size); } -static void ne2000_cleanup(NetClientState *nc) -{ - NE2000State *s = qemu_get_nic_opaque(nc); - - s->nic = NULL; -} - static NetClientInfo net_ne2000_info = { .type = NET_CLIENT_OPTIONS_KIND_NIC, .size = sizeof(NICState), .can_receive = ne2000_can_receive, .receive = ne2000_receive, - .cleanup = ne2000_cleanup, }; static int pci_ne2000_init(PCIDevice *pci_dev) diff --git a/hw/net/opencores_eth.c b/hw/net/opencores_eth.c index 4a44304..3642046 100644 --- a/hw/net/opencores_eth.c +++ b/hw/net/opencores_eth.c @@ -472,16 +472,11 @@ static ssize_t open_eth_receive(NetClientState *nc, return size; } -static void open_eth_cleanup(NetClientState *nc) -{ -} - static NetClientInfo net_open_eth_info = { .type = NET_CLIENT_OPTIONS_KIND_NIC, .size = sizeof(NICState), .can_receive = open_eth_can_receive, .receive = open_eth_receive, - .cleanup = open_eth_cleanup, .link_status_changed = open_eth_set_link_status, }; diff --git a/hw/net/pcnet-pci.c b/hw/net/pcnet-pci.c index fb5f5d6..b86bc0d 100644 --- a/hw/net/pcnet-pci.c +++ b/hw/net/pcnet-pci.c @@ -271,13 +271,6 @@ static void pci_physical_memory_read(void *dma_opaque, hwaddr addr, pci_dma_read(dma_opaque, addr, buf, len); } -static void pci_pcnet_cleanup(NetClientState *nc) -{ - PCNetState *d = qemu_get_nic_opaque(nc); - - pcnet_common_cleanup(d); -} - static void pci_pcnet_uninit(PCIDevice *dev) { PCIPCNetState *d = PCI_PCNET(dev); @@ -294,7 +287,6 @@ static NetClientInfo net_pci_pcnet_info = { .can_receive = pcnet_can_receive, .receive = pcnet_receive, .link_status_changed = pcnet_set_link_status, - .cleanup = pci_pcnet_cleanup, }; static int pci_pcnet_init(PCIDevice *pci_dev) diff --git a/hw/net/pcnet.c b/hw/net/pcnet.c index f409b92..8a1c8f1 100644 --- a/hw/net/pcnet.c +++ b/hw/net/pcnet.c @@ -1724,11 +1724,6 @@ const VMStateDescription vmstate_pcnet = { } }; -void pcnet_common_cleanup(PCNetState *d) -{ - d->nic = NULL; -} - int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info) { int i; diff --git a/hw/net/pcnet.h b/hw/net/pcnet.h index f8e8a6f..3f12fe3 100644 --- a/hw/net/pcnet.h +++ b/hw/net/pcnet.h @@ -63,7 +63,6 @@ uint32_t pcnet_bcr_readw(PCNetState *s, uint32_t rap); int pcnet_can_receive(NetClientState *nc); ssize_t pcnet_receive(NetClientState *nc, const uint8_t *buf, size_t size_); void pcnet_set_link_status(NetClientState *nc); -void pcnet_common_cleanup(PCNetState *d); int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info); extern const VMStateDescription vmstate_pcnet; #endif diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c index 5f0197c..6fa9e0a 100644 --- a/hw/net/rtl8139.c +++ b/hw/net/rtl8139.c @@ -3455,13 +3455,6 @@ static void rtl8139_timer(void *opaque) rtl8139_set_next_tctr_time(s, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); } -static void rtl8139_cleanup(NetClientState *nc) -{ - RTL8139State *s = qemu_get_nic_opaque(nc); - - s->nic = NULL; -} - static void pci_rtl8139_uninit(PCIDevice *dev) { RTL8139State *s = RTL8139(dev); @@ -3494,7 +3487,6 @@ static NetClientInfo net_rtl8139_info = { .size = sizeof(NICState), .can_receive = rtl8139_can_receive, .receive = rtl8139_receive, - .cleanup = rtl8139_cleanup, .link_status_changed = rtl8139_set_link_status, }; diff --git a/hw/net/smc91c111.c b/hw/net/smc91c111.c index d1dca8f..74e06e6 100644 --- a/hw/net/smc91c111.c +++ b/hw/net/smc91c111.c @@ -736,19 +736,11 @@ static const MemoryRegionOps smc91c111_mem_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static void smc91c111_cleanup(NetClientState *nc) -{ - smc91c111_state *s = qemu_get_nic_opaque(nc); - - s->nic = NULL; -} - static NetClientInfo net_smc91c111_info = { .type = NET_CLIENT_OPTIONS_KIND_NIC, .size = sizeof(NICState), .can_receive = smc91c111_can_receive, .receive = smc91c111_receive, - .cleanup = smc91c111_cleanup, }; static int smc91c111_init1(SysBusDevice *sbd) diff --git a/hw/net/spapr_llan.c b/hw/net/spapr_llan.c index 2c8b038..c255d92 100644 --- a/hw/net/spapr_llan.c +++ b/hw/net/spapr_llan.c @@ -187,19 +187,11 @@ static ssize_t spapr_vlan_receive(NetClientState *nc, const uint8_t *buf, return size; } -static void spapr_vlan_cleanup(NetClientState *nc) -{ - VIOsPAPRVLANDevice *dev = qemu_get_nic_opaque(nc); - - dev->nic = NULL; -} - static NetClientInfo net_spapr_vlan_info = { .type = NET_CLIENT_OPTIONS_KIND_NIC, .size = sizeof(NICState), .can_receive = spapr_vlan_can_receive, .receive = spapr_vlan_receive, - .cleanup = spapr_vlan_cleanup, }; static void spapr_vlan_reset(VIOsPAPRDevice *sdev) diff --git a/hw/net/stellaris_enet.c b/hw/net/stellaris_enet.c index c07e513..278a654 100644 --- a/hw/net/stellaris_enet.c +++ b/hw/net/stellaris_enet.c @@ -451,19 +451,11 @@ static void stellaris_enet_reset(stellaris_enet_state *s) s->tx_fifo_len = 0; } -static void stellaris_enet_cleanup(NetClientState *nc) -{ - stellaris_enet_state *s = qemu_get_nic_opaque(nc); - - s->nic = NULL; -} - static NetClientInfo net_stellaris_enet_info = { .type = NET_CLIENT_OPTIONS_KIND_NIC, .size = sizeof(NICState), .can_receive = stellaris_enet_can_receive, .receive = stellaris_enet_receive, - .cleanup = stellaris_enet_cleanup, }; static int stellaris_enet_init(SysBusDevice *sbd) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index e574bd4..45da34a 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1522,19 +1522,11 @@ static int virtio_net_load_device(VirtIODevice *vdev, QEMUFile *f, return 0; } -static void virtio_net_cleanup(NetClientState *nc) -{ - VirtIONet *n = qemu_get_nic_opaque(nc); - - n->nic = NULL; -} - static NetClientInfo net_virtio_info = { .type = NET_CLIENT_OPTIONS_KIND_NIC, .size = sizeof(NICState), .can_receive = virtio_net_can_receive, .receive = virtio_net_receive, - .cleanup = virtio_net_cleanup, .link_status_changed = virtio_net_set_link_status, .query_rx_filter = virtio_net_query_rxfilter, }; diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c index 8eea589..a83d2a1 100644 --- a/hw/net/vmxnet3.c +++ b/hw/net/vmxnet3.c @@ -1912,12 +1912,6 @@ vmxnet3_receive(NetClientState *nc, const uint8_t *buf, size_t size) return bytes_indicated; } -static void vmxnet3_cleanup(NetClientState *nc) -{ - VMXNET3State *s = qemu_get_nic_opaque(nc); - s->nic = NULL; -} - static void vmxnet3_set_link_status(NetClientState *nc) { VMXNET3State *s = qemu_get_nic_opaque(nc); @@ -1937,7 +1931,6 @@ static NetClientInfo net_vmxnet3_info = { .size = sizeof(NICState), .can_receive = vmxnet3_can_receive, .receive = vmxnet3_receive, - .cleanup = vmxnet3_cleanup, .link_status_changed = vmxnet3_set_link_status, }; diff --git a/hw/net/xgmac.c b/hw/net/xgmac.c index aeffcb5..b068f3a 100644 --- a/hw/net/xgmac.c +++ b/hw/net/xgmac.c @@ -368,19 +368,11 @@ out: return ret; } -static void eth_cleanup(NetClientState *nc) -{ - XgmacState *s = qemu_get_nic_opaque(nc); - - s->nic = NULL; -} - static NetClientInfo net_xgmac_enet_info = { .type = NET_CLIENT_OPTIONS_KIND_NIC, .size = sizeof(NICState), .can_receive = eth_can_rx, .receive = eth_rx, - .cleanup = eth_cleanup, }; static int xgmac_enet_init(SysBusDevice *sbd) diff --git a/hw/net/xilinx_axienet.c b/hw/net/xilinx_axienet.c index cd952d2..21efedf 100644 --- a/hw/net/xilinx_axienet.c +++ b/hw/net/xilinx_axienet.c @@ -857,14 +857,6 @@ static ssize_t eth_rx(NetClientState *nc, const uint8_t *buf, size_t size) return size; } -static void eth_cleanup(NetClientState *nc) -{ - /* FIXME. */ - XilinxAXIEnet *s = qemu_get_nic_opaque(nc); - g_free(s->rxmem); - g_free(s); -} - static size_t xilinx_axienet_control_stream_push(StreamSlave *obj, uint8_t *buf, size_t len) { @@ -936,7 +928,6 @@ static NetClientInfo net_xilinx_enet_info = { .size = sizeof(NICState), .can_receive = eth_can_rx, .receive = eth_rx, - .cleanup = eth_cleanup, }; static void xilinx_enet_realize(DeviceState *dev, Error **errp) diff --git a/hw/net/xilinx_ethlite.c b/hw/net/xilinx_ethlite.c index 1b177b3..9536f64 100644 --- a/hw/net/xilinx_ethlite.c +++ b/hw/net/xilinx_ethlite.c @@ -212,19 +212,11 @@ static void xilinx_ethlite_reset(DeviceState *dev) s->rxbuf = 0; } -static void eth_cleanup(NetClientState *nc) -{ - struct xlx_ethlite *s = qemu_get_nic_opaque(nc); - - s->nic = NULL; -} - static NetClientInfo net_xilinx_ethlite_info = { .type = NET_CLIENT_OPTIONS_KIND_NIC, .size = sizeof(NICState), .can_receive = eth_can_rx, .receive = eth_rx, - .cleanup = eth_cleanup, }; static void xilinx_ethlite_realize(DeviceState *dev, Error **errp) -- cgit v1.1 From b4f72e31b924bec2c18fe0b2a8c6462dbed9dcb2 Mon Sep 17 00:00:00 2001 From: Chen Gang Date: Wed, 17 Dec 2014 04:48:54 +0800 Subject: hw/net/xen_nic.c: Free 'netdev->txs' when map 'netdev->rxs' fails When map 'netdev->rxs' fails, need free the original resource, or will cause resource leak. Signed-off-by: Chen Gang Signed-off-by: Stefan Hajnoczi --- hw/net/xen_nic.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c index 63918ae..7a57feb 100644 --- a/hw/net/xen_nic.c +++ b/hw/net/xen_nic.c @@ -370,11 +370,16 @@ static int net_connect(struct XenDevice *xendev) netdev->xendev.dom, netdev->tx_ring_ref, PROT_READ | PROT_WRITE); + if (!netdev->txs) { + return -1; + } netdev->rxs = xc_gnttab_map_grant_ref(netdev->xendev.gnttabdev, netdev->xendev.dom, netdev->rx_ring_ref, PROT_READ | PROT_WRITE); - if (!netdev->txs || !netdev->rxs) { + if (!netdev->rxs) { + xc_gnttab_munmap(netdev->xendev.gnttabdev, netdev->txs, 1); + netdev->txs = NULL; return -1; } BACK_RING_INIT(&netdev->tx_ring, netdev->txs, XC_PAGE_SIZE); -- cgit v1.1 From d46858377b822b820946c6b2e3a9153ee0aebd37 Mon Sep 17 00:00:00 2001 From: Chen Gang Date: Wed, 17 Dec 2014 04:52:16 +0800 Subject: hw/net/xen_nic.c: Need free 'netdev->nic' in net_free() instead of net_disconnect() net_init() and net_free() are pairs, net_connect() and net_disconnect() are pairs. net_init() creates 'netdev->nic', so also need free it in net_free(). Signed-off-by: Chen Gang Signed-off-by: Stefan Hajnoczi --- hw/net/xen_nic.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c index 7a57feb..8eaa77b 100644 --- a/hw/net/xen_nic.c +++ b/hw/net/xen_nic.c @@ -410,10 +410,6 @@ static void net_disconnect(struct XenDevice *xendev) xc_gnttab_munmap(netdev->xendev.gnttabdev, netdev->rxs, 1); netdev->rxs = NULL; } - if (netdev->nic) { - qemu_del_nic(netdev->nic); - netdev->nic = NULL; - } } static void net_event(struct XenDevice *xendev) @@ -427,6 +423,10 @@ static int net_free(struct XenDevice *xendev) { struct XenNetDev *netdev = container_of(xendev, struct XenNetDev, xendev); + if (netdev->nic) { + qemu_del_nic(netdev->nic); + netdev->nic = NULL; + } g_free(netdev->mac); return 0; } -- cgit v1.1 From a39d97c7becca5fd679d70d17ae5b1d62b9b5da6 Mon Sep 17 00:00:00 2001 From: Chen Gang Date: Wed, 17 Dec 2014 04:58:42 +0800 Subject: hw/net/xen_nic.c: Set 'netdev->mac' to NULL after free it Since net_init() checks whether 'netdev->mac' is NULL, before alloc it; net_release() also need set 'netdev->mac' to NULL after free it. Signed-off-by: Chen Gang Signed-off-by: Stefan Hajnoczi --- hw/net/xen_nic.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c index 8eaa77b..19ecfc4 100644 --- a/hw/net/xen_nic.c +++ b/hw/net/xen_nic.c @@ -428,6 +428,7 @@ static int net_free(struct XenDevice *xendev) netdev->nic = NULL; } g_free(netdev->mac); + netdev->mac = NULL; return 0; } -- cgit v1.1