All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] iommu/tegra: smmu: Simplify allocation at once
@ 2012-05-14 19:16 ` Hiroshi DOYU
  0 siblings, 0 replies; 19+ messages in thread
From: Hiroshi DOYU @ 2012-05-14 19:16 UTC (permalink / raw)
  To: hdoyu-DDmLM1+adcrQT0dZR+AlfA
  Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Grant Likely,
	Rob Herring, Joerg Roedel, Thierry Reding, Stephen Warren,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ

To simplify the code, alloc necessary data at once.

Signed-off-by: Hiroshi DOYU <hdoyu-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
This patch requires:

    [PATCH 1/2] iommu/tegra: smmu: Add device tree support for SMMU
        http://marc.info/?l=linux-tegra&m=133663641107327&w=2

Also the above patch requires:

    [PATCH 1/1] dt: Add general DMA window parser
        http://marc.info/?l=linux-tegra&m=133671302703840&w=2
---
 drivers/iommu/tegra-smmu.c |   29 +++++++++--------------------
 1 files changed, 9 insertions(+), 20 deletions(-)

diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
index dbaba77..e4acd44 100644
--- a/drivers/iommu/tegra-smmu.c
+++ b/drivers/iommu/tegra-smmu.c
@@ -241,8 +241,6 @@ struct smmu_device {
 	spinlock_t	lock;
 	char		*name;
 	struct device	*dev;
-	int		num_as;
-	struct smmu_as	*as;		/* Run-time allocated array */
 	struct page *avp_vector_page;	/* dummy page shared by all AS's */
 
 	/*
@@ -254,6 +252,9 @@ struct smmu_device {
 	unsigned long asid_security;
 
 	struct device_node *ahb;
+
+	int		num_as;
+	struct smmu_as	as[0];		/* Run-time allocated array */
 };
 
 static struct smmu_device *smmu_handle; /* unique for a system */
@@ -902,15 +903,18 @@ static int tegra_smmu_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	int i, asids, err = 0;
 	dma_addr_t base;
-	size_t size;
-	const void *prop;
+	size_t bytes, size;
 
 	if (smmu_handle)
 		return -EIO;
 
 	BUILD_BUG_ON(PAGE_SHIFT != SMMU_PAGE_SHIFT);
 
-	smmu = devm_kzalloc(dev, sizeof(*smmu), GFP_KERNEL);
+	if (of_property_read_u32(dev->of_node, "nvidia,#asids", &asids))
+		return -ENODEV;
+
+	bytes = sizeof(*smmu) + asids * sizeof(*smmu->as);
+	smmu = devm_kzalloc(dev, bytes, GFP_KERNEL);
 	if (!smmu) {
 		dev_err(dev, "failed to allocate smmu_device\n");
 		return -ENOMEM;
@@ -939,13 +943,6 @@ static int tegra_smmu_probe(struct platform_device *pdev)
 	if (!size)
 		return -EINVAL;
 
-	prop = of_get_property(dev->of_node, "nvidia,#asids", NULL);
-	if (!prop)
-		return -ENODEV;
-	asids = be32_to_cpup(prop);
-	if (!asids)
-		return -ENODEV;
-
 	smmu->ahb = of_parse_phandle(dev->of_node, "nvidia,ahb", 0);
 	if (!smmu->ahb)
 		return -ENODEV;
@@ -960,14 +957,6 @@ static int tegra_smmu_probe(struct platform_device *pdev)
 	smmu->translation_enable_2 = ~0;
 	smmu->asid_security = 0;
 
-	smmu->as = devm_kzalloc(dev,
-			sizeof(smmu->as[0]) * smmu->num_as, GFP_KERNEL);
-	if (!smmu->as) {
-		dev_err(dev, "failed to allocate smmu_as\n");
-		err = -ENOMEM;
-		goto fail;
-	}
-
 	for (i = 0; i < smmu->num_as; i++) {
 		struct smmu_as *as = &smmu->as[i];
 
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2012-05-18 10:05 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-14 19:16 [PATCH 1/2] iommu/tegra: smmu: Simplify allocation at once Hiroshi DOYU
2012-05-14 19:16 ` Hiroshi DOYU
     [not found] ` <1337022975-23999-1-git-send-email-hdoyu-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2012-05-14 19:16   ` [PATCH 2/2] iommu/tegra: smmu: Remove unnecessary cleanups with devm_*() Hiroshi DOYU
2012-05-14 19:16     ` Hiroshi DOYU
2012-05-14 23:34   ` [PATCH 1/2] iommu/tegra: smmu: Simplify allocation at once Stephen Warren
2012-05-14 23:34     ` Stephen Warren
     [not found]     ` <4FB19677.4040702-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-05-15  8:06       ` Hiroshi Doyu
2012-05-15  8:06         ` Hiroshi Doyu
2012-05-15  8:12       ` [v2 " Hiroshi DOYU
2012-05-15  8:12         ` Hiroshi DOYU
     [not found]         ` <1337069574-2022-1-git-send-email-hdoyu-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2012-05-15  8:12           ` [v2 2/2] iommu/tegra: smmu: Remove unnecessary cleanups with devm_*() Hiroshi DOYU
2012-05-15  8:12             ` Hiroshi DOYU
2012-05-15  8:26       ` [PATCH 1/2] iommu/tegra: smmu: Simplify allocation at once Hiroshi Doyu
2012-05-15  8:26         ` Hiroshi Doyu
     [not found]         ` <20120515.112649.411607744957826949.hdoyu-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2012-05-15 16:09           ` Stephen Warren
2012-05-15 16:09             ` Stephen Warren
     [not found]             ` <4FB27FA9.20106-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-05-15 18:47               ` Hiroshi Doyu
2012-05-15 18:47                 ` Hiroshi Doyu
2012-05-18 10:05   ` [PATCH 1/1] iommu/tegra: smmu: Fix uninitialized var warning Hiroshi DOYU

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.