git: af4fb0c0fe1c - stable/13 - linuxkpi: Add some memset functions

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Wed, 07 Sep 2022 15:10:09 UTC
The branch stable/13 has been updated by manu:

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

commit af4fb0c0fe1ce5b8e06aaedcb1e653ff6abe0c60
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2022-07-26 09:28:11 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2022-09-07 15:09:03 +0000

    linuxkpi: Add some memset functions
    
    Needed by drm-kmod
    
    Obtained from:  OpenBSD
    Sponsored by:   Beckhoff Automation GmbH & Co. KG
    Differential Revision:  https://reviews.freebsd.org/D35943
    
    (cherry picked from commit fa1f02baafd3d46e9d09a3715be23e96b601d9c9)
---
 sys/compat/linuxkpi/common/include/linux/string.h | 33 ++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/sys/compat/linuxkpi/common/include/linux/string.h b/sys/compat/linuxkpi/common/include/linux/string.h
index 73a38dc42c6c..7a118bb17c48 100644
--- a/sys/compat/linuxkpi/common/include/linux/string.h
+++ b/sys/compat/linuxkpi/common/include/linux/string.h
@@ -38,6 +38,7 @@
 #include <linux/slab.h>
 #include <linux/uaccess.h>
 #include <linux/err.h>
+#include <linux/bitops.h> /* for BITS_PER_LONG */
 
 #include <sys/libkern.h>
 
@@ -196,4 +197,34 @@ strscpy(char* dst, const char* src, size_t len)
 	return (-E2BIG);
 }
 
-#endif					/* _LINUXKPI_LINUX_STRING_H_ */
+static inline void *
+memset32(uint32_t *b, uint32_t c, size_t len)
+{
+	uint32_t *dst = b;
+
+	while (len--)
+		*dst++ = c;
+	return (b);
+}
+
+static inline void *
+memset64(uint64_t *b, uint64_t c, size_t len)
+{
+	uint64_t *dst = b;
+
+	while (len--)
+		*dst++ = c;
+	return (b);
+}
+
+static inline void *
+memset_p(void **p, void *v, size_t n)
+{
+
+	if (BITS_PER_LONG == 32)
+		return (memset32((uint32_t *)p, (uintptr_t)v, n));
+	else
+		return (memset64((uint64_t *)p, (uintptr_t)v, n));
+}
+
+#endif	/* _LINUXKPI_LINUX_STRING_H_ */