Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3557930pxk; Mon, 28 Sep 2020 23:20:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXYPHEiCYzrX3CezV4hxaa9vjNOgI8ALmLELU3JOivHtYgu25eiDlh6+69E23rO1Pfk9yV X-Received: by 2002:a17:906:858a:: with SMTP id v10mr2324761ejx.61.1601360426113; Mon, 28 Sep 2020 23:20:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601360426; cv=none; d=google.com; s=arc-20160816; b=0a6caevI3K0UB0YEXjpItiy3rQ5+nmt6KyA7UZiEiky1eflyDQlXAOf05nKTGHqLPe 6Wg64L/9QmoKWJ4j1TPnAFzqVgTWY1tMTDCd/q9KJ1tnSkdcCUmQ4UXtkEwx2J13x+X3 WOkCI6AHgP7uw/NXL6Wb20Gq2VDikHjemcUSUYlzS2cP6xHEvz7n80/qUs1zMe/K2hJ5 5bhS/6vcTWB2IkL7cS4qZeLntEgDdnTC6jWKkCDQEVDXj4FoH+zZ7rWZIPK7Bv8FsaD7 JkC6/nxL6wG5W/AZ2e5b1QodfKkzy1E13+l8YWrQ4lDJI/Wwew5qpxyh7PvKsJYTM+KU VWBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=7/FgS/Bu4Sm/fvo7Kw9FiL37U/scbZL5l1h7O/ec2LY=; b=oyOoeJcdpR+R+2kvT4V2Xb+HQ2CCeKW5HhHW82K3yMgrM2elr1Dh3P7hIhsQbUhoW7 TbSdk6VSSy03+krUCj1KRVT4tyjTtxM0qZ+ybYZSEDT5lxT9P/T5LPsAaVi0ws7Dgmg5 YqK36kt5OI1TjB70K3Fnbi1N13rOQ0DvZxoRvi4ikEKg6cyZu46nQ6DQNK3KRyiN4yhE brB+52eg06pyeouM3jrL6zj38K+4G3WjzcKWYYR4FTY2vZlw8P5+jyhJy4gmJ9BFZ/0y vMw/eXSzDHp0CO4grcFy1ha8j0nJtTAqOccx/7H07UijzecBLTVWiPYIw/KaL0KAFyWY +ffg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=u5d9C8QP; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j3si2048222ejb.156.2020.09.28.23.20.03; Mon, 28 Sep 2020 23:20:26 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=u5d9C8QP; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725601AbgI2GS4 (ORCPT + 99 others); Tue, 29 Sep 2020 02:18:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725320AbgI2GS4 (ORCPT ); Tue, 29 Sep 2020 02:18:56 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC0FDC0613D0; Mon, 28 Sep 2020 23:18:55 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id d13so3011520pgl.6; Mon, 28 Sep 2020 23:18:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7/FgS/Bu4Sm/fvo7Kw9FiL37U/scbZL5l1h7O/ec2LY=; b=u5d9C8QP7pX6TR4cjb2BXigfMhHFBN/IE37xTN/FotpT2LDHCf7xdI/v5ncgR/Qio7 ijuWo0LqrkynH1CZLhUvG8MLopNAWs4rIXBluF84oqMpicliVKqQw6fjNseSjlOhruwM yvIntkub8J8LKMMVQq0f4pl6iQx5tinvDvq5y7HdXBmrvnNqIyFCCn2TvEg/Ig+ua7Q3 KOwBSlB/seahfVqeo0NbYgaXTovchyVFTiR5PEhQt4dSfFS2sxxv57VH5YNYWJoYDq0u ESe4wN3RxKxFgWBsNakhLy4jnUaP2hO/kBx3VUI05XCXIUBQIBVxFy/TeU2Hjrnpiu4A /4Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7/FgS/Bu4Sm/fvo7Kw9FiL37U/scbZL5l1h7O/ec2LY=; b=m5pMxGMmK4DDqywuHDUrNskmOCPSIX6GVEyvWq71dlVW/3vjbD/rDbQ42egj3Ml2fN +YAayexs8PPq/hDWHvwKoN34inQU+GmyQiGat5W2l0sGdVCCZcb4n02wMsQJqnqfLOYq DHNXVKadvjpX+Dr7AnsG54LcPcLqtMlp2iAek5znc2apezCgmuwX+vC6HjSeQAFxuop2 S0IQS0SM6BFuxw2Cy8WMKKZYVaEK8ZW2oJxDddm6U3yQgtFKEAuNYijlr5RwuBaxOjQR bHbLBiw04ZeCfayBazocoaVHonfpUY2HZ57p4VvFjiCYl9IFTj+SxJB8muXod7ZNarT8 IjXg== X-Gm-Message-State: AOAM532Dguf3Q9mkSfxPL1rvCb4oMcAD/yJ94wnYNJV5pcHV5xfbgkGV nCItuIPdqiHmhVX58K+jXNs= X-Received: by 2002:a63:f70e:: with SMTP id x14mr2039284pgh.407.1601360335436; Mon, 28 Sep 2020 23:18:55 -0700 (PDT) Received: from Asurada-Nvidia.nvidia.com (thunderhill.nvidia.com. [216.228.112.22]) by smtp.gmail.com with ESMTPSA id cf7sm3280562pjb.52.2020.09.28.23.18.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 23:18:55 -0700 (PDT) From: Nicolin Chen To: thierry.reding@gmail.com, joro@8bytes.org Cc: vdumpa@nvidia.com, jonathanh@nvidia.com, digetx@gmail.com, linux-tegra@vger.kernel.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, hch@infradead.org Subject: [PATCH v4 1/2] iommu/tegra-smmu: Unwrap tegra_smmu_group_get Date: Mon, 28 Sep 2020 23:13:24 -0700 Message-Id: <20200929061325.10197-2-nicoleotsuka@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200929061325.10197-1-nicoleotsuka@gmail.com> References: <20200929061325.10197-1-nicoleotsuka@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The tegra_smmu_group_get was added to group devices in different SWGROUPs and it'd return a NULL group pointer upon a mismatch at tegra_smmu_find_group(), so for most of clients/devices, it very likely would mismatch and need a fallback generic_device_group(). But now tegra_smmu_group_get handles devices in same SWGROUP too, which means that it would allocate a group for every new SWGROUP or would directly return an existing one upon matching a SWGROUP, i.e. any device will go through this function. So possibility of having a NULL group pointer in device_group() is upon failure of either devm_kzalloc() or iommu_group_alloc(). In either case, calling generic_device_group() no longer makes a sense. Especially for devm_kzalloc() failing case, it'd cause a problem if it fails at devm_kzalloc() yet succeeds at a fallback generic_device_group(), because it does not create a group->list for other devices to match. This patch simply unwraps the function to clean it up. Signed-off-by: Nicolin Chen --- Changelog v2->v4: * N/A v1->v2: * Changed type of swgroup to "unsigned int", following Thierry's commnets. drivers/iommu/tegra-smmu.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c index 0becdbfea306..ec4c9dafff95 100644 --- a/drivers/iommu/tegra-smmu.c +++ b/drivers/iommu/tegra-smmu.c @@ -903,10 +903,12 @@ static void tegra_smmu_group_release(void *iommu_data) mutex_unlock(&smmu->lock); } -static struct iommu_group *tegra_smmu_group_get(struct tegra_smmu *smmu, - unsigned int swgroup) +static struct iommu_group *tegra_smmu_device_group(struct device *dev) { + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); + struct tegra_smmu *smmu = dev_iommu_priv_get(dev); const struct tegra_smmu_group_soc *soc; + unsigned int swgroup = fwspec->ids[0]; struct tegra_smmu_group *group; struct iommu_group *grp; @@ -950,19 +952,6 @@ static struct iommu_group *tegra_smmu_group_get(struct tegra_smmu *smmu, return group->group; } -static struct iommu_group *tegra_smmu_device_group(struct device *dev) -{ - struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); - struct tegra_smmu *smmu = dev_iommu_priv_get(dev); - struct iommu_group *group; - - group = tegra_smmu_group_get(smmu, fwspec->ids[0]); - if (!group) - group = generic_device_group(dev); - - return group; -} - static int tegra_smmu_of_xlate(struct device *dev, struct of_phandle_args *args) { -- 2.17.1