From patchwork Wed Dec 14 03:03:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 9473657 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 7863560823 for ; Wed, 14 Dec 2016 03:05:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B802286B3 for ; Wed, 14 Dec 2016 03:05:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5D607286E3; Wed, 14 Dec 2016 03:05:13 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 D3ED6286B3 for ; Wed, 14 Dec 2016 03:05:12 +0000 (UTC) Received: from localhost ([::1]:45213 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cGzsV-0007YO-Ur for patchwork-qemu-devel@patchwork.kernel.org; Tue, 13 Dec 2016 22:05:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58841) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cGzs3-0007KV-5o for qemu-devel@nongnu.org; Tue, 13 Dec 2016 22:04:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cGzrz-0008HX-8C for qemu-devel@nongnu.org; Tue, 13 Dec 2016 22:04:43 -0500 Received: from mail-oi0-f68.google.com ([209.85.218.68]:33341) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cGzrz-0008HB-1t for qemu-devel@nongnu.org; Tue, 13 Dec 2016 22:04:39 -0500 Received: by mail-oi0-f68.google.com with SMTP id f201so871853oib.0 for ; Tue, 13 Dec 2016 19:04:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:from:to:cc:subject:date; bh=LbqvRvIDoTAh/FO/SI3muFeGb9gIL0/3ws7pF9bPRwU=; b=JHlLGAssTgh6IReCCPJwIOvBAc8Q5yjybjmvEnsVk3vui3YoeP1I0OZCobRzVQ59T2 A1iP5MHuZRGviUQnU5WnP9n9/n4dX94wDSOBXp9LNluAyru+CQcJQoUOrAY1aPII81Tn AWQA6zXJxVhD6nE0RBSSV16yXJY1yEVnbQ6CEbf1iLxVCUhoag9uFTdqAoxRSH3Pyi50 U3g7hSU0tTV67jtTxr/Rz73DrujsenuoiE7d5R33aagJ6tY91cebgVBQTVjvU3K9ARyo qqYDCL54yWHOGi1qA8rtZml+/fuRbZugvl4ZJXJJafTFEjiJyjm73gCKFTwFjP26JjMe twjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:from:to:cc:subject:date; bh=LbqvRvIDoTAh/FO/SI3muFeGb9gIL0/3ws7pF9bPRwU=; b=TIiibsSr8uk15fQhhMZzsJg1w2mSVCFGT5caN1UbNBe9z1diYxRrvb6DEtAw5pwYIY 0pnYpOK5XmU+XHKW2q/DXosV/ArnWCP0IkmUna/EsHHA4nmzVDQpzCdC7mMxXchLlxWT csX6qq/MT0AqF8hfXUIKstYnMj5qb7mM3quXBJWzUtx+hpUMglYpiIriBqhM9Nb8mlbo p3qHnC2tgsuENPThuMswGBZupRBr42jSkzhEgRfmmGDQ/V7Jra8tIEuVBxyF3aCwoaK+ MC8du4jzvsWD/9UMN35gjWm+TcYOoMIF9E/MkCXYCdLo5KzFIZOemamOeIbMS9swLtiJ M7LQ== X-Gm-Message-State: AKaTC01co/Fufl/5HE72q2dCwDwRfzVL2D3nsDdSnV22OVyCLjnyY2nvSVbu+by6/sMg2g== X-Received: by 10.157.6.7 with SMTP id 7mr59889136otn.43.1481684618341; Tue, 13 Dec 2016 19:03:38 -0800 (PST) Received: from localhost.localdomain.localdomain ([104.192.110.250]) by smtp.gmail.com with ESMTPSA id l37sm19901795otd.33.2016.12.13.19.03.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Dec 2016 19:03:37 -0800 (PST) Message-ID: <5850b689.68219d0a.9be2d.9b07@mx.google.com> X-Google-Original-Message-ID: <1481684612-4880-1-git-send-email-Qiang(liqiang6-s@360.cn)> From: Li Qiang X-Google-Original-From: Li Qiang(liqiang6-s@360.cn) To: kraxel@redhat.com, qemu-devel@nongnu.org, marcandre.lureau@gmail.com Date: Tue, 13 Dec 2016 19:03:32 -0800 X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.218.68 Subject: [Qemu-devel] [PATCH v2] audio: ac97: add exit function 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: Li Qiang Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Li Qiang Currently the ac97 device emulation doesn't have a exit function, hot unplug this device will leak some memory. Add a exit function to avoid this. Signed-off-by: Li Qiang --- Changes since the v1: close the streams hw/audio/ac97.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/hw/audio/ac97.c b/hw/audio/ac97.c index cbd959e..efa20b5 100644 --- a/hw/audio/ac97.c +++ b/hw/audio/ac97.c @@ -1387,6 +1387,23 @@ static void ac97_realize(PCIDevice *dev, Error **errp) ac97_on_reset (&s->dev.qdev); } +static void ac97_exit(PCIDevice *dev) +{ + AC97LinkState *s = DO_UPCAST(AC97LinkState, dev, dev); + + if (s->voice_pi) { + AUD_close_in (&s->card, s->voice_pi); + } + if (s->voice_po) { + AUD_close_out (&s->card, s->voice_po); + } + if (s->voice_mc) { + AUD_close_in (&s->card, s->voice_mc); + } + + AUD_remove_card (&s->card); +} + static int ac97_init (PCIBus *bus) { pci_create_simple (bus, -1, "AC97"); @@ -1404,6 +1421,7 @@ static void ac97_class_init (ObjectClass *klass, void *data) PCIDeviceClass *k = PCI_DEVICE_CLASS (klass); k->realize = ac97_realize; + k->exit = ac97_exit; k->vendor_id = PCI_VENDOR_ID_INTEL; k->device_id = PCI_DEVICE_ID_INTEL_82801AA_5; k->revision = 0x01;