svn commit: r362316 - stable/12/sys/compat/linuxkpi/common/include/linux
Hans Petter Selasky
hselasky at FreeBSD.org
Thu Jun 18 10:46:58 UTC 2020
Author: hselasky
Date: Thu Jun 18 10:46:58 2020
New Revision: 362316
URL: https://svnweb.freebsd.org/changeset/base/362316
Log:
MFC r361723:
Implement struct_size() function macro in the LinuxKPI.
Sponsored by: Mellanox Technologies
Modified:
stable/12/sys/compat/linuxkpi/common/include/linux/kernel.h
Directory Properties:
stable/12/ (props changed)
Modified: stable/12/sys/compat/linuxkpi/common/include/linux/kernel.h
==============================================================================
--- stable/12/sys/compat/linuxkpi/common/include/linux/kernel.h Thu Jun 18 10:46:05 2020 (r362315)
+++ stable/12/sys/compat/linuxkpi/common/include/linux/kernel.h Thu Jun 18 10:46:58 2020 (r362316)
@@ -534,4 +534,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_ */
More information about the svn-src-all
mailing list