From patchwork Thu Oct 13 17:45:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Weil X-Patchwork-Id: 9375583 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 06C876075E for ; Thu, 13 Oct 2016 17:58:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA8E82A15E for ; Thu, 13 Oct 2016 17:58:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DEADA2A163; Thu, 13 Oct 2016 17:58:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9EE0E2A15E for ; Thu, 13 Oct 2016 17:58:11 +0000 (UTC) Received: from localhost ([::1]:42247 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bukGg-0007cf-4n for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Oct 2016 13:58:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33519) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1buk54-0006Qi-1F for qemu-devel@nongnu.org; Thu, 13 Oct 2016 13:46:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1buk51-0008Dr-TO for qemu-devel@nongnu.org; Thu, 13 Oct 2016 13:46:09 -0400 Received: from qemu.weilnetz.de ([2a03:4000:2:362::1]:57804) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1buk51-0008Cd-Ng for qemu-devel@nongnu.org; Thu, 13 Oct 2016 13:46:07 -0400 Received: by qemu.weilnetz.de (Postfix, from userid 1000) id E57D217F591; Thu, 13 Oct 2016 19:46:03 +0200 (CEST) From: Stefan Weil To: QEMU Developer Date: Thu, 13 Oct 2016 19:45:59 +0200 Message-Id: <1476380759-18492-1-git-send-email-sw@weilnetz.de> X-Mailer: git-send-email 2.1.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a03:4000:2:362::1 Subject: [Qemu-devel] [PATCH] eepro100: Fix memory leak and simplify code for VMStateDescription X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Weil , Jason Wang , Li Qiang Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Instead of allocating a VMStateDescription for each NIC instance, the code now uses a single constant VMStateDescription for all instances. That implies that the name field is always the same. Reported-by: Li Qiang Signed-off-by: Stefan Weil --- hw/net/eepro100.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c index bab4dbf..6f9777d 100644 --- a/hw/net/eepro100.c +++ b/hw/net/eepro100.c @@ -269,9 +269,6 @@ typedef struct { /* Configuration bytes. */ uint8_t configuration[22]; - /* vmstate for each particular nic */ - VMStateDescription *vmstate; - /* Quasi static device properties (no need to save them). */ uint16_t stats_size; bool has_extended_tcb_support; @@ -1787,7 +1784,8 @@ static ssize_t nic_receive(NetClientState *nc, const uint8_t * buf, size_t size) return size; } -static const VMStateDescription vmstate_eepro100 = { +static const VMStateDescription vmstate_e100 = { + .name = "e100", .version_id = 3, .minimum_version_id = 2, .fields = (VMStateField[]) { @@ -1842,7 +1840,6 @@ static void pci_nic_uninit(PCIDevice *pci_dev) { EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev); - vmstate_unregister(&pci_dev->qdev, s->vmstate, s); eeprom93xx_free(&pci_dev->qdev, s->eeprom); qemu_del_nic(s->nic); } @@ -1892,11 +1889,6 @@ static void e100_nic_realize(PCIDevice *pci_dev, Error **errp) TRACE(OTHER, logout("%s\n", qemu_get_queue(s->nic)->info_str)); qemu_register_reset(nic_reset, s); - - s->vmstate = g_malloc(sizeof(vmstate_eepro100)); - memcpy(s->vmstate, &vmstate_eepro100, sizeof(vmstate_eepro100)); - s->vmstate->name = qemu_get_queue(s->nic)->model; - vmstate_register(&pci_dev->qdev, -1, s->vmstate, s); } static void eepro100_instance_init(Object *obj) @@ -2083,6 +2075,7 @@ static void eepro100_class_init(ObjectClass *klass, void *data) set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); dc->props = e100_properties; dc->desc = info->desc; + dc->vmsd = &vmstate_e100; k->vendor_id = PCI_VENDOR_ID_INTEL; k->class_id = PCI_CLASS_NETWORK_ETHERNET; k->romfile = "pxe-eepro100.rom";