From patchwork Wed Jul 17 09:47:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 11047579 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 867A9912 for ; Wed, 17 Jul 2019 09:47:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7435B28715 for ; Wed, 17 Jul 2019 09:47:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 689BA28720; Wed, 17 Jul 2019 09:47:57 +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_INVALID, DKIM_SIGNED,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 1559828715 for ; Wed, 17 Jul 2019 09:47:57 +0000 (UTC) Received: from localhost ([::1]:55456 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hngXU-00073H-50 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 17 Jul 2019 05:47:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42211) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hngXD-00063H-OL for qemu-devel@nongnu.org; Wed, 17 Jul 2019 05:47:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hngXC-0004Tl-Nb for qemu-devel@nongnu.org; Wed, 17 Jul 2019 05:47:39 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]:45495) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hngXC-0004TU-HM for qemu-devel@nongnu.org; Wed, 17 Jul 2019 05:47:38 -0400 Received: by mail-wr1-x430.google.com with SMTP id f9so24015978wre.12 for ; Wed, 17 Jul 2019 02:47:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=NjI+HmyxGNKghok4nOlp66yM1BjstXg68u+D7oUdNEc=; b=TESzvAxJEltSse3Qs1grm+2ivvCGvT5m8QSEsHFCKtBDRl3veA70lPTI7NsDG5Wjjg +7yRXZZgOPgG4UgD+TR+C6+Zz9oyZVALoaQxM8rSdM6fsBbTWNarCKkjxNkXjhMJflZ8 4nl5pL9yWOt/oR5isHurGWBN//4WKm9yat3ZsJdeSEXDEvZfcKFZvvZL/jTNXsHwhTAV Y+ertceD7rtG+o/qB/C8/OXYZ1tgL/o3kh/jIWMLlTZzbE2qB0UezHJoG7ikjNMR29EP koSxw+BLGmpNT/Xs5T3b2FhWlHPbf5UPTaNuJ8KSYTBkigdH2jNXpTv2yRCG5p4KR9N1 l9pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=NjI+HmyxGNKghok4nOlp66yM1BjstXg68u+D7oUdNEc=; b=neVIOAEsxxyfynkfytUxHe1vLVvB8KAwdOlLTNcK6rkKXLBal2DhnnXjSNHXImkhDa wkwS0z5LaxLcaddZav5kuqZkTIAxv9KKtb+mZNPwLMzBNBm7gjHd/B2+/n30B+uSHYc+ aaRDhwE08bqXT5qz8eWldXDuCRQ/7DwznqB0QEkSMSoCkbaECq7P5zMF0YahYVV5LgAM W+2AhkERzIFQXlt2wlx+4baiZ9TjxA8HKpvpNTi7k+uE8dbbXp15PXuevTACjBvaE5wz LZkmqJaTZbWeTu8MBzTprytZsyyZBiy/9nRRgIKwwuASyjpiJthGl9OZaXc2OUIHzBT+ Szdg== X-Gm-Message-State: APjAAAXOk6C6ORtHESDdFtd7U7/ilYhIxYd7JZRSB9MBbp+MzHKVWqtp eJrgbIc9w6sTtIIkJF3esG6I9M9wJVs= X-Google-Smtp-Source: APXvYqxrfniimrHvc8NUjiOLAb2h3gZNJG6RmqQuAcRpEoU9MvnJ8BtjuFgobiDQUpeKLLX1qr8l+Q== X-Received: by 2002:adf:deca:: with SMTP id i10mr30730025wrn.313.1563356857248; Wed, 17 Jul 2019 02:47:37 -0700 (PDT) Received: from donizetti.lan ([2001:b07:6468:f312:e427:3beb:1110:dda2]) by smtp.gmail.com with ESMTPSA id y12sm2037249wru.30.2019.07.17.02.47.36 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 17 Jul 2019 02:47:36 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 17 Jul 2019 11:47:35 +0200 Message-Id: <20190717094735.31151-1-pbonzini@redhat.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::430 Subject: [Qemu-devel] [PATCH] 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 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 Message-Id: <20190717004606.12444-2-xieyongji@baidu.com> Signed-off-by: Paolo Bonzini --- 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 a0b69fbc0f..665939df19 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)