Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp587091ybz; Wed, 15 Apr 2020 14:36:36 -0700 (PDT) X-Google-Smtp-Source: APiQypIogCYNdMGsncSnJklqS30JRDJJjqLhoBIb3lSdG/t2luydTz9nm9nHHgesO+yBj8Ojg9IK X-Received: by 2002:a17:906:2922:: with SMTP id v2mr1299918ejd.11.1586986596087; Wed, 15 Apr 2020 14:36:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586986596; cv=none; d=google.com; s=arc-20160816; b=sIxudIBkpPLZhTH3owNhM1KQ8A7sj9PK0iLYb4Zoxl3Z5DdOTb6nI2W/H3HIHqUQS0 lCajCj0RqoU14RZc50t2xtj05ByXUfhCmke9GdLMZNM7WQJDzGDbAUxbqVncbCfHxmIp A5Ta1fiWgRGU/YWxePI9P5Woyi2OfjwlOwAeLgt3xN3hJ0WBu10pdFDzbU98NXZG3HOV dzn3xV4KjncWlLL7OGSmxdkJICHZueLTxEGuO4SxsDmNIEryKJTxvL0WFfc6RwIfXZWp ws4CgWhTsbi+pxZ1N71iAXzU6T3LH+7qymYiorySCNFhRSbLrM21HdQTm2VzNNPNWay2 CYTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=vfJq/s7Fitvz4gOUIgPTj+7knKnIZ42QN86Vh2tWHQc=; b=fQTPynoFTUGs+thURUMYuiKdtgNUZuKE8nYuQtc/Kdc9GvWdzFcO4lN6YOmMKDxJ0i Dh5r3ixjKGFn++9v58TtT9opKe3n3epl4tKyzupnrL3rAay2wZ4jhPM20VnShPspfCSS 70cKUP4kNpi4Hut8JacPNcjYEsNQuDTRVss/MnOyG2ihiWxLtKhvS5ox27bmOS91vTvr ShG+aB+GPFMjGJb9oGByPzId7OY+yjyH8S/HTn1IF8SR72t11b0JwszrnUlX2scfafd+ Ozi11ElPu2bzEefgXsrKI6uKeI/bo5zi/g6Tj8bKd+Pd2FrajkkOSBCKgXyM+KrJLZ8y R/Uw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id df23si5193068edb.556.2020.04.15.14.36.13; Wed, 15 Apr 2020 14:36:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731619AbgDNNZg (ORCPT + 99 others); Tue, 14 Apr 2020 09:25:36 -0400 Received: from 8bytes.org ([81.169.241.247]:35058 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2502885AbgDNNQC (ORCPT ); Tue, 14 Apr 2020 09:16:02 -0400 Received: by theia.8bytes.org (Postfix, from userid 1000) id 31ED54F2; Tue, 14 Apr 2020 15:15:53 +0200 (CEST) From: Joerg Roedel To: Joerg Roedel , Will Deacon , Robin Murphy , Marek Szyprowski , Kukjin Kim , Krzysztof Kozlowski , David Woodhouse , Lu Baolu , Andy Gross , Bjorn Andersson , Matthias Brugger , Rob Clark , Heiko Stuebner , Gerald Schaefer , Thierry Reding , Jonathan Hunter , Jean-Philippe Brucker Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-tegra@vger.kernel.org, virtualization@lists.linux-foundation.org, Joerg Roedel Subject: [PATCH v2 10/33] iommu: Move new probe_device path to separate function Date: Tue, 14 Apr 2020 15:15:19 +0200 Message-Id: <20200414131542.25608-11-joro@8bytes.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200414131542.25608-1-joro@8bytes.org> References: <20200414131542.25608-1-joro@8bytes.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel This makes it easier to remove to old code-path when all drivers are converted. As a side effect that it also fixes the error cleanup path. Signed-off-by: Joerg Roedel --- drivers/iommu/iommu.c | 69 ++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 23 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 18eb3623bd00..8be047a4808f 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -218,12 +218,55 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list return ret; } +static int __iommu_probe_device_helper(struct device *dev) +{ + const struct iommu_ops *ops = dev->bus->iommu_ops; + struct iommu_group *group; + int ret; + + ret = __iommu_probe_device(dev, NULL); + if (ret) + goto err_out; + + /* + * Try to allocate a default domain - needs support from the + * IOMMU driver. There are still some drivers which don't + * support default domains, so the return value is not yet + * checked. + */ + iommu_alloc_default_domain(dev); + + group = iommu_group_get(dev); + if (!group) + goto err_release; + + if (group->default_domain) + ret = __iommu_attach_device(group->default_domain, dev); + + iommu_group_put(group); + + if (ret) + goto err_release; + + if (ops->probe_finalize) + ops->probe_finalize(dev); + + return 0; + +err_release: + iommu_release_device(dev); +err_out: + return ret; + +} + int iommu_probe_device(struct device *dev) { const struct iommu_ops *ops = dev->bus->iommu_ops; int ret; WARN_ON(dev->iommu_group); + if (!ops) return -EINVAL; @@ -235,30 +278,10 @@ int iommu_probe_device(struct device *dev) goto err_free_dev_param; } - if (ops->probe_device) { - struct iommu_group *group; - - ret = __iommu_probe_device(dev, NULL); - - /* - * Try to allocate a default domain - needs support from the - * IOMMU driver. There are still some drivers which don't - * support default domains, so the return value is not yet - * checked. - */ - if (!ret) - iommu_alloc_default_domain(dev); - - group = iommu_group_get(dev); - if (group && group->default_domain) { - ret = __iommu_attach_device(group->default_domain, dev); - iommu_group_put(group); - } - - } else { - ret = ops->add_device(dev); - } + if (ops->probe_device) + return __iommu_probe_device_helper(dev); + ret = ops->add_device(dev); if (ret) goto err_module_put; -- 2.17.1