From patchwork Tue May 26 13:01:32 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: 1298042 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 49WZ1c1lvvz9sSt; Tue, 26 May 2020 23:04:51 +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 1jdZGA-0006uu-2O; Tue, 26 May 2020 13:04:46 +0000 Received: from mail-pg1-f194.google.com ([209.85.215.194]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jdZEo-0005tj-RG for kernel-team@lists.ubuntu.com; Tue, 26 May 2020 13:03:22 +0000 Received: by mail-pg1-f194.google.com with SMTP id p21so10037474pgm.13 for ; Tue, 26 May 2020 06:03:22 -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=LTUy0Qoj+MWLQhTcDm0Gcr+OFwTbArgivsmbjpgS3kc=; b=sHYjVDIi9jPlyl55W6F7EHNLsYCgHVVTq9yDoN3Eo3Rt5jNAoUi4yCTqdi+lL1P9BQ 0yW36towidsxZI8ZC/x3jBE0beR6oG4dZVllqLqzCGa3pna1rd7igHEhBJ9b80hYN41B gXa9iP4BgofsyWiEZWw5CP9JeSU1XtuNcJVal17c6miBT5BacVFTKRTVrt9Fd0AKxL9P LmP0xRRv9BOdMKwvZHEvhtacI7J48w3dI0FqIiNltHEzG1wsYY3qhM06y5yPZ0L6BIAB WByI6iVKQ8DnL8DvMQ5VuHoLVf8OGCjMi8P2hN0J0k3+sWP9LRPVr8QJ/pCwx1K8B5Pb nsPg== X-Gm-Message-State: AOAM533H4YkeXDs6VOoxzltnDjYkgCjwCEjZtD9LFhzCv2D0vZlxHepB I72YAH1+dYH0hlOk/tcD/y6s+G+yObc= X-Google-Smtp-Source: ABdhPJxNlrhzMnkkwu4GRsequ9enrBXBtYp9g6w+wryGnNW0d+w8vTK8Xvg4KiTAG45pyYvLgi0gFQ== X-Received: by 2002:aa7:9431:: with SMTP id y17mr21030918pfo.33.1590498199641; Tue, 26 May 2020 06:03:19 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id 128sm15080448pfd.114.2020.05.26.06.03.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2020 06:03:18 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH 28/60][SRU][OEM-5.6] UBUNTU: SAUCE: iommu: Move new probe_device path to separate function Date: Tue, 26 May 2020 21:01:32 +0800 Message-Id: <20200526130204.238445-29-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200526130204.238445-1-vicamo.yang@canonical.com> References: <20200526130204.238445-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 iommu/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 c9b0b7e15cf4..83aa20784c65 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;