add kerneldoc for clamp(), clamp_t(), clamp_val() macros
PATCH 1/1 add kerneldoc for clamp(), clamp_t(), clamp_val() macros
Signed-off-by Harvey Harrison <[email protected]>
--- include/linux/kernel.h | 30 ++++++++++++++++++++++++++++++ 1 files changed, 30 insertions(+), 0 deletions(-)
include/linux/kernel.h +30 -0
@@ -351,6 +351,15 @@ static inline int __attribute__ ((format (printf, 1, 2))) pr_debug(const char * (void ) (&_max1 == &_max2); \ _max1 > _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 > __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 < __min ? __min: __val; \ __val > __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 argument 'val' is. This is useful when val is an unsigned +* type and min and max are literals that will otherwise be assigned a signed +* integer type. +*/ #define clamp_val (val, min, max) ({ \ typeof(val) __val = (val); \ typeof(val) __min = (min); \
Signature · 1 line
1.5.4.4.684.g0e08
Quoted 1 line · On Fri, 14 Mar 2008 12:58:49 -0700 Harvey Harrison wrote:
Signed-off-by Harvey Harrison <[email protected]>
Acked-by Randy Dunlap <[email protected]>
Thanks, Harvey.
Quoted 50 lines
--- include/linux/kernel.h | 30 ++++++++++++++++++++++++++++++ 1 files changed, 30 insertions(+), 0 deletions(-)include/linux/kernel.h +23
-0@@ -351,6 +351,15 @@ static inline int __attribute__ ((format (printf, 1, 2))) pr_debug(const char * (void ) (&_max1 == &_max2); \ _max1 > _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 > __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 < __min ? __min: __val; \ __val > __max ? __max: __val; }) +/** +* clamp_val - return a value clamped to a given range using val's type +* @val: current value +* @min: minimum allowable value
include/linux/kernel.h static inline int __attribute__ ((format (printf, 1, 2))) pr_debug(const char * · line 418
Quoted 10 lines
include/linux/kernel.h +7
-0+* @max: maximum allowable value +* +* This macro does no typechecking and uses temporary variables of whatever +* type the input argument 'val' is. This is useful when val is an unsigned +* type and min and max are literals that will otherwise be assigned a signed +* integer type. +*/ #define clamp_val (val, min, max) ({ \ typeof(val) __val = (val); \ typeof(val) __min = (min); \
---
~Randy