From patchwork Mon Jan 30 08:37:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Antipov X-Patchwork-Id: 6431 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 1000023E0E for ; Mon, 30 Jan 2012 08:36:50 +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 EE4CAA18696 for ; Mon, 30 Jan 2012 08:36:49 +0000 (UTC) Received: by bkar19 with SMTP id r19so3934141bka.11 for ; Mon, 30 Jan 2012 00:36:49 -0800 (PST) Received: by 10.205.134.129 with SMTP id ic1mr7862701bkc.92.1327912609590; Mon, 30 Jan 2012 00:36:49 -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 u28cs144610bks; Mon, 30 Jan 2012 00:36:49 -0800 (PST) Received: by 10.204.153.195 with SMTP id l3mr8155604bkw.123.1327912608546; Mon, 30 Jan 2012 00:36:48 -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 um8si8526182bkb.151.2012.01.30.00.36.48 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 30 Jan 2012 00:36:48 -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 zu5so4155041bkb.37 for ; Mon, 30 Jan 2012 00:36:48 -0800 (PST) Received: by 10.204.150.69 with SMTP id x5mr7971098bkv.53.1327912607959; Mon, 30 Jan 2012 00:36:47 -0800 (PST) Received: from localhost.localdomain ([78.153.153.8]) by mx.google.com with ESMTPS id ek9sm36013755bkb.10.2012.01.30.00.36.46 (version=SSLv3 cipher=OTHER); Mon, 30 Jan 2012 00:36:47 -0800 (PST) From: Dmitry Antipov To: Tejun Heo , Christoph Lameter Cc: Rusty Russell , linux-mm@kvack.org, linux-kernel@vger.kernel.org, patches@linaro.org, linaro-dev@lists.linaro.org, Dmitry Antipov Subject: [PATCH 1/3] percpu: use ZERO_SIZE_PTR / ZERO_OR_NULL_PTR Date: Mon, 30 Jan 2012 12:37:34 +0400 Message-Id: <1327912654-8738-1-git-send-email-dmitry.antipov@linaro.org> X-Mailer: git-send-email 1.7.7.6 Fix pcpu_alloc() to return ZERO_SIZE_PTR if requested size is 0; fix free_percpu() to check passed pointer with ZERO_OR_NULL_PTR. Signed-off-by: Dmitry Antipov Acked-by: Christoph Lameter --- mm/percpu.c | 16 +++++++++++----- 1 files changed, 11 insertions(+), 5 deletions(-) diff --git a/mm/percpu.c b/mm/percpu.c index f47af91..e903a19 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -702,7 +702,8 @@ static struct pcpu_chunk *pcpu_chunk_addr_search(void *addr) * Does GFP_KERNEL allocation. * * RETURNS: - * Percpu pointer to the allocated area on success, NULL on failure. + * ZERO_SIZE_PTR if @size is zero, percpu pointer to the + * allocated area on success or NULL on failure. */ static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved) { @@ -713,7 +714,10 @@ static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved) unsigned long flags; void __percpu *ptr; - if (unlikely(!size || size > PCPU_MIN_UNIT_SIZE || align > PAGE_SIZE)) { + if (unlikely(!size)) + return ZERO_SIZE_PTR; + + if (unlikely(size > PCPU_MIN_UNIT_SIZE || align > PAGE_SIZE)) { WARN(true, "illegal size (%zu) or align (%zu) for " "percpu allocation\n", size, align); return NULL; @@ -834,7 +838,8 @@ fail_unlock_mutex: * Does GFP_KERNEL allocation. * * RETURNS: - * Percpu pointer to the allocated area on success, NULL on failure. + * ZERO_SIZE_PTR if @size is zero, percpu pointer to the + * allocated area on success, NULL on failure. */ void __percpu *__alloc_percpu(size_t size, size_t align) { @@ -856,7 +861,8 @@ EXPORT_SYMBOL_GPL(__alloc_percpu); * Does GFP_KERNEL allocation. * * RETURNS: - * Percpu pointer to the allocated area on success, NULL on failure. + * ZERO_SIZE_PTR if @size is zero, percpu pointer to the + * allocated area on success or NULL on failure. */ void __percpu *__alloc_reserved_percpu(size_t size, size_t align) { @@ -917,7 +923,7 @@ void free_percpu(void __percpu *ptr) unsigned long flags; int off; - if (!ptr) + if (unlikely(ZERO_OR_NULL_PTR(ptr))) return; kmemleak_free_percpu(ptr);