• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
2 
3 #ifndef __LINUX_KERNEL_H
4 #define __LINUX_KERNEL_H
5 
6 #include <linux/build_bug.h>
7 
8 #ifndef container_of
9 #define container_of(ptr, type, member) ({			\
10 	const typeof(((type *)0)->member) * __mptr = (ptr);	\
11 	(type *)((char *)__mptr - offsetof(type, member)); })
12 #endif
13 
14 #ifndef max
15 #define max(x, y) ({				\
16 	typeof(x) _max1 = (x);			\
17 	typeof(y) _max2 = (y);			\
18 	(void) (&_max1 == &_max2);		\
19 	_max1 > _max2 ? _max1 : _max2; })
20 #endif
21 
22 #ifndef roundup
23 #define roundup(x, y) (				\
24 {						\
25 	const typeof(y) __y = y;		\
26 	(((x) + (__y - 1)) / __y) * __y;	\
27 }						\
28 )
29 #endif
30 
31 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
32 #define __round_mask(x, y) ((__typeof__(x))((y)-1))
33 #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
34 
35 #endif
36