linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Antipov <dmitry.antipov@linaro.org>
To: Tejun Heo <tj@kernel.org>, Christoph Lameter <cl@linux-foundation.org>
Cc: Rusty Russell <rusty@rustcorp.com.au>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	patches@linaro.org, linaro-dev@lists.linaro.org,
	Dmitry Antipov <dmitry.antipov@linaro.org>
Subject: [PATCH 1/3] percpu: use ZERO_SIZE_PTR / ZERO_OR_NULL_PTR
Date: Mon, 30 Jan 2012 12:37:34 +0400	[thread overview]
Message-ID: <1327912654-8738-1-git-send-email-dmitry.antipov@linaro.org> (raw)

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 <dmitry.antipov@linaro.org>
---
 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);
-- 
1.7.7.6


             reply	other threads:[~2012-01-30  8:36 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-30  8:37 Dmitry Antipov [this message]
2012-01-30 16:15 ` [PATCH 1/3] percpu: use ZERO_SIZE_PTR / ZERO_OR_NULL_PTR Christoph Lameter
2012-01-30 17:15 ` Tejun Heo
2012-01-30 17:19   ` Tejun Heo
2012-01-30 17:22     ` Christoph Lameter
2012-01-30 17:33       ` Tejun Heo
2012-01-30 17:35         ` Christoph Lameter
2012-01-30 17:22   ` Christoph Lameter
2012-01-30 17:42     ` Tejun Heo
2012-01-30 17:52       ` Christoph Lameter
2012-01-30 17:54         ` Tejun Heo
2012-01-30 17:58           ` Christoph Lameter
2012-01-30 18:02             ` Tejun Heo
2012-01-30 18:12               ` Christoph Lameter
2012-01-30 18:16                 ` Tejun Heo
2012-01-31  4:48                   ` Rusty Russell
2012-01-30 18:13               ` Tejun Heo
2012-01-30 18:15                 ` Christoph Lameter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1327912654-8738-1-git-send-email-dmitry.antipov@linaro.org \
    --to=dmitry.antipov@linaro.org \
    --cc=cl@linux-foundation.org \
    --cc=linaro-dev@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=patches@linaro.org \
    --cc=rusty@rustcorp.com.au \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).