Implement struct_size() function macro in the LinuxKPI.

MFC after:	1 week
Sponsored by:	Mellanox Technologies
This commit is contained in:
Hans Petter Selasky 2020-06-02 10:19:45 +00:00
parent c185f13b92
commit ef5f8c18b5

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_ */