From patchwork Mon Jul 27 12:29:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell King X-Patchwork-Id: 6873311 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C7BE0C05AC for ; Mon, 27 Jul 2015 12:33:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D9E1A204D8 for ; Mon, 27 Jul 2015 12:33:23 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0A29C2043C for ; Mon, 27 Jul 2015 12:33:23 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZJhYw-0005KV-6h; Mon, 27 Jul 2015 12:31:22 +0000 Received: from pandora.arm.linux.org.uk ([2001:4d48:ad52:3201:214:fdff:fe10:1be6]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZJhXy-0002zu-5v for linux-arm-kernel@lists.infradead.org; Mon, 27 Jul 2015 12:30:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=arm.linux.org.uk; s=pandora-2014; h=Date:Sender:Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:References:In-Reply-To; bh=/nh7zew1YdN3i+TFNnXMgwwisUfVgtEALYMi3YeoSu0=; b=pe9gNv3iKtch6Tc0Tb99Pq0fIx9mOCsvIyPTjL9ha7xFXeR7ZcF5aAwqrArpbFhvpHy6xi2wgDlb4iwTJGNK0bXo9w1gxlPRXBnbqjYFFy0gK+xkuRKg6Hj+hqdRXRfXZFDq+rOJYZG81K712TgCFh2konD6qI4nZXvCy6iD5YQ=; Received: from e0022681537dd.dyn.arm.linux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:40260 helo=rmk-PC.arm.linux.org.uk) by pandora.arm.linux.org.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1ZJhXG-00070X-6h; Mon, 27 Jul 2015 13:29:38 +0100 Received: from rmk by rmk-PC.arm.linux.org.uk with local (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1ZJhX9-00047r-Dq; Mon, 27 Jul 2015 13:29:31 +0100 In-Reply-To: <20150727122824.GH7557@n2100.arm.linux.org.uk> References: <20150727122824.GH7557@n2100.arm.linux.org.uk> From: Russell King To: iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org Subject: [PATCH 09/18] iommu: tegra-smmu: use kcalloc() to allocate counter array MIME-Version: 1.0 Content-Disposition: inline Message-Id: Date: Mon, 27 Jul 2015 13:29:31 +0100 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150727_053022_886647_D3B0CA47 X-CRM114-Status: GOOD ( 16.21 ) X-Spam-Score: -2.0 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Courbot , Joerg Roedel , Stephen Warren , Thierry Reding , Hiroshi Doyu Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use kcalloc() to allocate the use-counter array for the page directory entries/page tables. Using kcalloc() allows us to be provided with zero-initialised memory from the allocators, rather than initialising it ourselves. Signed-off-by: Russell King --- drivers/iommu/tegra-smmu.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c index 8ec5ac45caab..d649b06cc4ca 100644 --- a/drivers/iommu/tegra-smmu.c +++ b/drivers/iommu/tegra-smmu.c @@ -40,7 +40,7 @@ struct tegra_smmu_as { struct iommu_domain domain; struct tegra_smmu *smmu; unsigned int use_count; - struct page *count; + u32 *count; struct page **pts; struct page *pd; unsigned id; @@ -265,7 +265,7 @@ static struct iommu_domain *tegra_smmu_domain_alloc(unsigned type) return NULL; } - as->count = alloc_page(GFP_KERNEL); + as->count = kcalloc(SMMU_NUM_PDE, sizeof(u32), GFP_KERNEL); if (!as->count) { __free_page(as->pd); kfree(as); @@ -274,7 +274,7 @@ static struct iommu_domain *tegra_smmu_domain_alloc(unsigned type) as->pts = kcalloc(SMMU_NUM_PDE, sizeof(*as->pts), GFP_KERNEL); if (!as->pts) { - __free_page(as->count); + kfree(as->count); __free_page(as->pd); kfree(as); return NULL; @@ -287,13 +287,6 @@ static struct iommu_domain *tegra_smmu_domain_alloc(unsigned type) for (i = 0; i < SMMU_NUM_PDE; i++) pd[i] = 0; - /* clear PDE usage counters */ - pd = page_address(as->count); - SetPageReserved(as->count); - - for (i = 0; i < SMMU_NUM_PDE; i++) - pd[i] = 0; - /* setup aperture */ as->domain.geometry.aperture_start = 0; as->domain.geometry.aperture_end = 0xffffffff; @@ -509,7 +502,7 @@ static u32 *tegra_smmu_pte_lookup(struct tegra_smmu_as *as, unsigned long iova, static u32 *as_get_pte(struct tegra_smmu_as *as, dma_addr_t iova, struct page **pagep) { - u32 *pd = page_address(as->pd), *pt, *count; + u32 *pd = page_address(as->pd), *pt; unsigned int pde = iova_pd_index(iova); struct tegra_smmu *smmu = as->smmu; struct page *page; @@ -545,9 +538,8 @@ static u32 *as_get_pte(struct tegra_smmu_as *as, dma_addr_t iova, pt = page_address(page); /* Keep track of entries in this page table. */ - count = page_address(as->count); if (pt[iova_pt_index(iova)] == 0) - count[pde]++; + as->count[pde]++; return tegra_smmu_pte_offset(page, iova); } @@ -556,7 +548,6 @@ static void tegra_smmu_pte_put_use(struct tegra_smmu_as *as, unsigned long iova) { struct tegra_smmu *smmu = as->smmu; unsigned int pde = iova_pd_index(iova); - u32 *count = page_address(as->count); u32 *pd = page_address(as->pd); struct page *page = as->pts[pde]; @@ -564,7 +555,7 @@ static void tegra_smmu_pte_put_use(struct tegra_smmu_as *as, unsigned long iova) * When no entries in this page table are used anymore, return the * memory page to the system. */ - if (--count[pde] == 0) { + if (--as->count[pde] == 0) { unsigned int offset = pde * sizeof(*pd); /* Clear the page directory entry first */