From patchwork Tue Aug 28 05:13:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hiroshi Doyu X-Patchwork-Id: 10987 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id DEDB123F22 for ; Tue, 28 Aug 2012 05:13:38 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id F3FEDA18EDD for ; Tue, 28 Aug 2012 05:13:09 +0000 (UTC) Received: by iafj25 with SMTP id j25so7179036iaf.11 for ; Mon, 27 Aug 2012 22:13:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :x-pgp-universal:from:to:date:message-id:x-mailer:in-reply-to :references:mime-version:cc:subject:x-beenthere:x-mailman-version :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:content-type:content-transfer-encoding :sender:errors-to:x-gm-message-state; bh=SmO3lTkGi87i/9hXi3PTVRjbkcB8a8Z9Nw8jHr3BvmY=; b=PMLhtb1pzJowaqfaDriD97gDEnsWult0seI5U6ome+MVkwB+tlcnUENzw7JlE9pwci mliebbIjGtuDDa1lPW7inTYDdVZ0QdO9lZDVGvAZR5zuqkQudIKJfdBSN+zptMO1cxYv XrU1b8RmybR2nMGVK3u4qgePDMo7aDMupKJO1Ynwq2HtpbNx1zmLQaqDiks7LbYirX62 uFgHHFsGN/cmRZUHeMMzq0wapjBodXz8rtq1GuEikeEUvzNjFpmZRgNs1Df8FyJodWfh Eu5ZbBUZKIjZNckDGTOI2rcxXODmd0RdMwCXUMwcd43Y5uza1trZW79IETWvi3VuDEr2 SBTg== Received: by 10.50.159.196 with SMTP id xe4mr12290830igb.43.1346130817690; Mon, 27 Aug 2012 22:13:37 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.232 with SMTP id ex8csp7668igc; Mon, 27 Aug 2012 22:13:36 -0700 (PDT) Received: by 10.204.157.6 with SMTP id z6mr4387769bkw.25.1346130815732; Mon, 27 Aug 2012 22:13:35 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id hu14si12121677bkc.66.2012.08.27.22.13.33; Mon, 27 Aug 2012 22:13:35 -0700 (PDT) Received-SPF: neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) client-ip=91.189.95.16; Authentication-Results: mx.google.com; spf=neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) smtp.mail=linaro-mm-sig-bounces@lists.linaro.org Received: from localhost ([127.0.0.1] helo=mombin.canonical.com) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1T6E7I-0004Bq-4g; Tue, 28 Aug 2012 05:13:32 +0000 Received: from hqemgate04.nvidia.com ([216.228.121.35]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1T6E7G-00047y-VW for linaro-mm-sig@lists.linaro.org; Tue, 28 Aug 2012 05:13:31 +0000 Received: from hqnvupgp07.nvidia.com (Not Verified[216.228.121.13]) by hqemgate04.nvidia.com id ; Mon, 27 Aug 2012 22:12:46 -0700 Received: from hqemhub02.nvidia.com ([172.17.108.22]) by hqnvupgp07.nvidia.com (PGP Universal service); Mon, 27 Aug 2012 22:07:16 -0700 X-PGP-Universal: processed; by hqnvupgp07.nvidia.com on Mon, 27 Aug 2012 22:07:16 -0700 Received: from hqnvemgw01.nvidia.com (172.20.150.20) by hqemhub02.nvidia.com (172.20.150.31) with Microsoft SMTP Server id 8.3.264.0; Mon, 27 Aug 2012 22:13:24 -0700 Received: from thelma.nvidia.com (Not Verified[172.16.212.77]) by hqnvemgw01.nvidia.com with MailMarshal (v6,7,2,8378) id ; Mon, 27 Aug 2012 22:13:24 -0700 Received: from oreo.Nvidia.com (dhcp-10-21-25-186.nvidia.com [10.21.25.186]) by thelma.nvidia.com (8.13.8+Sun/8.8.8) with ESMTP id q7S5D9NX003531; Mon, 27 Aug 2012 22:13:20 -0700 (PDT) From: Hiroshi Doyu To: Date: Tue, 28 Aug 2012 08:13:02 +0300 Message-ID: <1346130784-23571-3-git-send-email-hdoyu@nvidia.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1346130784-23571-1-git-send-email-hdoyu@nvidia.com> References: <1346130784-23571-1-git-send-email-hdoyu@nvidia.com> MIME-Version: 1.0 Cc: linux@arm.linux.org.uk, arnd@arndb.de, minchan@kernel.org, konrad.wilk@oracle.com, linux-kernel@vger.kernel.org, linaro-mm-sig@lists.linaro.org, linux-mm@kvack.org, kyungmin.park@samsung.com, linux-tegra@vger.kernel.org, pullip.cho@samsung.com, linux-arm-kernel@lists.infradead.org Subject: [Linaro-mm-sig] [v4 2/4] ARM: dma-mapping: Refactor out to introduce __in_atomic_pool X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Unified memory management interest group." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linaro-mm-sig-bounces@lists.linaro.org Errors-To: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQkxUWPexaNUPQG6hq+J0wE1b6znfox2N9mE+XSw2fZGF6zVKEXpgoEPb3DWF8V4W0+AV9Dt Check the given range("start", "size") is included in "atomic_pool" or not. Signed-off-by: Hiroshi Doyu --- arch/arm/mm/dma-mapping.c | 26 ++++++++++++++++++++------ 1 files changed, 20 insertions(+), 6 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 51d5e2b..a62f552 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -503,20 +503,34 @@ static void *__alloc_from_pool(size_t size, struct page **ret_page) return ptr; } +static bool __in_atomic_pool(void *start, size_t size) +{ + struct dma_pool *pool = &atomic_pool; + void *end = start + size; + void *pool_start = pool->vaddr; + void *pool_end = pool->vaddr + pool->size; + + if (start < pool_start || start > pool_end) + return false; + + if (end <= pool_end) + return true; + + WARN(1, "Wrong coherent size(%p-%p) from atomic pool(%p-%p)\n", + start, end - 1, pool_start, pool_end - 1); + + return false; +} + static int __free_from_pool(void *start, size_t size) { struct dma_pool *pool = &atomic_pool; unsigned long pageno, count; unsigned long flags; - if (start < pool->vaddr || start > pool->vaddr + pool->size) + if (!__in_atomic_pool(start, size)) return 0; - if (start + size > pool->vaddr + pool->size) { - WARN(1, "freeing wrong coherent size from pool\n"); - return 0; - } - pageno = (start - pool->vaddr) >> PAGE_SHIFT; count = size >> PAGE_SHIFT;