11,6 → 11,7 |
#include <linux/stddef.h> |
#include <linux/types.h> |
#include <linux/compiler.h> |
#include <linux/bitops.h> |
|
#define USHRT_MAX ((u16)(~0U)) |
#define SHRT_MAX ((s16)(USHRT_MAX>>1)) |
54,7 → 55,21 |
#define KERN_NOTICE "<5>" /* normal but significant condition */ |
#define KERN_INFO "<6>" /* informational */ |
#define KERN_DEBUG "<7>" /* debug-level messages */ |
extern const char hex_asc[]; |
#define hex_asc_lo(x) hex_asc[((x) & 0x0f)] |
#define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4] |
|
static inline char *pack_hex_byte(char *buf, u8 byte) |
{ |
*buf++ = hex_asc_hi(byte); |
*buf++ = hex_asc_lo(byte); |
return buf; |
} |
|
extern int hex_to_bin(char ch); |
extern void hex2bin(u8 *dst, const char *src, size_t count); |
|
|
//int printk(const char *fmt, ...); |
|
#define printk(fmt, arg...) dbgprintf(fmt , ##arg) |
77,6 → 92,52 |
(void) (&_max1 == &_max2); \ |
_max1 > _max2 ? _max1 : _max2; }) |
|
#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); }) |
|
#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); }) |
|
/** |
* min_not_zero - return the minimum that is _not_ zero, unless both are zero |
* @x: value1 |
* @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)); }) |
|
/** |
* 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); \ |
typeof(max) __max = (max); \ |
(void) (&__val == &__min); \ |
(void) (&__val == &__max); \ |
__val = __val < __min ? __min: __val; \ |
__val > __max ? __max: __val; }) |
|
/* |
* ..and if you can't take the strict |
* types, you can specify one yourself. |
112,18 → 173,7 |
return kzalloc(n * size, 0); |
} |
|
extern const char hex_asc[]; |
#define hex_asc_lo(x) hex_asc[((x) & 0x0f)] |
#define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4] |
|
static inline char *pack_hex_byte(char *buf, u8 byte) |
{ |
*buf++ = hex_asc_hi(byte); |
*buf++ = hex_asc_lo(byte); |
return buf; |
} |
|
|
void free (void *ptr); |
|
#endif /* __KERNEL__ */ |