aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Nazarewicz <mina86@mina86.com>2014-10-09 18:30:15 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-10-09 22:26:03 -0400
commitc185b07fc9f24d52a864376ed22a6d84384b0c53 (patch)
tree03822f22af12a7b905ac7dde19406f72a9ba47a8
parent2e1d06e1c05af9dbe8a3bfddeefbf041ca637fff (diff)
include/linux/kernel.h: deduplicate code implementing clamp* macros
Instead of open-coding clamp_t macro min_t and max_t the way clamp macro does and instead of open-coding clamp_val simply use clamp_t. Furthermore, normalise argument naming in the macros to be lo and hi. Signed-off-by: Michal Nazarewicz <mina86@mina86.com> Cc: Mark Rustad <mark.d.rustad@intel.com> Cc: "Kirsher, Jeffrey T" <jeffrey.t.kirsher@intel.com> Cc: Hagen Paul Pfeifer <hagen@jauu.net> Cc: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--include/linux/kernel.h24
1 files changed, 7 insertions, 17 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index aa2a0cb57f50..e9e420b6d931 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -734,7 +734,7 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
734 * @lo: lowest allowable value 734 * @lo: lowest allowable value
735 * @hi: highest allowable value 735 * @hi: highest allowable value
736 * 736 *
737 * This macro does strict typechecking of min/max to make sure they are of the 737 * This macro does strict typechecking of lo/hi to make sure they are of the
738 * same type as val. See the unnecessary pointer comparisons. 738 * same type as val. See the unnecessary pointer comparisons.
739 */ 739 */
740#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi) 740#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
@@ -759,36 +759,26 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
759 * clamp_t - return a value clamped to a given range using a given type 759 * clamp_t - return a value clamped to a given range using a given type
760 * @type: the type of variable to use 760 * @type: the type of variable to use
761 * @val: current value 761 * @val: current value
762 * @min: minimum allowable value 762 * @lo: minimum allowable value
763 * @max: maximum allowable value 763 * @hi: maximum allowable value
764 * 764 *
765 * This macro does no typechecking and uses temporary variables of type 765 * This macro does no typechecking and uses temporary variables of type
766 * 'type' to make all the comparisons. 766 * 'type' to make all the comparisons.
767 */ 767 */
768#define clamp_t(type, val, min, max) ({ \ 768#define clamp_t(type, val, lo, hi) min_t(type, max_t(type, val, lo), hi)
769 type __val = (val); \
770 type __min = (min); \
771 type __max = (max); \
772 __val = __val < __min ? __min: __val; \
773 __val > __max ? __max: __val; })
774 769
775/** 770/**
776 * clamp_val - return a value clamped to a given range using val's type 771 * clamp_val - return a value clamped to a given range using val's type
777 * @val: current value 772 * @val: current value
778 * @min: minimum allowable value 773 * @lo: minimum allowable value
779 * @max: maximum allowable value 774 * @hi: maximum allowable value
780 * 775 *
781 * This macro does no typechecking and uses temporary variables of whatever 776 * This macro does no typechecking and uses temporary variables of whatever
782 * type the input argument 'val' is. This is useful when val is an unsigned 777 * type the input argument 'val' is. This is useful when val is an unsigned
783 * type and min and max are literals that will otherwise be assigned a signed 778 * type and min and max are literals that will otherwise be assigned a signed
784 * integer type. 779 * integer type.
785 */ 780 */
786#define clamp_val(val, min, max) ({ \ 781#define clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi)
787 typeof(val) __val = (val); \
788 typeof(val) __min = (min); \
789 typeof(val) __max = (max); \
790 __val = __val < __min ? __min: __val; \
791 __val > __max ? __max: __val; })
792 782
793 783
794/* 784/*