Implement struct_size() function macro in the LinuxKPI.

MFC after:	1 week
Sponsored by:	Mellanox Technologies
This commit is contained in:
hselasky 2020-06-02 10:19:45 +00:00
parent 7f08027678
commit 8c32f0d8ad

View File

@ -555,4 +555,10 @@ linux_ratelimited(linux_ratelimit_t *rl)
return (ppsratecheck(&rl->lasttime, &rl->counter, 1));
}
#define struct_size(ptr, field, num) ({ \
const size_t __size = offsetof(__typeof(*(ptr)), field); \
const size_t __max = (SIZE_MAX - __size) / sizeof((ptr)->field[0]); \
((num) > __max) ? SIZE_MAX : (__size + sizeof((ptr)->field[0]) * (num)); \
})
#endif /* _LINUX_KERNEL_H_ */