Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 18 Jun 2020 10:46:58 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r362316 - stable/12/sys/compat/linuxkpi/common/include/linux
Message-ID:  <202006181046.05IAkwCo082079@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202006181046.05IAkwCo082079>