Author: hselasky
Date: Tue Jun  2 10:19:45 2020
New Revision: 361723
URL: https://svnweb.freebsd.org/changeset/base/361723

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

Modified:
  head/sys/compat/linuxkpi/common/include/linux/kernel.h

Modified: head/sys/compat/linuxkpi/common/include/linux/kernel.h
==============================================================================
--- head/sys/compat/linuxkpi/common/include/linux/kernel.h      Tue Jun  2 
09:45:43 2020        (r361722)
+++ head/sys/compat/linuxkpi/common/include/linux/kernel.h      Tue Jun  2 
10:19:45 2020        (r361723)
@@ -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_ */
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to