Changeset View
Changeset View
Standalone View
Standalone View
sys/compat/linuxkpi/common/include/linux/kernel.h
Show First 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | |||||
#define U16_C(x) x ## U | #define U16_C(x) x ## U | ||||
#define S32_C(x) x | #define S32_C(x) x | ||||
#define U32_C(x) x ## U | #define U32_C(x) x ## U | ||||
#define S64_C(x) x ## LL | #define S64_C(x) x ## LL | ||||
#define U64_C(x) x ## ULL | #define U64_C(x) x ## ULL | ||||
#define BUILD_BUG() do { CTASSERT(0); } while (0) | #define BUILD_BUG() do { CTASSERT(0); } while (0) | ||||
#define BUILD_BUG_ON(x) CTASSERT(!(x)) | #define BUILD_BUG_ON(x) CTASSERT(!(x)) | ||||
#ifndef BUILD_BUG_ON_MSG | |||||
#define BUILD_BUG_ON_MSG(x, msg) BUILD_BUG_ON(x) | #define BUILD_BUG_ON_MSG(x, msg) BUILD_BUG_ON(x) | ||||
#endif | |||||
#define BUILD_BUG_ON_NOT_POWER_OF_2(x) BUILD_BUG_ON(!powerof2(x)) | #define BUILD_BUG_ON_NOT_POWER_OF_2(x) BUILD_BUG_ON(!powerof2(x)) | ||||
#define BUILD_BUG_ON_INVALID(expr) while (0) { (void)(expr); } | #define BUILD_BUG_ON_INVALID(expr) while (0) { (void)(expr); } | ||||
#define BUG() panic("BUG at %s:%d", __FILE__, __LINE__) | #define BUG() panic("BUG at %s:%d", __FILE__, __LINE__) | ||||
#define BUG_ON(cond) do { \ | #define BUG_ON(cond) do { \ | ||||
if (cond) { \ | if (cond) { \ | ||||
panic("BUG ON %s failed at %s:%d", \ | panic("BUG ON %s failed at %s:%d", \ | ||||
__stringify(cond), __FILE__, __LINE__); \ | __stringify(cond), __FILE__, __LINE__); \ | ||||
▲ Show 20 Lines • Show All 265 Lines • ▼ Show 20 Lines | kstrtou32(const char *cp, unsigned int base, u32 *res) | ||||
/* skip newline character, if any */ | /* skip newline character, if any */ | ||||
if (*end == '\n') | if (*end == '\n') | ||||
end++; | end++; | ||||
if (*cp == 0 || *end != 0) | if (*cp == 0 || *end != 0) | ||||
return (-EINVAL); | return (-EINVAL); | ||||
if (temp != (u32)temp) | if (temp != (u32)temp) | ||||
return (-ERANGE); | return (-ERANGE); | ||||
return (0); | return (0); | ||||
} | |||||
static inline int | |||||
kstrtobool(const char *s, bool *res) | |||||
{ | |||||
if (!s) | |||||
return -EINVAL; | |||||
switch (s[0]) { | |||||
case 'y': | |||||
case 'Y': | |||||
case '1': | |||||
*res = true; | |||||
return 0; | |||||
case 'n': | |||||
case 'N': | |||||
case '0': | |||||
*res = false; | |||||
return 0; | |||||
case 'o': | |||||
case 'O': | |||||
switch (s[1]) { | |||||
case 'n': | |||||
case 'N': | |||||
*res = true; | |||||
return 0; | |||||
case 'f': | |||||
case 'F': | |||||
*res = false; | |||||
return 0; | |||||
default: | |||||
break; | |||||
} | |||||
default: | |||||
break; | |||||
} | |||||
return -EINVAL; | |||||
} | |||||
static inline int | |||||
kstrtobool_from_user(const char __user *s, size_t count, bool *res) | |||||
{ | |||||
char buf[4]; | |||||
count = min(count, sizeof(buf) - 1); | |||||
if (copy_from_user(buf, s, count)) | |||||
return -EFAULT; | |||||
buf[count] = '\0'; | |||||
return kstrtobool(buf, res); | |||||
} | } | ||||
#define min(x, y) ((x) < (y) ? (x) : (y)) | #define min(x, y) ((x) < (y) ? (x) : (y)) | ||||
#define max(x, y) ((x) > (y) ? (x) : (y)) | #define max(x, y) ((x) > (y) ? (x) : (y)) | ||||
#define min3(a, b, c) min(a, min(b,c)) | #define min3(a, b, c) min(a, min(b,c)) | ||||
#define max3(a, b, c) max(a, max(b,c)) | #define max3(a, b, c) max(a, max(b,c)) | ||||
▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines |