1 /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 3 #ifndef __LINUX_KERNEL_H 4 #define __LINUX_KERNEL_H 5 6 #ifndef offsetof 7 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 8 #endif 9 10 #ifndef container_of 11 #define container_of(ptr, type, member) ({ \ 12 const typeof(((type *)0)->member) * __mptr = (ptr); \ 13 (type *)((char *)__mptr - offsetof(type, member)); }) 14 #endif 15 16 #ifndef max 17 #define max(x, y) ({ \ 18 typeof(x) _max1 = (x); \ 19 typeof(y) _max2 = (y); \ 20 (void) (&_max1 == &_max2); \ 21 _max1 > _max2 ? _max1 : _max2; }) 22 #endif 23 24 #ifndef min 25 #define min(x, y) ({ \ 26 typeof(x) _min1 = (x); \ 27 typeof(y) _min2 = (y); \ 28 (void) (&_min1 == &_min2); \ 29 _min1 < _min2 ? _min1 : _min2; }) 30 #endif 31 32 #ifndef roundup 33 #define roundup(x, y) ( \ 34 { \ 35 const typeof(y) __y = y; \ 36 (((x) + (__y - 1)) / __y) * __y; \ 37 } \ 38 ) 39 #endif 40 41 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) 42 #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) 43 44 #endif 45