From nobody Sat May 18 18:27:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563356880; cv=none; d=zoho.com; s=zohoarc; b=SyZQaYEZiDG9FjSttUYx9d5HowaTCAPAccTcvchohpeCu779MegyQL3WiwZ/Fy6M0BhnoaM/fxP4Sk8DrdGCxWy6XqRRCkk+AAQHciCl/YkjtDOHIzFV3XN9IrlR6eFv6RRRLM9LrL5UDatY85c/4tRpanzFF9FDfPsGIUh9KNo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563356880; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=NjI+HmyxGNKghok4nOlp66yM1BjstXg68u+D7oUdNEc=; b=gx6uI97HqS7CaulS4Ly8NALZpmea5PUxZJhsKXFBqaR241O+XuQDTtZ43NP82KsOTtfurXOwFmki/tSKgT3twibKEyTNOAB61hbrDx+dyiFQk7wjzPLjDoW1cus6cXEV/YyEjBHgPNbnhKeYI/t3nw3v4KeljkWDfbeHKackLL4= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1563356880884275.92062313561803; Wed, 17 Jul 2019 02:48:00 -0700 (PDT) Received: from localhost ([::1]:55456 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hngXX-00073H-S1 for importer@patchew.org; Wed, 17 Jul 2019 05:47:59 -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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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, Err= or **errp) } =20 if (!vhost_user_init(&s->vhost_user, &vs->conf.chardev, errp)) { - return; + goto free_virtio; } =20 vsc->dev.nvqs =3D 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; } =20 /* Channel and lun both are 0 for bootable vhost-user-scsi disk */ vsc->channel =3D 0; vsc->lun =3D 0; vsc->target =3D vs->conf.boot_tpgt; + + return; + +free_vhost: + vhost_user_cleanup(&s->vhost_user); + g_free(vqs); +free_virtio: + err =3D NULL; + virtio_scsi_common_unrealize(dev, &err); + error_propagate(errp, err); } =20 static void vhost_user_scsi_unrealize(DeviceState *dev, Error **errp) --=20 2.21.0