From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C63D2C5DF60 for ; Fri, 8 Nov 2019 15:16:39 +0000 (UTC) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 996CF214DB for ; Fri, 8 Nov 2019 15:16:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="XVpaEGWA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 996CF214DB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=iommu-bounces@lists.linux-foundation.org Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 92BE9DD1; Fri, 8 Nov 2019 15:16:29 +0000 (UTC) Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id ABABADC6 for ; Fri, 8 Nov 2019 15:16:28 +0000 (UTC) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 6AE95196 for ; Fri, 8 Nov 2019 15:16:28 +0000 (UTC) Received: from localhost.localdomain (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3909D222CD; Fri, 8 Nov 2019 15:16:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573226188; bh=uFaLAgrpPHuI/YFOn88Rm5/aUifByC237X9HFHz9J+g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XVpaEGWAXqD3t+ULRKRNz9570P3bYyFcit4fo3e3wFUaZPPR2/fEKHUt6BsjlDBZf c/yNFGphJAh8A+ngL4/OBoeBMvm0qbiVeGbCLZFGGzQiI1AH53yJs9osHFzyJJ/UvQ jaHjKvMV2I2w7VnigaZ/ojohJtymu3Qdypqg7lkg= From: Will Deacon To: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/9] iommu/of: Take a ref to the IOMMU driver during ->of_xlate() Date: Fri, 8 Nov 2019 15:16:04 +0000 Message-Id: <20191108151608.20932-6-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191108151608.20932-1-will@kernel.org> References: <20191108151608.20932-1-will@kernel.org> MIME-Version: 1.0 Cc: "Isaac J. Manjarres" , Jean-Philippe Brucker , Saravana Kannan , Robin Murphy , Bjorn Helgaas , Will Deacon X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: iommu-bounces@lists.linux-foundation.org Errors-To: iommu-bounces@lists.linux-foundation.org Ensure that we hold a reference to the IOMMU driver module while calling the '->of_xlate()' callback during early device probing. Signed-off-by: Will Deacon --- drivers/iommu/of_iommu.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c index 78faa9f73a91..25491403a0bd 100644 --- a/drivers/iommu/of_iommu.c +++ b/drivers/iommu/of_iommu.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -89,16 +90,16 @@ static int of_iommu_xlate(struct device *dev, { const struct iommu_ops *ops; struct fwnode_handle *fwnode = &iommu_spec->np->fwnode; - int err; + int ret; ops = iommu_ops_from_fwnode(fwnode); if ((ops && !ops->of_xlate) || !of_device_is_available(iommu_spec->np)) return NO_IOMMU; - err = iommu_fwspec_init(dev, &iommu_spec->np->fwnode, ops); - if (err) - return err; + ret = iommu_fwspec_init(dev, &iommu_spec->np->fwnode, ops); + if (ret) + return ret; /* * The otherwise-empty fwspec handily serves to indicate the specific * IOMMU device we're waiting for, which will be useful if we ever get @@ -107,7 +108,12 @@ static int of_iommu_xlate(struct device *dev, if (!ops) return driver_deferred_probe_check_state(dev); - return ops->of_xlate(dev, iommu_spec); + if (!try_module_get(ops->owner)) + return -ENODEV; + + ret = ops->of_xlate(dev, iommu_spec); + module_put(ops->owner); + return ret; } struct of_pci_iommu_alias_info { -- 2.24.0.rc1.363.gb1bccd3e3d-goog _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu