From patchwork Tue Jun 2 07:48:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: You-Sheng Yang X-Patchwork-Id: 1302204 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49bkhK15hrz9sSn; Tue, 2 Jun 2020 17:49:21 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1jg1fh-0005Kx-Lx; Tue, 02 Jun 2020 07:49:17 +0000 Received: from mail-pj1-f65.google.com ([209.85.216.65]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1fe-0005Hb-SO for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:49:15 +0000 Received: by mail-pj1-f65.google.com with SMTP id d6so1056000pjs.3 for ; Tue, 02 Jun 2020 00:49:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZDdYH4EU19FWka6N/vAt/zgFFsdpvA7xc3kS5TDgO0I=; b=Yg8+6PnweHvav+u2Io+tI+aZxaOjChEnHNHOAVvqwSHZkr3WJQo8H/T6aXFRoDQUd7 bTrxB7hJSFNbnYordvTyhueM287c2iVYmXw8wpnwxD16tBkuYOo8+nEJAWib7bJ7Nab9 lBzztdgOIKgBmAzUl/OUfHRJlCRSEWrlVq1Yp2bJt/QZy3sgiOhHSb9xyjZJlUIyUDbG 00qaHWjvrg2Yt9rqTVg12cU4CveXJtsRyzLdf9wKDRXoW78tbju95zwdhw5xrjxu9R4K 66EZcITrhzlRkXGS3uRHA6Lc/gI28K7gOpriiyxQ/2zFppKTCSD5ntsvoYX0OBxjVUHb 893A== X-Gm-Message-State: AOAM530m3QTyPChxSp/b36ZpRM6zX5belcoviHDWXrnMgFTybL/cqx1v xYAlpjehC7fuPwa34d6Mhfom9LDkpL8= X-Google-Smtp-Source: ABdhPJwuLpgLjPC6YXTdAu4hOgeoOfB6k9v7e2pGxvhu9Yn845cMZuDGbiYYdzTkUQ0PtRSe1ZHU1w== X-Received: by 2002:a17:902:e788:: with SMTP id cp8mr10458007plb.34.1591084152330; Tue, 02 Jun 2020 00:49:12 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id y10sm1617307pfq.34.2020.06.02.00.49.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:49:11 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 10/42][SRU][U] iommu: Move new probe_device path to separate function Date: Tue, 2 Jun 2020 15:48:11 +0800 Message-Id: <20200602074843.1743493-11-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200602074843.1743493-1-vicamo.yang@canonical.com> References: <20200602074843.1743493-1-vicamo.yang@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Joerg Roedel BugLink: https://bugs.launchpad.net/bugs/1876707 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 Tested-by: Marek Szyprowski Acked-by: Marek Szyprowski Link: https://lore.kernel.org/r/20200429133712.31431-11-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit cf193888bfbd3d57e03a511e49d26f7d9c6f76df linux-next) Signed-off-by: You-Sheng Yang --- 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 87706d225dba..428ba12c338c 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -219,12 +219,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; @@ -236,30 +279,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;