From patchwork Tue May 26 13:01:55 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: 1298064 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 49WZ2m34kgz9sTS; Tue, 26 May 2020 23:05:52 +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 1jdZH9-0007r0-3o; Tue, 26 May 2020 13:05:47 +0000 Received: from mail-pl1-f196.google.com ([209.85.214.196]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jdZFl-0006dB-Vl for kernel-team@lists.ubuntu.com; Tue, 26 May 2020 13:04:22 +0000 Received: by mail-pl1-f196.google.com with SMTP id x11so7673861plv.9 for ; Tue, 26 May 2020 06:04:21 -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=v1liNrs/QuyDiuFoA+mle3mgXYr9buucNzLNE6lq9og=; b=GAqpBV7hbTYcK1O0YHy7Nn3fUWfY59WFWeWjZMItE1GDNaa8qkKcIbvBVszwIW/aCa UxzR5iji7WX27C7AbQUUJvAwQZ1hqWqfkBifPcb1T1tuF8kcakX0Xad0p+D9IVw50e8S 3c3Aui+EcGbpQ1gzNdnzIBeLBDUxRwXikn5fsTdyQf7zOpuD+yzB36gvWpHjXv759JQM 1z34/fsqyQLVAehkv/e1yuNL+Heqjl+PzekP9ZHXETrJvgaCEw+TWdP5S9P6/zCSRe+S lOl6hSWTmIQA/1f7IpVDr87gRit8uQCZcmyzKYOl3S+ifQalYnuzPLsSGi7QkQUFypWu lO4w== X-Gm-Message-State: AOAM530Gg5PUTS2MuHtQzkBP0Kak+LK6iTtLwtrQfJ6VqA1a5MnUATHl gqZeJ2wBlQanDJ0flWRLBONjbOn/ZWg= X-Google-Smtp-Source: ABdhPJyDzXL4gQQ50JgN4VqUk0t7pQ73d3OiF4PKvW18IpmVgN1XcyxPdXHg98X92BADmc7rtRkHrA== X-Received: by 2002:a17:90a:9904:: with SMTP id b4mr13623207pjp.207.1590498258871; Tue, 26 May 2020 06:04:18 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id t25sm14002322pgo.7.2020.05.26.06.04.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2020 06:04:16 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH 51/60][SRU][OEM-5.6] UBUNTU: SAUCE: iommu: Move more initialization to __iommu_probe_device() Date: Tue, 26 May 2020 21:01:55 +0800 Message-Id: <20200526130204.238445-52-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 Move the calls to dev_iommu_get() and try_module_get() into __iommu_probe_device(), so that the callers don't have to do it on their own. Signed-off-by: Joerg Roedel Tested-by: Marek Szyprowski Acked-by: Marek Szyprowski Link: https://lore.kernel.org/r/20200429133712.31431-34-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit 4e8906f0d84d1a7d3cf82a30a701b0fb5d48977c iommu/next) Signed-off-by: You-Sheng Yang --- drivers/iommu/iommu.c | 47 +++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index d1931f27dc6b..7f6c0cc4b294 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -195,9 +195,19 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list struct iommu_group *group; int ret; + if (!dev_iommu_get(dev)) + return -ENOMEM; + + if (!try_module_get(ops->owner)) { + ret = -EINVAL; + goto err_free; + } + iommu_dev = ops->probe_device(dev); - if (IS_ERR(iommu_dev)) - return PTR_ERR(iommu_dev); + if (IS_ERR(iommu_dev)) { + ret = PTR_ERR(iommu_dev); + goto out_module_put; + } dev->iommu->iommu_dev = iommu_dev; @@ -218,6 +228,12 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list out_release: ops->release_device(dev); +out_module_put: + module_put(ops->owner); + +err_free: + dev_iommu_free(dev); + return ret; } @@ -227,14 +243,6 @@ int iommu_probe_device(struct device *dev) struct iommu_group *group; int ret; - if (!dev_iommu_get(dev)) - return -ENOMEM; - - if (!try_module_get(ops->owner)) { - ret = -EINVAL; - goto err_out; - } - ret = __iommu_probe_device(dev, NULL); if (ret) goto err_out; @@ -1533,14 +1541,10 @@ struct iommu_domain *iommu_group_default_domain(struct iommu_group *group) static int probe_iommu_group(struct device *dev, void *data) { - const struct iommu_ops *ops = dev->bus->iommu_ops; struct list_head *group_list = data; struct iommu_group *group; int ret; - if (!dev_iommu_get(dev)) - return -ENOMEM; - /* Device is probed already if in a group */ group = iommu_group_get(dev); if (group) { @@ -1548,22 +1552,7 @@ static int probe_iommu_group(struct device *dev, void *data) return 0; } - if (!try_module_get(ops->owner)) { - ret = -EINVAL; - goto err_free_dev_iommu; - } - ret = __iommu_probe_device(dev, group_list); - if (ret) - goto err_module_put; - - return 0; - -err_module_put: - module_put(ops->owner); -err_free_dev_iommu: - dev_iommu_free(dev); - if (ret == -ENODEV) ret = 0;