svn commit: r362317 - stable/11/sys/compat/linuxkpi/common/include/linux

Hans Petter Selasky hselasky at FreeBSD.org
Thu Jun 18 10:47:30 UTC 2020


Author: hselasky
Date: Thu Jun 18 10:47:30 2020
New Revision: 362317
URL: https://svnweb.freebsd.org/changeset/base/362317

Log:
  MFC r361723:
  Implement struct_size() function macro in the LinuxKPI.
  
  Sponsored by:	Mellanox Technologies

Modified:
  stable/11/sys/compat/linuxkpi/common/include/linux/kernel.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/compat/linuxkpi/common/include/linux/kernel.h
==============================================================================
--- stable/11/sys/compat/linuxkpi/common/include/linux/kernel.h	Thu Jun 18 10:46:58 2020	(r362316)
+++ stable/11/sys/compat/linuxkpi/common/include/linux/kernel.h	Thu Jun 18 10:47:30 2020	(r362317)
@@ -527,4 +527,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-stable mailing list