Loading...
Searching...
No Matches
Go to the documentation of this file.
2#ifndef _LINUX_HELPER_MACROS_H_
3#define _LINUX_HELPER_MACROS_H_
8#include <linux/stddef.h>
23#define for_each_if(condition) if (!(condition)) {} else
36#define find_closest(x, a, as) \
38 typeof(as) __fc_i, __fc_as = (as) - 1; \
39 long __fc_mid_x, __fc_x = (x); \
40 long __fc_left, __fc_right; \
41 typeof(*a) const *__fc_a = (a); \
42 for (__fc_i = 0; __fc_i < __fc_as; __fc_i++) { \
43 __fc_mid_x = (__fc_a[__fc_i] + __fc_a[__fc_i + 1]) / 2; \
44 if (__fc_x <= __fc_mid_x) { \
45 __fc_left = __fc_x - __fc_a[__fc_i]; \
46 __fc_right = __fc_a[__fc_i + 1] - __fc_x; \
47 if (__fc_right < __fc_left) \
66#define find_closest_descending(x, a, as) \
68 typeof(as) __fc_i, __fc_as = (as) - 1; \
69 long __fc_mid_x, __fc_x = (x); \
70 long __fc_left, __fc_right; \
71 typeof(*a) const *__fc_a = (a); \
72 for (__fc_i = __fc_as; __fc_i >= 1; __fc_i--) { \
73 __fc_mid_x = (__fc_a[__fc_i] + __fc_a[__fc_i - 1]) / 2; \
74 if (__fc_x <= __fc_mid_x) { \
75 __fc_left = __fc_x - __fc_a[__fc_i]; \
76 __fc_right = __fc_a[__fc_i - 1] - __fc_x; \
77 if (__fc_right < __fc_left) \
136#define PTR_IF(cond, ptr) ((cond) ? (ptr) : NULL)
145#define u64_to_user_ptr(x) \
147 typecheck(u64, (x)); \
148 (void __user *)(uintptr_t)(x); \
159#define is_insidevar(ptr, var) \
160 ((uintptr_t)(ptr) >= (uintptr_t)(var) && \
161 (uintptr_t)(ptr) < (uintptr_t)(var) + sizeof(var))