[U-Boot] [PATCH v1 01/11] linux_compat: add kmemdup()

AKASHI Takahiro takahiro.akashi at linaro.org
Fri Oct 11 07:41:50 UTC 2019


Adding kmemdup() will help improve portability from linux kernel
code (in my case, lib/crypto/x509_cert_parser.c and pkcs7_parser.c).

Signed-off-by: AKASHI Takahiro <takahiro.akashi at linaro.org>
---
 include/linux/compat.h |  4 ++--
 lib/linux_compat.c     | 11 +++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/include/linux/compat.h b/include/linux/compat.h
index d0f51baab407..d23ef50454ce 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -117,6 +117,8 @@ static inline void kmem_cache_destroy(struct kmem_cache *cachep)
 	free(cachep);
 }
 
+void *kmemdup(const void *src, size_t size, int flags);
+
 #define DECLARE_WAITQUEUE(...)	do { } while (0)
 #define add_wait_queue(...)	do { } while (0)
 #define remove_wait_queue(...)	do { } while (0)
@@ -346,8 +348,6 @@ struct writeback_control {
 	unsigned for_sync:1;		/* sync(2) WB_SYNC_ALL writeback */
 };
 
-void *kmemdup(const void *src, size_t len, gfp_t gfp);
-
 typedef int irqreturn_t;
 
 struct timer_list {};
diff --git a/lib/linux_compat.c b/lib/linux_compat.c
index 6373b4451eb3..dd1e5b3c2087 100644
--- a/lib/linux_compat.c
+++ b/lib/linux_compat.c
@@ -40,3 +40,14 @@ void *kmem_cache_alloc(struct kmem_cache *obj, int flag)
 {
 	return malloc_cache_aligned(obj->sz);
 }
+
+void *kmemdup(const void *src, size_t size, int flags)
+{
+	void *p;
+
+	p = kmalloc(size, flags);
+	if (p)
+		memcpy(p, src, size);
+
+	return p;
+}
-- 
2.21.0



More information about the U-Boot mailing list