From patchwork Wed Jul 17 00:46:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 11046849 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 2A47314F6 for ; Wed, 17 Jul 2019 00:47:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 18AF91FF7E for ; Wed, 17 Jul 2019 00:47:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0BC67285A7; Wed, 17 Jul 2019 00:47:00 +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 A61D21FF7E for ; Wed, 17 Jul 2019 00:46:59 +0000 (UTC) Received: from localhost ([::1]:53246 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnY5y-0002YO-I8 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 16 Jul 2019 20:46:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53627) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnY5Y-0001g5-16 for qemu-devel@nongnu.org; Tue, 16 Jul 2019 20:46:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnY5W-0001pj-Sw for qemu-devel@nongnu.org; Tue, 16 Jul 2019 20:46:31 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:44694) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hnY5W-0001pW-Mk for qemu-devel@nongnu.org; Tue, 16 Jul 2019 20:46:30 -0400 Received: by mail-pl1-x641.google.com with SMTP id t14so10968910plr.11 for ; Tue, 16 Jul 2019 17:46:30 -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=y7FSocOkMHVg4UK5VR546jFApa/3IjN0xth3/ynVktM=; b=jBFmTC7P9uml8WriUrIub0rQoyzoinEaCYneySCOTh5GI+AklZf58PZeo4A3lqTGZp pPr7KJDKUj8+rJbmxnH55/Bi6CwT8rX0yZZDmbBdQKEO+3jTJW0SDtvmGauM2Cd+Ql62 I8Fy/gMjz0YlHZKtoOEvWME4g6TDiZ7CoA8r9w63O/tLcJiWbZAD3k6XahiVgc1OENic qB1oZiRnrifJYdLAsNqzZPsifUqepwdzZheowIGX2NM+fzkJ4/tfRz5g5xk0SHlZuARm ZpmEM3OzhQou731mHvtRn1h8cNd6gd6JCXI1S+DBy1aFXuDVGXuVofon3ByYw1vN3Bk6 4VWQ== 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=y7FSocOkMHVg4UK5VR546jFApa/3IjN0xth3/ynVktM=; b=jGMxNDALjWPUa8wtlq7MuArQ5cKaOmpkyG5hBH2CmUod0VwbEPqrggP9E68apx2I2h rz7p1T1pAfcXCrRGCz23NBUOesTNRWUyoiMOx/xopp8NAAvs4FwEdP+BH1SSLqv1ke+A XOZR2PwUZf0yGYffbQRD2N6HBQgUI/6GSly6WenMVqRS7Zk8/lhpMp3mh/S0/xBbupUK o7qXah2qijeV0kEs07JRDKrGuHlSFg70QcckCsIDlOz+JTDXiu+udAMU0V9RTVrVUu8N /ParORkxAZidlMSzoooIsv2N/ABoG1FtHljI+6wK52VjvChokRXLK5StjneMzeckyZLi i4Pw== X-Gm-Message-State: APjAAAU5xC1yJzVzf7Kj0ICtpbHNp7NCCoxB6GTDJ7LLQpBGBxdmM8U1 KbRz4+KeRh0nbnKwA+MFrbU= X-Google-Smtp-Source: APXvYqwoP6+7MVErkrozIlhhfQI80VYrXQFzbRs5mXb36qIYCgdvoKdO5FGFpnuKl9jU4BUpgV44yw== X-Received: by 2002:a17:902:1003:: with SMTP id b3mr39875866pla.172.1563324389858; Tue, 16 Jul 2019 17:46:29 -0700 (PDT) Received: from localhost ([116.247.112.152]) by smtp.gmail.com with ESMTPSA id e5sm26290303pfd.56.2019.07.16.17.46.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 16 Jul 2019 17:46:29 -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: Wed, 17 Jul 2019 08:46:06 +0800 Message-Id: <20190717004606.12444-2-xieyongji@baidu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190717004606.12444-1-xieyongji@baidu.com> References: <20190717004606.12444-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::641 Subject: [Qemu-devel] [PATCH v2 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 | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c index a9fd8ea305..17826ef8e2 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,23 @@ 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: + err = NULL; + virtio_scsi_common_unrealize(dev, &err); + error_propagate(errp, err); } static void vhost_user_scsi_unrealize(DeviceState *dev, Error **errp)