login
Header Space

 
 

Re: [PATCH] add kerneldoc for clamp(), clamp_t(), clamp_val() macros

Previous thread: [PATCH 16/18] MMC: OMAP: Lazy clock shutdown by Carlos Aguiar on Friday, March 14, 2008 - 3:36 pm. (1 message)

Next thread: [PATCH 0/8] NTP updates by zippel on Friday, March 14, 2008 - 2:40 pm. (3 messages)
To: Andrew Morton <akpm@...>
Cc: LKML <linux-kernel@...>, Randy Dunlap <randy.dunlap@...>
Date: Friday, March 14, 2008 - 3:58 pm

Signed-off-by: Harvey Harrison &lt;harvey.harrison@gmail.com&gt;
---
 include/linux/kernel.h |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index c74460c..d57e537 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -351,6 +351,15 @@ static inline int __attribute__ ((format (printf, 1, 2))) pr_debug(const char *
 	(void) (&amp;_max1 == &amp;_max2);		\
 	_max1 &gt; _max2 ? _max1 : _max2; })
 
+/**
+ * clamp - return a value clamped to a given range with strict typechecking
+ * @val: current value
+ * @min: minimum allowable value
+ * @max: maximum allowable value
+ *
+ * This macro does strict typechecking of min/max to make sure they are of the
+ * same type as val.  See the unnecessary pointer comparisons.
+ */
 #define clamp(val, min, max) ({			\
 	typeof(val) __val = (val);		\
 	typeof(min) __min = (min);		\
@@ -376,6 +385,16 @@ static inline int __attribute__ ((format (printf, 1, 2))) pr_debug(const char *
 	type __max2 = (y);			\
 	__max1 &gt; __max2 ? __max1: __max2; })
 
+/**
+ * clamp_t - return a value clamped to a given range using a given type
+ * @type: the type of variable to use
+ * @val: current value
+ * @min: minimum allowable value
+ * @max: maximum allowable value
+ *
+ * This macro does no typechecking and uses temporary variables of type
+ * 'type' to make all the comparisons.
+ */
 #define clamp_t(type, val, min, max) ({		\
 	type __val = (val);			\
 	type __min = (min);			\
@@ -383,6 +402,17 @@ static inline int __attribute__ ((format (printf, 1, 2))) pr_debug(const char *
 	__val = __val &lt; __min ? __min: __val;	\
 	__val &gt; __max ? __max: __val; })
 
+/**
+ * clamp_val - return a value clamped to a given range using val's type
+ * @val: current value
+ * @min: minimum allowable value
+ * @max: maximum allowable value
+ *
+ * This macro does no typechecking and uses temporary variables of whatever
+ * type the input ...
To: Harvey Harrison <harvey.harrison@...>
Cc: Andrew Morton <akpm@...>, LKML <linux-kernel@...>
Date: Friday, March 14, 2008 - 4:03 pm

Acked-by: Randy Dunlap &lt;randy.dunlap@oracle.com&gt;


---
~Randy
--
Previous thread: [PATCH 16/18] MMC: OMAP: Lazy clock shutdown by Carlos Aguiar on Friday, March 14, 2008 - 3:36 pm. (1 message)

Next thread: [PATCH 0/8] NTP updates by zippel on Friday, March 14, 2008 - 2:40 pm. (3 messages)
speck-geostationary