Date: Thu, 18 Jun 2020 10:47:30 +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-11@freebsd.org Subject: svn commit: r362317 - stable/11/sys/compat/linuxkpi/common/include/linux Message-ID: <202006181047.05IAlUKq082166@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202006181047.05IAlUKq082166>