From patchwork Mon Jul 15 10:23:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 11043551 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DC2176C5 for ; Mon, 15 Jul 2019 10:24:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB6331FF7F for ; Mon, 15 Jul 2019 10:24:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD7A928399; Mon, 15 Jul 2019 10:24:03 +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=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 90B671FF7F for ; Mon, 15 Jul 2019 10:24:02 +0000 (UTC) Received: from localhost ([::1]:36666 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hmy9J-0000sz-G1 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 15 Jul 2019 06:24:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35026) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hmy98-0000Ig-D7 for qemu-devel@nongnu.org; Mon, 15 Jul 2019 06:23:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hmy97-00081p-H5 for qemu-devel@nongnu.org; Mon, 15 Jul 2019 06:23:50 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:42416) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hmy97-00080i-BB for qemu-devel@nongnu.org; Mon, 15 Jul 2019 06:23:49 -0400 Received: by mail-pl1-x641.google.com with SMTP id ay6so8064928plb.9 for ; Mon, 15 Jul 2019 03:23:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=7p2G/91PqJ8RuOo5lhHUra5YVPwP+D+LVK4urSQ4OpA=; b=bK8x2Zr8/rJFONtuAaOfrtOkNr+LN0fAHst74lyaoE/b4xJoshc32toRLNjbp7t4b+ fR53E6LnIEU91KEH/9bNUCIUCkFeIBLGNtI/5PlrzRNqns85E9HDpzd0D/GKUzqkRS3C /2LRkWsDx9ZeZcbSGssQm7/2Jg/1xvs37r5qx9m/83+bzVu7N5aAZxf3Ma1CBaVpAYot PsKkszco34qXXLlMQphUIJG0hyHboF50ZAFjCHYidCTUkd9rUE7KVaeX6V/KJ/f82Wjv 3H03CVi2ZZZiWBhcztYJIDxUZIXirtXUfLxUKLfqZVxWscHLZYzXLsBkVP7X7QnILPuH ooUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=7p2G/91PqJ8RuOo5lhHUra5YVPwP+D+LVK4urSQ4OpA=; b=SCHnylV0bVnPnfc9VOvEO/PlyKyj2T3/DaGc4iWQaw31nybpDJO9ZFWDTAKhpcC5au 4+PrlJxnOGGrZjqOJafMRk0NG5MPYoWmkKIvvw40f4FynnFNfeiVke7ZdvVyQpnEZwbG 0Qcr7SMvOd0rhPJzApk6s1om+mMG01nDRv8jIKkIai+rWHvSim1VblOaJfwxyL1udcHO RpzqgZNN9rrPPZjJyOZJkjdktpz7HxFHPjSWTSDDSMVW4nifwlW9JSeQGi+JDXZuDsu0 O0ZvMTVc+27+CnflDHLUPhWuhMx4r6lbzIj0xRpkTWec3bWdmq/t3aow/ONn9hLQOHNE ny7w== X-Gm-Message-State: APjAAAWrJo0Pcw44sMNWujN6rSqtVWmXcoM5/tW0RlV0r3WgFfXnLmN/ GD0eW5QkKj6qITHS5i+u/T0= X-Google-Smtp-Source: APXvYqw9SB3SBYrMcDya6hs0EDVcdlmoLhSkZ6Jbt01rgAl+Zm4S0dJYhRxYG4WEYGb3zPHVuB2VHg== X-Received: by 2002:a17:902:6b85:: with SMTP id p5mr25069625plk.225.1563186227723; Mon, 15 Jul 2019 03:23:47 -0700 (PDT) Received: from localhost ([116.247.112.152]) by smtp.gmail.com with ESMTPSA id m9sm31381908pgr.24.2019.07.15.03.23.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 15 Jul 2019 03:23:47 -0700 (PDT) From: elohimes@gmail.com X-Google-Original-From: xieyongji@baidu.com To: mst@redhat.com, stefanha@gmail.com, pbonzini@redhat.com, fam@euphon.net Date: Mon, 15 Jul 2019 18:23:25 +0800 Message-Id: <20190715102326.2805-1-xieyongji@baidu.com> X-Mailer: git-send-email 2.17.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::641 Subject: [Qemu-devel] [PATCH 1/2] vhost-scsi: Call virtio_scsi_common_unrealize() when device realize failed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Xie Yongji , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Xie Yongji This avoids memory leak when device hotplug is failed. Signed-off-by: Xie Yongji --- hw/scsi/vhost-scsi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c index 4090f99ee4..db4a090576 100644 --- a/hw/scsi/vhost-scsi.c +++ b/hw/scsi/vhost-scsi.c @@ -210,7 +210,7 @@ static void vhost_scsi_realize(DeviceState *dev, Error **errp) if (err) { error_propagate(errp, err); error_free(vsc->migration_blocker); - goto close_fd; + goto free_virtio; } } @@ -240,6 +240,8 @@ static void vhost_scsi_realize(DeviceState *dev, Error **errp) migrate_del_blocker(vsc->migration_blocker); } g_free(vsc->dev.vqs); + free_virtio: + virtio_scsi_common_unrealize(dev, errp); close_fd: close(vhostfd); return; From patchwork Mon Jul 15 10:23:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 11043553 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AAA8C6C5 for ; Mon, 15 Jul 2019 10:24:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A58C1FF7F for ; Mon, 15 Jul 2019 10:24:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8EBEB28399; Mon, 15 Jul 2019 10:24:07 +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=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 421131FF7F for ; Mon, 15 Jul 2019 10:24:07 +0000 (UTC) Received: from localhost ([::1]:36668 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hmy9O-0001Fq-CR for patchwork-qemu-devel@patchwork.kernel.org; Mon, 15 Jul 2019 06:24:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35041) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hmy9B-0000L1-Av for qemu-devel@nongnu.org; Mon, 15 Jul 2019 06:23:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hmy9A-00083K-DU for qemu-devel@nongnu.org; Mon, 15 Jul 2019 06:23:53 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:33335) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hmy9A-00082v-6t for qemu-devel@nongnu.org; Mon, 15 Jul 2019 06:23:52 -0400 Received: by mail-pf1-x442.google.com with SMTP id g2so7223267pfq.0 for ; Mon, 15 Jul 2019 03:23:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+wNQNJSarln9knX28psYjT7Bngaa0MsW1kki3C9Cweo=; b=mFh/nUt7Psi6dchjwmmOgok29HlE6P8wr3dSkqncGkt94Bi9uzld4bmq7GbMi7/MX7 enRPn0E4exeXo+lq1lHl9RZmCQpmqVg+XJ9Ixtq3KgGKTpsP04DG2EYqDprpIA6stav2 WjCbetCHPTqzrVS40dWdGGZluo9i0qgQJS2zPVt9gT+qKS92nZGf6GfzQbu/YzqaWXS8 pwCUpPUUBH93r4lV9bLEuGCU0AfSdKBF/ZdyQb1kKelhSQU7vC7x1LXa0hcTRo2dMQaM dh07Tz13b5+KEvQV++OykLup4kNu3b6FJ34YdPmwC+bUF8A842mvNfbrnaBlBj0Uveai TmNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+wNQNJSarln9knX28psYjT7Bngaa0MsW1kki3C9Cweo=; b=WQuL0BIi2vJXwHm/Q3wHUK9TWFF4cSai392J61K1ALWB/YFpxEhHa66dBkXZVLh7hf hne4azx6aGubEQmfvPFjhtMj5zi8hOBkXnu9/DCxeMITLtcXIMvp7q8AlameeYHJlKfS zcsff+7XjpH3h5mupjrYL2Px6YZIDreOM7uqLwsHWcSeCKJ57xN5ns/to7+px0UShvEP r/K9Z5asgRZxLiM4s3/ULUfRQ7sDblWYp75sBvbq6+FJ5jhpy1MlRgCdCZfUn0W4BvLW oMRqhmD/cau+dS++gVM+VSsqiYTXF6iSX2VUFA8Gn1ExynLIRfwlFRf8buBAc87oJDK6 Gi1A== X-Gm-Message-State: APjAAAX9F3a8W2b5dSowsK04cUdgnhUBS76BAgxLRN9zkl03L+w9DQVy 1Lr17wapx3wlbW9l8i6+uI4= X-Google-Smtp-Source: APXvYqzIAbzwl/j1Mx0/dYjtav5gczxnzO0t7AhaQySuTXNG9s+Aa7aMzxF1iEbtGEw19iTTZinaMw== X-Received: by 2002:a17:90b:d8f:: with SMTP id bg15mr28342218pjb.65.1563186231274; Mon, 15 Jul 2019 03:23:51 -0700 (PDT) Received: from localhost ([116.247.112.152]) by smtp.gmail.com with ESMTPSA id 131sm21636967pfx.57.2019.07.15.03.23.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 15 Jul 2019 03:23:50 -0700 (PDT) From: elohimes@gmail.com X-Google-Original-From: xieyongji@baidu.com To: mst@redhat.com, stefanha@gmail.com, pbonzini@redhat.com, fam@euphon.net Date: Mon, 15 Jul 2019 18:23:26 +0800 Message-Id: <20190715102326.2805-2-xieyongji@baidu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190715102326.2805-1-xieyongji@baidu.com> References: <20190715102326.2805-1-xieyongji@baidu.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 Subject: [Qemu-devel] [PATCH 2/2] vhost-user-scsi: Call virtio_scsi_common_unrealize() when device realize failed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Xie Yongji , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Xie Yongji This avoids memory leak when device hotplug is failed. Signed-off-by: Xie Yongji --- hw/scsi/vhost-user-scsi.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c index a9fd8ea305..a79653df46 100644 --- a/hw/scsi/vhost-user-scsi.c +++ b/hw/scsi/vhost-user-scsi.c @@ -87,7 +87,7 @@ static void vhost_user_scsi_realize(DeviceState *dev, Error **errp) } if (!vhost_user_init(&s->vhost_user, &vs->conf.chardev, errp)) { - return; + goto free_virtio; } vsc->dev.nvqs = 2 + vs->conf.num_queues; @@ -101,15 +101,21 @@ static void vhost_user_scsi_realize(DeviceState *dev, Error **errp) if (ret < 0) { error_setg(errp, "vhost-user-scsi: vhost initialization failed: %s", strerror(-ret)); - vhost_user_cleanup(&s->vhost_user); - g_free(vqs); - return; + goto free_vhost; } /* Channel and lun both are 0 for bootable vhost-user-scsi disk */ vsc->channel = 0; vsc->lun = 0; vsc->target = vs->conf.boot_tpgt; + + return; + +free_vhost: + vhost_user_cleanup(&s->vhost_user); + g_free(vqs); +free_virtio: + virtio_scsi_common_unrealize(dev, errp); } static void vhost_user_scsi_unrealize(DeviceState *dev, Error **errp)