xref: /openbsd/sys/dev/pci/drm/include/linux/overflow.h (revision 8e54c6d8)
1 /* Public domain. */
2 
3 #ifndef _LINUX_OVERFLOW_H
4 #define _LINUX_OVERFLOW_H
5 
6 #define array_size(x, y)	((x) * (y))
7 
8 #define struct_size(p, member, n) \
9 	(sizeof(*(p)) + ((n) * (sizeof(*(p)->member))))
10 
11 #if defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 5)
12 #define check_add_overflow(x, y, sum)	__builtin_add_overflow(x, y, sum)
13 #define check_mul_overflow(x, y, z)	__builtin_mul_overflow(x, y, z)
14 #else
15 #define check_mul_overflow(x, y, z) ({		\
16 	*(z) = (x) * (y);			\
17 	0;					\
18 })
19 #endif
20 
21 #endif
22