Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp868247ybv; Wed, 19 Feb 2020 10:55:33 -0800 (PST) X-Google-Smtp-Source: APXvYqwAOe2jUHuZe7NRXmroLU0Pm2U/lvcQd03yOikg5sYHi1cXJ+tQ4SD/YVSSV+IS5+/87zrz X-Received: by 2002:a9d:67c9:: with SMTP id c9mr21692497otn.144.1582138533256; Wed, 19 Feb 2020 10:55:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582138533; cv=none; d=google.com; s=arc-20160816; b=YSdaO6oaW+P8ezW6zAT7vHGEwQJeqWp6cdVa94sQQiNqTzstOa0Q6aCaZ0cbxeY1Yb OSwLAdVSurEIFcXJ+aTh4lZPtFl4oirTQSlh35TSQCA4CMak0/FPcJUFwWB+0duhy0wV jONTcIUAgqS8dp004tFbF+grABv+fZjxIGlN9QAQO32Mr98TkfFDM3NII1KAHrm9p9ee NYsLVN9n8cbBRNaoVre3BTb9yHrbzqttU8NDxl8anPzpEPBh3pFuy49kxnzsdCBHMjrA qklyIv0qx/cCsI4dLN2uYAheiXGmZiZYNgdu3jgDOTgA/pC6PpULKJTFzgi86DcT19HA Le1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:dkim-signature; bh=oOG1xcfx/XK/BX/8Fvn0t0Ub7ouo5ivEiSJ+HCOiGlw=; b=sRZR6+83hFOZSYmYx+M313E+cCCi+ML6l2jc/lAriMPDnjTI1C+e8bjcQmjg3/rqDe l6JqWH2CKCw4MT9FOVfCKl7aqLuxJJYyhIJM5AX7gRri18roG6qcWR4LrzIHcB60ZAJD 5wu8PAeNjKTr+VlOgfw6H4uMAvuS26BMK/fTrJdXECEX8CwBlDmmHdYDXQUcDdTo8dZq Gt5A03aEot0z0tEGT/gFTEtyP2EK0eXfyp0nwrr7kqw6GbvWBZ3PsXjlxXcOLOXgKavb PvQp7mhR54+TPqtIWM6Ax38s6cqQH5/vQqOrwlxAjhJZaqRl3qOJlZOLnvZhBeQff1MC UUPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LnC+7vRt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j25si9788981oij.242.2020.02.19.10.55.21; Wed, 19 Feb 2020 10:55:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LnC+7vRt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727132AbgBSSyy (ORCPT + 99 others); Wed, 19 Feb 2020 13:54:54 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:47658 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726773AbgBSSyy (ORCPT ); Wed, 19 Feb 2020 13:54:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582138493; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oOG1xcfx/XK/BX/8Fvn0t0Ub7ouo5ivEiSJ+HCOiGlw=; b=LnC+7vRtlcMObsBxcS1nv+sGGWelxraaUuDd2U5EzNwD57GF3BmWqVd6ZlKfjQPYsXLWlW G78thYe0X1scgqntnsfbYnHeaxtiBHfkOKEEAHnGEcW0aFTG9KQ29Cwpdg/PKA16UW7TlA 69n9hglIdMuLK4TOnwFWyLrc3F9Gb2o= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-107-JTzWQq42OsiK8L_9c_iN8g-1; Wed, 19 Feb 2020 13:54:49 -0500 X-MC-Unique: JTzWQq42OsiK8L_9c_iN8g-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 447DD1800D42; Wed, 19 Feb 2020 18:54:48 +0000 (UTC) Received: from gimli.home (ovpn-116-28.phx2.redhat.com [10.3.116.28]) by smtp.corp.redhat.com (Postfix) with ESMTP id 284F060BE1; Wed, 19 Feb 2020 18:54:45 +0000 (UTC) Subject: [PATCH v2 7/7] vfio/pci: Cleanup .probe() exit paths From: Alex Williamson To: kvm@vger.kernel.org Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, dev@dpdk.org, mtosatti@redhat.com, thomas@monjalon.net, bluca@debian.org, jerinjacobk@gmail.com, bruce.richardson@intel.com, cohuck@redhat.com Date: Wed, 19 Feb 2020 11:54:44 -0700 Message-ID: <158213848474.17090.18286195387831295821.stgit@gimli.home> In-Reply-To: <158213716959.17090.8399427017403507114.stgit@gimli.home> References: <158213716959.17090.8399427017403507114.stgit@gimli.home> User-Agent: StGit/0.19-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The cleanup is getting a tad long. Signed-off-by: Alex Williamson --- drivers/vfio/pci/vfio_pci.c | 54 ++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index 497ecadef2ba..7d410224343a 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -1591,8 +1591,8 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) vdev = kzalloc(sizeof(*vdev), GFP_KERNEL); if (!vdev) { - vfio_iommu_group_put(group, &pdev->dev); - return -ENOMEM; + ret = -ENOMEM; + goto out_group_put; } vdev->pdev = pdev; @@ -1603,43 +1603,27 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) INIT_LIST_HEAD(&vdev->ioeventfds_list); ret = vfio_add_group_dev(&pdev->dev, &vfio_pci_ops, vdev); - if (ret) { - vfio_iommu_group_put(group, &pdev->dev); - kfree(vdev); - return ret; - } + if (ret) + goto out_free; ret = vfio_pci_reflck_attach(vdev); - if (ret) { - vfio_del_group_dev(&pdev->dev); - vfio_iommu_group_put(group, &pdev->dev); - kfree(vdev); - return ret; - } + if (ret) + goto out_del_group_dev; if (pdev->is_physfn) { vdev->vf_token = kzalloc(sizeof(*vdev->vf_token), GFP_KERNEL); if (!vdev->vf_token) { - vfio_pci_reflck_put(vdev->reflck); - vfio_del_group_dev(&pdev->dev); - vfio_iommu_group_put(group, &pdev->dev); - kfree(vdev); - return -ENOMEM; - } - - vdev->nb.notifier_call = vfio_pci_bus_notifier; - ret = bus_register_notifier(&pci_bus_type, &vdev->nb); - if (ret) { - kfree(vdev->vf_token); - vfio_pci_reflck_put(vdev->reflck); - vfio_del_group_dev(&pdev->dev); - vfio_iommu_group_put(group, &pdev->dev); - kfree(vdev); - return ret; + ret = -ENOMEM; + goto out_reflck; } mutex_init(&vdev->vf_token->lock); uuid_gen(&vdev->vf_token->uuid); + + vdev->nb.notifier_call = vfio_pci_bus_notifier; + ret = bus_register_notifier(&pci_bus_type, &vdev->nb); + if (ret) + goto out_vf_token; } if (vfio_pci_is_vga(pdev)) { @@ -1665,6 +1649,18 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) } return ret; + +out_vf_token: + kfree(vdev->vf_token); +out_reflck: + vfio_pci_reflck_put(vdev->reflck); +out_del_group_dev: + vfio_del_group_dev(&pdev->dev); +out_free: + kfree(vdev); +out_group_put: + vfio_iommu_group_put(group, &pdev->dev); + return ret; } static void vfio_pci_remove(struct pci_dev *pdev)