From patchwork Mon Jan 30 08:39:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Antipov X-Patchwork-Id: 6432 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 EC1F723E0E for ; Mon, 30 Jan 2012 08:38:27 +0000 (UTC) Received: from mail-bk0-f52.google.com (mail-bk0-f52.google.com [209.85.214.52]) by fiordland.canonical.com (Postfix) with ESMTP id DB859A18228 for ; Mon, 30 Jan 2012 08:38:27 +0000 (UTC) Received: by bkar19 with SMTP id r19so3935138bka.11 for ; Mon, 30 Jan 2012 00:38:27 -0800 (PST) Received: by 10.205.127.17 with SMTP id gy17mr7854508bkc.110.1327912707583; Mon, 30 Jan 2012 00:38:27 -0800 (PST) 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.204.130.220 with SMTP id u28cs144628bks; Mon, 30 Jan 2012 00:38:27 -0800 (PST) Received: by 10.204.133.219 with SMTP id g27mr8076908bkt.47.1327912707014; Mon, 30 Jan 2012 00:38:27 -0800 (PST) Received: from mail-bk0-f50.google.com (mail-bk0-f50.google.com [209.85.214.50]) by mx.google.com with ESMTPS id af6si8547482bkc.53.2012.01.30.00.38.26 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 30 Jan 2012 00:38:26 -0800 (PST) Received-SPF: neutral (google.com: 209.85.214.50 is neither permitted nor denied by best guess record for domain of dmitry.antipov@linaro.org) client-ip=209.85.214.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.214.50 is neither permitted nor denied by best guess record for domain of dmitry.antipov@linaro.org) smtp.mail=dmitry.antipov@linaro.org Received: by bkbzu5 with SMTP id zu5so4156258bkb.37 for ; Mon, 30 Jan 2012 00:38:26 -0800 (PST) Received: by 10.205.138.136 with SMTP id is8mr8065294bkc.72.1327912706524; Mon, 30 Jan 2012 00:38:26 -0800 (PST) Received: from localhost.localdomain ([78.153.153.8]) by mx.google.com with ESMTPS id sp6sm36029580bkb.2.2012.01.30.00.38.25 (version=SSLv3 cipher=OTHER); Mon, 30 Jan 2012 00:38:26 -0800 (PST) From: Dmitry Antipov To: Andrew Morton Cc: Rusty Russell , linux-mm@kvack.org, linux-kernel@vger.kernel.org, patches@linaro.org, linaro-dev@lists.linaro.org, Dmitry Antipov Subject: [PATCH 2/3] vmalloc: use ZERO_SIZE_PTR / ZERO_OR_NULL_PTR Date: Mon, 30 Jan 2012 12:39:26 +0400 Message-Id: <1327912766-8779-1-git-send-email-dmitry.antipov@linaro.org> X-Mailer: git-send-email 1.7.7.6 - Fix vmap() to return ZERO_SIZE_PTR if 0 pages are requested; - fix __vmalloc_node_range() to return ZERO_SIZE_PTR if 0 bytes are requested; - fix __vunmap() to check passed pointer with ZERO_OR_NULL_PTR. Signed-off-by: Dmitry Antipov --- mm/vmalloc.c | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 86ce9a5..040a9cd 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -1456,7 +1456,7 @@ static void __vunmap(const void *addr, int deallocate_pages) { struct vm_struct *area; - if (!addr) + if (unlikely(ZERO_OR_NULL_PTR(addr))) return; if ((PAGE_SIZE-1) & (unsigned long)addr) { @@ -1548,7 +1548,9 @@ void *vmap(struct page **pages, unsigned int count, might_sleep(); - if (count > totalram_pages) + if (unlikely(!count)) + return ZERO_SIZE_PTR; + if (unlikely(count > totalram_pages)) return NULL; area = get_vm_area_caller((count << PAGE_SHIFT), flags, @@ -1648,8 +1650,10 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align, void *addr; unsigned long real_size = size; + if (unlikely(!size)) + return ZERO_SIZE_PTR; size = PAGE_ALIGN(size); - if (!size || (size >> PAGE_SHIFT) > totalram_pages) + if (unlikely((size >> PAGE_SHIFT) > totalram_pages)) goto fail; area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,