From: Sasha Levin <levinsasha928@gmail.com>
To: torvalds@linux-foundation.org, akpm@linux-foundation.org,
peterz@infradead.org, mingo@elte.hu, hpa@zytor.com,
tglx@linutronix.de, srivatsa.bhat@linux.vnet.ibm.com
Cc: linux-kernel@vger.kernel.org, Sasha Levin <levinsasha928@gmail.com>
Subject: [RFC 3/3] kernel.h: use new typechecking macros in min()/max() and friends
Date: Sat, 14 Apr 2012 18:14:45 -0400 [thread overview]
Message-ID: <1334441685-4438-4-git-send-email-levinsasha928@gmail.com> (raw)
In-Reply-To: <1334441685-4438-1-git-send-email-levinsasha928@gmail.com>
Convert to using new typechecking macros in kernel.h. This prevents code
duplication and makes the modified macros (easily) readable again.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
include/linux/kernel.h | 47 +++++++++++++++--------------------------------
1 files changed, 15 insertions(+), 32 deletions(-)
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 645231c..ec509cc 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -555,34 +555,22 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
* "unnecessary" pointer comparison.
*/
#define min(x, y) ({ \
- typeof(x) _min1 = (x); \
- typeof(y) _min2 = (y); \
- (void) (&_min1 == &_min2); \
- _min1 < _min2 ? _min1 : _min2; })
+ typecmp2((x), (y)); \
+ (x) < (y) ? (x) : (y); })
#define max(x, y) ({ \
- typeof(x) _max1 = (x); \
- typeof(y) _max2 = (y); \
- (void) (&_max1 == &_max2); \
- _max1 > _max2 ? _max1 : _max2; })
+ typecmp2((x), (y)); \
+ (x) > (y) ? (x) : (y); })
#define min3(x, y, z) ({ \
- typeof(x) _min1 = (x); \
- typeof(y) _min2 = (y); \
- typeof(z) _min3 = (z); \
- (void) (&_min1 == &_min2); \
- (void) (&_min1 == &_min3); \
- _min1 < _min2 ? (_min1 < _min3 ? _min1 : _min3) : \
- (_min2 < _min3 ? _min2 : _min3); })
+ typecmp3((x), (y), (z)); \
+ (x) < (y) ? ((x) < (z) ? (x) : (z)) : \
+ ((y) < (z) ? (y) : (z)); })
#define max3(x, y, z) ({ \
- typeof(x) _max1 = (x); \
- typeof(y) _max2 = (y); \
- typeof(z) _max3 = (z); \
- (void) (&_max1 == &_max2); \
- (void) (&_max1 == &_max3); \
- _max1 > _max2 ? (_max1 > _max3 ? _max1 : _max3) : \
- (_max2 > _max3 ? _max2 : _max3); })
+ typecmp3((x), (y), (z)); \
+ (x) > (y) ? ((x) > (z) ? (x) : (z)) : \
+ ((y) > (z) ? (y) : (z)); })
/**
* min_not_zero - return the minimum that is _not_ zero, unless both are zero
@@ -590,9 +578,8 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
* @y: value2
*/
#define min_not_zero(x, y) ({ \
- typeof(x) __x = (x); \
- typeof(y) __y = (y); \
- __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); })
+ typecmp2((x), (y)); \
+ (x) == 0 ? (y) : ((y) == 0 ? (x) : min((x), (y))); })
/**
* clamp - return a value clamped to a given range with strict typechecking
@@ -604,13 +591,9 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
* same type as val. See the unnecessary pointer comparisons.
*/
#define clamp(val, min, max) ({ \
- typeof(val) __val = (val); \
- typeof(min) __min = (min); \
- typeof(max) __max = (max); \
- (void) (&__val == &__min); \
- (void) (&__val == &__max); \
- __val = __val < __min ? __min: __val; \
- __val > __max ? __max: __val; })
+ typecmp3((val), (min), (max)); \
+ ((val) > (max) ? (max) : (val)) < (min) ? \
+ (min) : ((val) > (max) ? (max) : (val)); })
/*
* ..and if you can't take the strict
--
1.7.8.5
next prev parent reply other threads:[~2012-04-14 19:15 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-14 22:14 [RFC 0/3] Extend type checking macros Sasha Levin
2012-04-14 21:02 ` Peter Zijlstra
2012-04-14 21:18 ` Srivatsa S. Bhat
2012-04-14 22:31 ` Srivatsa S. Bhat
2012-04-14 22:14 ` [RFC 1/3] typecheck: extend typecheck.h with more useful typechecking macros Sasha Levin
2012-04-14 21:12 ` Linus Torvalds
2012-04-14 22:14 ` [RFC 2/3] sched: add type checks to for_each_cpu_mask() Sasha Levin
2012-04-14 21:15 ` Linus Torvalds
2012-04-20 22:33 ` Andrew Morton
2012-04-14 22:14 ` Sasha Levin [this message]
2012-04-14 21:01 ` [RFC 3/3] kernel.h: use new typechecking macros in min()/max() and friends Peter Zijlstra
2012-04-14 21:17 ` Linus Torvalds
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=1334441685-4438-4-git-send-email-levinsasha928@gmail.com \
--to=levinsasha928@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
--cc=srivatsa.bhat@linux.vnet.ibm.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.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
Powered by JetHome