From: dyoung@redhat.com
To: akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
d.hatayama@jp.fujitsu.com, bhe@redhat.com, vgoyal@redhat.com
Cc: dyoung@redhat.com, kexec@lists.infradead.org
Subject: [PATCH 1/2] [PATCH 1/2] Introduce new macros min_lt and max_lt for comparing with larger type
Date: Fri, 11 Mar 2016 14:21:57 +0800 [thread overview]
Message-ID: <20160311062953.571397512@redhat.com> (raw)
[-- Attachment #1: 0001-Introduce-new-macros-min_lt-and-max_lt-for-comparing.patch --]
[-- Type: text/plain, Size: 1170 bytes --]
A useful use case for min_t and max_t is comparing two values with larger
type. For example comparing an u64 and an u32, usually we do not want to
truncate the u64, so we need use min_t or max_t with u64.
To simplify the usage introducing two more macros min_lt and max_lt,
'lt' means larger type.
Signed-off-by: Dave Young <dyoung@redhat.com>
---
include/linux/kernel.h | 13 +++++++++++++
1 file changed, 13 insertions(+)
--- linux.orig/include/linux/kernel.h
+++ linux/include/linux/kernel.h
@@ -798,6 +798,19 @@ static inline void ftrace_dump(enum ftra
type __max2 = (y); \
__max1 > __max2 ? __max1: __max2; })
+/*
+ * use type of larger size in min_lt and max_lt
+ */
+#define min_lt(x, y) ({ \
+ int sx = sizeof(typeof(x)); \
+ int sy = sizeof(typeof(y)); \
+ sx > sy ? min_t(typeof(x), x, y) : min_t(typeof(y), x, y); })
+
+#define max_lt(x, y) ({ \
+ int sx = sizeof(typeof(x)); \
+ int sy = sizeof(typeof(y)); \
+ sx > sy ? max_t(typeof(x), x, y) : max_t(typeof(y), x, y); })
+
/**
* clamp_t - return a value clamped to a given range using a given type
* @type: the type of variable to use
next reply other threads:[~2016-03-11 6:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-11 6:21 dyoung [this message]
2016-03-11 7:19 ` [PATCH 1/2] [PATCH 1/2] Introduce new macros min_lt and max_lt for comparing with larger type Jianyu Zhan
2016-03-11 7:55 ` Dave Young
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=20160311062953.571397512@redhat.com \
--to=dyoung@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=bhe@redhat.com \
--cc=d.hatayama@jp.fujitsu.com \
--cc=kexec@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=vgoyal@redhat.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