From patchwork Thu Feb 2 18:35:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 9552909 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 57E3460424 for ; Thu, 2 Feb 2017 18:38:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47C0F28411 for ; Thu, 2 Feb 2017 18:38:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C3632849B; Thu, 2 Feb 2017 18:38:04 +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.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 95E3828411 for ; Thu, 2 Feb 2017 18:38:03 +0000 (UTC) Received: from localhost ([::1]:58411 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZMGg-00057h-TB for patchwork-qemu-devel@patchwork.kernel.org; Thu, 02 Feb 2017 13:38:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38297) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZMEb-0003qF-HD for qemu-devel@nongnu.org; Thu, 02 Feb 2017 13:35:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cZMEa-0004gX-Kz for qemu-devel@nongnu.org; Thu, 02 Feb 2017 13:35:53 -0500 Received: from mail.kernel.org ([198.145.29.136]:45178) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cZMEa-0004g6-EY for qemu-devel@nongnu.org; Thu, 02 Feb 2017 13:35:52 -0500 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AEFA6201C7; Thu, 2 Feb 2017 18:35:50 +0000 (UTC) Received: from sstabellini-ThinkPad-X260.hsd1.ca.comcast.net (c-50-131-44-19.hsd1.ca.comcast.net [50.131.44.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 81727202FF; Thu, 2 Feb 2017 18:35:49 +0000 (UTC) From: Stefano Stabellini To: stefanha@gmail.com Date: Thu, 2 Feb 2017 10:35:41 -0800 Message-Id: <1486060541-29146-5-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1486060541-29146-1-git-send-email-sstabellini@kernel.org> References: <1486060541-29146-1-git-send-email-sstabellini@kernel.org> MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 198.145.29.136 Subject: [Qemu-devel] [PULL 5/5] xen: use qdev_unplug() instead of g_free() in xen_pv_find_xendev() 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: Juergen Gross , peter.maydell@linaro.org, sstabellini@kernel.org, qemu-devel@nongnu.org, stefanha@redhat.com, anthony.perard@citrix.com, xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Juergen Gross The error exits of xen_pv_find_xendev() free the new xen-device via g_free() which is wrong. As the xen-device has been initialized as qdev it must be removed via qdev_unplug(). This bug has been introduced with commit 3a6c9172ac5951e6dac2b3f6 ("xen: create qdev for each backend device"). Reported-by: Roger Pau Monné Tested-by: Roger Pau Monné Signed-off-by: Juergen Gross Reviewed-by: Stefano Stabellini --- hw/xen/xen_backend.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index d119004..6c21c37 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -124,10 +124,11 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, /* init new xendev */ xendev = g_malloc0(ops->size); object_initialize(&xendev->qdev, ops->size, TYPE_XENBACKEND); - qdev_set_parent_bus(&xendev->qdev, xen_sysbus); - qdev_set_id(&xendev->qdev, g_strdup_printf("xen-%s-%d", type, dev)); - qdev_init_nofail(&xendev->qdev); - object_unref(OBJECT(&xendev->qdev)); + OBJECT(xendev)->free = g_free; + qdev_set_parent_bus(DEVICE(xendev), xen_sysbus); + qdev_set_id(DEVICE(xendev), g_strdup_printf("xen-%s-%d", type, dev)); + qdev_init_nofail(DEVICE(xendev)); + object_unref(OBJECT(xendev)); xendev->type = type; xendev->dom = dom; @@ -145,7 +146,7 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, xendev->evtchndev = xenevtchn_open(NULL, 0); if (xendev->evtchndev == NULL) { xen_pv_printf(NULL, 0, "can't open evtchn device\n"); - g_free(xendev); + qdev_unplug(DEVICE(xendev), NULL); return NULL; } fcntl(xenevtchn_fd(xendev->evtchndev), F_SETFD, FD_CLOEXEC); @@ -155,7 +156,7 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, if (xendev->gnttabdev == NULL) { xen_pv_printf(NULL, 0, "can't open gnttab device\n"); xenevtchn_close(xendev->evtchndev); - g_free(xendev); + qdev_unplug(DEVICE(xendev), NULL); return NULL; } } else {