From patchwork Thu Aug 23 06:10:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hiroshi Doyu X-Patchwork-Id: 10893 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 31E6E23E00 for ; Thu, 23 Aug 2012 06:11:11 +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 4D272A18F33 for ; Thu, 23 Aug 2012 06:10:57 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id j38so694034iad.11 for ; Wed, 22 Aug 2012 23:11:10 -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=NGR+adsrt1owHdqqPpidJmAPY9yVsLe7Cjw5gVxzs/U=; b=VmlStl/EZaBmIpWyEWBmyC9KFyz+t8FGTsSnto2AVEO/I67DZqY+gju3j9L0kl39Hf wyxC1aqI2vZlS2pG/WNpkDWXZKt6WG75ctMZEpPit0J68P+NCSGXVqKVii1pTGagGjM4 iFNVPxMiEayPw62C0gde4rKG741CLB54iSNdUnBT7IHNQp5BLjPJoHkTdr+g/wODQJ9M Ob+5A8HDZEptGIN4Kx8MMm+6vWMh21ws2V+ULy6vkuPoyG6la8OdDz9YIxrxQ7DEwcNK g6eROLmKSa/4lSTL7xrkSTdQu8lIdCWCDYiPseyAknrwEiwIQqB3Yf/QdVA288/saVm/ FBPQ== Received: by 10.50.182.162 with SMTP id ef2mr357809igc.43.1345702270578; Wed, 22 Aug 2012 23:11:10 -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 ex8csp239282igc; Wed, 22 Aug 2012 23:11:09 -0700 (PDT) Received: by 10.204.129.208 with SMTP id p16mr67344bks.129.1345702269151; Wed, 22 Aug 2012 23:11:09 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id gq18si4100581bkc.91.2012.08.22.23.11.07; Wed, 22 Aug 2012 23:11:09 -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 1T4QdG-0004td-BF; Thu, 23 Aug 2012 06:11:06 +0000 Received: from hqemgate03.nvidia.com ([216.228.121.140]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1T4QdE-0004sy-86 for linaro-mm-sig@lists.linaro.org; Thu, 23 Aug 2012 06:11:04 +0000 Received: from hqnvupgp05.nvidia.com (Not Verified[216.228.121.13]) by hqemgate03.nvidia.com id ; Wed, 22 Aug 2012 23:12:03 -0700 Received: from hqemhub02.nvidia.com ([172.17.108.22]) by hqnvupgp05.nvidia.com (PGP Universal service); Wed, 22 Aug 2012 23:10:49 -0700 X-PGP-Universal: processed; by hqnvupgp05.nvidia.com on Wed, 22 Aug 2012 23:10:49 -0700 Received: from hqnvemgw02.nvidia.com (172.16.227.111) by hqemhub02.nvidia.com (172.20.150.31) with Microsoft SMTP Server id 8.3.264.0; Wed, 22 Aug 2012 23:10:49 -0700 Received: from daphne.nvidia.com (Not Verified[172.16.212.96]) by hqnvemgw02.nvidia.com with MailMarshal (v6,7,2,8378) id ; Wed, 22 Aug 2012 23:11:36 -0700 Received: from oreo.Nvidia.com (dhcp-10-21-25-186.nvidia.com [10.21.25.186]) by daphne.nvidia.com (8.13.8+Sun/8.8.8) with ESMTP id q7N6AcIQ004834; Wed, 22 Aug 2012 23:10:45 -0700 (PDT) From: Hiroshi Doyu To: Date: Thu, 23 Aug 2012 09:10:26 +0300 Message-ID: <1345702229-9539-2-git-send-email-hdoyu@nvidia.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1345702229-9539-1-git-send-email-hdoyu@nvidia.com> References: <1345702229-9539-1-git-send-email-hdoyu@nvidia.com> MIME-Version: 1.0 Cc: linux@arm.linux.org.uk, arnd@arndb.de, konrad.wilk@oracle.com, minchan@kernel.org, linux-kernel@vger.kernel.org, linaro-mm-sig@lists.linaro.org, linux-mm@kvack.org, kyungmin.park@samsung.com, pullip.cho@samsung.com, linux-arm-kernel@lists.infradead.org Subject: [Linaro-mm-sig] [v2 1/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: ALoCoQmNMFKliZ3givRgyAkZbTGCtC7kb7PkAhJDXxxRPHBk6Mk2yYsk3rLhZYg9yvU0LVtU8MNt Check the given range("start", "size") is included in "atomic_pool" or not. Signed-off-by: Hiroshi Doyu --- arch/arm/mm/dma-mapping.c | 25 +++++++++++++++++++------ 1 files changed, 19 insertions(+), 6 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 601da7a..aca2fd0 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -492,19 +492,32 @@ 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) { + WARN(1, "freeing wrong coherent size from pool\n"); + return false; + } + + return true; +} + 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) - return 0; - - if (start + size > pool->vaddr + pool->size) { - WARN(1, "freeing wrong coherent size from pool\n"); + if (!__in_atomic_pool(start, size)) return 0; - } pageno = (start - pool->vaddr) >> PAGE_SHIFT; count = size >> PAGE_SHIFT;