git: 0f87cc98f926 - stable/13 - LinuxKPI: add __counted_by() and __nonstring

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Wed, 12 Jun 2024 19:16:46 UTC
The branch stable/13 has been updated by bz:

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

commit 0f87cc98f92691957a253b78a5b6fba5f1824ea9
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2024-04-02 09:41:54 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2024-06-12 16:57:46 +0000

    LinuxKPI: add __counted_by() and __nonstring
    
    Add checks for __counted_by(_x) and __nonstring as and depending
    on compiler support enable the attribute/feature.
    
    This is needed to make mtk76 and ath1xk drivers compile.
    
    Sposnored by:   The FreeBSD Foundation
    Reviewed by:    emaste, dim
    Differential Revision: https://reviews.freebsd.org/D44587
    
    (cherry picked from commit 2a8c50592f7fce8bceedf004f674a5a9eae0fd46)
---
 sys/compat/linuxkpi/common/include/linux/compiler.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/compiler.h b/sys/compat/linuxkpi/common/include/linux/compiler.h
index 22300e73652d..94595b2e8c50 100644
--- a/sys/compat/linuxkpi/common/include/linux/compiler.h
+++ b/sys/compat/linuxkpi/common/include/linux/compiler.h
@@ -66,6 +66,17 @@
 #define	____cacheline_aligned_in_smp	__aligned(CACHE_LINE_SIZE)
 #define	fallthrough			/* FALLTHROUGH */ do { } while(0)
 
+#if __has_attribute(__nonstring__)
+#define	__nonstring			__attribute__((__nonstring__))
+#else
+#define	__nonstring
+#endif
+#if __has_attribute(__counted_by__)
+#define	__counted_by(_x)		__attribute__((__counted_by__(_x)))
+#else
+#define	__counted_by(_x)
+#endif
+
 #define	likely(x)			__builtin_expect(!!(x), 1)
 #define	unlikely(x)			__builtin_expect(!!(x), 0)
 #define typeof(x)			__typeof(x)