git: a87e584f6c9d - stable/14 - LinuxKPI: add kvmemdup()

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

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

commit a87e584f6c9d1fbe6bb47e588628aae4331c9967
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2024-05-13 17:43:25 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2024-06-12 13:57:24 +0000

    LinuxKPI: add kvmemdup()
    
    Add kvmemdup() as a variant of kmemdup().  While currently it could
    just call kmemdup() we duplicate the code and use kvmalloc() in case
    someone will change the implementation of kvmalloc/kvfree in slab.h.
    This is used by an updated wireless driver.
    
    Sponsored by:   The FreeBSD Foundation
    Reviewed by:    emaste
    Differential Revision: https://reviews.freebsd.org/D45181
    
    (cherry picked from commit 8e4b8e9d807aa379d2a1c3aaac2537ba7d6bf0bf)
---
 sys/compat/linuxkpi/common/include/linux/string.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/string.h b/sys/compat/linuxkpi/common/include/linux/string.h
index 06dcdbd97663..9302c95e8636 100644
--- a/sys/compat/linuxkpi/common/include/linux/string.h
+++ b/sys/compat/linuxkpi/common/include/linux/string.h
@@ -97,6 +97,18 @@ kmemdup(const void *src, size_t len, gfp_t gfp)
 	return (dst);
 }
 
+/* See slab.h for kvmalloc/kvfree(). */
+static inline void *
+kvmemdup(const void *src, size_t len, gfp_t gfp)
+{
+	void *dst;
+
+	dst = kvmalloc(len, gfp);
+	if (dst != NULL)
+		memcpy(dst, src, len);
+	return (dst);
+}
+
 static inline char *
 strndup_user(const char __user *ustr, long n)
 {