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: 9552919 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 BD9DA60424 for ; Thu, 2 Feb 2017 18:38:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B036728425 for ; Thu, 2 Feb 2017 18:38:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A50E7284AD; Thu, 2 Feb 2017 18:38:22 +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=-3.7 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 32E8E28425 for ; Thu, 2 Feb 2017 18:38:22 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cZMEd-0003mo-EY; Thu, 02 Feb 2017 18:35:55 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cZMEc-0003lN-BK for xen-devel@lists.xenproject.org; Thu, 02 Feb 2017 18:35:54 +0000 Received: from [193.109.254.147] by server-8.bemta-6.messagelabs.com id A9/6F-21675-90C73985; Thu, 02 Feb 2017 18:35:53 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrMIsWRWlGSWpSXmKPExsVybKJshy5nzeQ Ig2//mSy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyWph6mgj6hivntr9gaGB/xdTFycQgJTGWU 2HPxNjuEs4NJouftByCHk4NNwFDi75NNbCC2iICYxOnd05hAipgFDjFK3F21CiwhLBAm0XxjJ yOIzSKgKtF54zKYzSvgJrF4RQtYjYSAnMTJY5NZQWxOAXeJtrdTmSC2tTNKbFizjQmiQVDi5M wnLF2MHEAb1CXWzxMCCTMLyEs0b53NDDEnQ2JezxxWCNtLYtGNS1C2msTVc5uYJzAKzkIyaRb CpFlIJi1gZF7FqFGcWlSWWqRrbKyXVJSZnlGSm5iZo2toYKaXm1pcnJiempOYVKyXnJ+7iREY uAxAsINx5/rAQ4ySHExKorxTtCZHCPEl5adUZiQWZ8QXleakFh9ilOHgUJLgZakGygkWpaanV qRl5gBjCCYtwcGjJMI7rwoozVtckJhbnJkOkTrFqCglzusF0icAksgozYNrg8XtJUZZKWFeRq BDhHgKUotyM0tQ5V8xinMwKgnzOoBM4cnMK4Gb/gpoMRPQ4p+PJ4EsLklESEk1MDYKMQX2lEy aluHbz3irnb2/vP2qhW9iTE+lo+u0V5xC11svxh7me3d5b8SsMmERdpZElu+9izi/cv6fXhQ9 vbmZa4tfTeCZu4pzL999v2XZXuMjW/6tm/x55rtzOawxW1J3nvJfqL1VvUW4b1qzb2jIBqd2m Ucl17RjH3jss9XfKn+zIsHSS4mlOCPRUIu5qDgRAIPSOB7WAgAA X-Env-Sender: sstabellini@kernel.org X-Msg-Ref: server-13.tower-27.messagelabs.com!1486060551!75622807!1 X-Originating-IP: [198.145.29.136] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 37435 invoked from network); 2 Feb 2017 18:35:52 -0000 Received: from mail.kernel.org (HELO mail.kernel.org) (198.145.29.136) by server-13.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 2 Feb 2017 18:35:52 -0000 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 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 Subject: [Xen-devel] [PULL 5/5] xen: use qdev_unplug() instead of g_free() in xen_pv_find_xendev() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-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 {