public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Wu Fengguang <wfg@linux.intel.com>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: L-K <linux-kernel@vger.kernel.org>
Subject: generic swap()
Date: Fri, 16 Jan 2009 10:26:34 +0100	[thread overview]
Message-ID: <1232097994.14073.4.camel@laptop> (raw)

Hi,

Where did this patch come from? -- I can't seem to find it on lkml at all..

The reason I ask it that I wonder why swap() has a return value?

---

commit 91f68b7359144aa40bb9668124543d15284750b4
Author: Wu Fengguang <fengguang.wu@intel.com>
Date:   Wed Jan 7 18:09:12 2009 -0800

    generic swap(): introduce global macro swap(a, b)
    
    There have been some local definitions of swap(), it's time to replace
    them all with a uniform one.
    
    Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 6b8e202..343df9e 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -476,6 +476,12 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
 	__val = __val < __min ? __min: __val;	\
 	__val > __max ? __max: __val; })
 
+
+/*
+ * swap - swap value of @a and @b
+ */
+#define swap(a, b) ({ typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; })
+
 /**
  * container_of - cast a member of a structure out to the containing structure
  * @ptr:	the pointer to the member.



             reply	other threads:[~2009-01-16  9:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-16  9:26 Peter Zijlstra [this message]
2009-01-16  9:38 ` generic swap() Andrew Morton
2009-01-16  9:45   ` Peter Zijlstra
2009-02-06  1:26     ` Wu Fengguang

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=1232097994.14073.4.camel@laptop \
    --to=peterz@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wfg@linux.intel.com \
    /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