From patchwork Thu Dec 15 02:30:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 9475431 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 A69D8607EE for ; Thu, 15 Dec 2016 02:33:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BA4D28424 for ; Thu, 15 Dec 2016 02:33:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F74F2871D; Thu, 15 Dec 2016 02:33:33 +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 08DD728424 for ; Thu, 15 Dec 2016 02:33:31 +0000 (UTC) Received: from localhost ([::1]:51801 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cHLrO-0000oH-3R for patchwork-qemu-devel@patchwork.kernel.org; Wed, 14 Dec 2016 21:33:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40641) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cHLqn-0000AB-6G for qemu-devel@nongnu.org; Wed, 14 Dec 2016 21:33:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cHLq2-0003ty-Ed for qemu-devel@nongnu.org; Wed, 14 Dec 2016 21:32:53 -0500 Received: from mail-qt0-f193.google.com ([209.85.216.193]:36806) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cHLq2-0003MP-80 for qemu-devel@nongnu.org; Wed, 14 Dec 2016 21:32:06 -0500 Received: by mail-qt0-f193.google.com with SMTP id n34so5297136qtb.3 for ; Wed, 14 Dec 2016 18:31:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:from:to:cc:subject:date; bh=WHOU6t6372ENlvwo2AyN2ezM21evB/Kq1dFbRAueFh8=; b=YW9kwVaX7/6c0sBgV/gZsV1oTkWuaDjmgG0t88P2Jhe6EiaZe1Jo7v8FKNcBcQw7qS nvVhuFZJjyFEoaOyNGT/+H2JPGgqf/3f5PeTBkLFtxFO/V4dZ3F+V48TtlcLTVPxGg72 6bYgbuLF7iGIHShdgij6aRtvn1c8IX+zdFl5jiQIstPjRgVZzL+cZNUbQUnJvep1x7LN kQeE9n+rwLk/LlozdwTyfSwjIoivF2tP2o2BI5kLYvBJQf0MUZgZRCcplohCx+YGiX2R mMaN/DPTWB/Jb3SYDxpGzeFHKRpI767/TFtwE3Re8ry7/qKzhwOtNzklFtCEh0i00DlH 9lBA== 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=WHOU6t6372ENlvwo2AyN2ezM21evB/Kq1dFbRAueFh8=; b=QP547heP64DQoXUi2tpj/pkLUOwwakES5tQHD435sjbhdo+z9baBP54eHur2/kl38/ 90M9iavyp2oDFxAgYU0F99O+6bkx1jT4BEaauuW60EFxqEHsY9hcVbOQCwhLC/3cizsz jctVCEUgwcvJWIOY7dRl0NNFyeuEsXMf+usHmC3XpNvN7XQ59FXkGAyKBsUCsh9zTcS0 Vgs3duax9Uo13hDTAqCznHqKYeORl7WLxALyiKYghHsnXfiudXIV50o4eMKOw5azygqB QJSdQad2YNEgnGAURAKJx9O3UJUNbscptaAF808cTit6oAUOqds4VS5FtFFbMZ63g7Bl ysCA== X-Gm-Message-State: AKaTC00B4kUcu4lx039BnZBf8MksMzcungfYIertQMl4iE4ljKuhv7JjTypSguDrClamxQ== X-Received: by 10.200.53.249 with SMTP id l54mr103178337qtb.173.1481769042955; Wed, 14 Dec 2016 18:30:42 -0800 (PST) Received: from localhost.localdomain.localdomain ([104.192.110.250]) by smtp.gmail.com with ESMTPSA id w8sm33255419qtc.3.2016.12.14.18.30.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Dec 2016 18:30:42 -0800 (PST) Message-ID: <58520052.4825ed0a.27a71.6cae@mx.google.com> X-Google-Original-Message-ID: <1481769021-5857-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, marcandre.lureau@gmail.com, qemu-devel@nongnu.org Date: Wed, 14 Dec 2016 18:30:21 -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.216.193 Subject: [Qemu-devel] [PATCH v3] 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 Reviewed-by: Marc-André Lureau --- Changes since the v2: take out of the null check Changes since the v1: close the streams hw/audio/ac97.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/audio/ac97.c b/hw/audio/ac97.c index cbd959e..c306575 100644 --- a/hw/audio/ac97.c +++ b/hw/audio/ac97.c @@ -1387,6 +1387,16 @@ 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); + + AUD_close_in(&s->card, s->voice_pi); + AUD_close_out(&s->card, s->voice_po); + 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 +1414,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;