git: 0e30cab0f32e - stable/15 - LinuxKPI: add __counted_by_le() and __counted_by_be()

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Thu, 23 Oct 2025 09:44:02 UTC
The branch stable/15 has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=0e30cab0f32ee40e89f59b3a287ae96c084e1e7a

commit 0e30cab0f32ee40e89f59b3a287ae96c084e1e7a
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2025-10-11 09:22:26 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2025-10-23 06:34:47 +0000

    LinuxKPI: add __counted_by_le() and __counted_by_be()
    
    The former is needed by a wireless driver at v6.17.
    
    Reviewed by:    dumbbell, emaste
    Differential Revision: https://reviews.freebsd.org/D53203
    
    (cherry picked from commit 0a4b11ddb298fa08e1a81af7337995a3769552bf)
---
 sys/compat/linuxkpi/common/include/linux/compiler.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/compiler.h b/sys/compat/linuxkpi/common/include/linux/compiler.h
index 948396144ad6..4146c829b936 100644
--- a/sys/compat/linuxkpi/common/include/linux/compiler.h
+++ b/sys/compat/linuxkpi/common/include/linux/compiler.h
@@ -31,6 +31,7 @@
 #define	_LINUXKPI_LINUX_COMPILER_H_
 
 #include <sys/cdefs.h>
+#include <sys/endian.h>
 
 #define __user
 #define __kernel
@@ -79,6 +80,13 @@
 #else
 #define	__counted_by(_x)
 #endif
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define	__counted_by_le(_x)		__counted_by(_x)
+#define	__counted_by_be(_x)
+#else
+#define	__counted_by_le(_x)
+#define	__counted_by_be(_x)		__counted_by(_x)
+#endif
 
 #define	likely(x)			__builtin_expect(!!(x), 1)
 #define	unlikely(x)			__builtin_expect(!!(x), 0)