aboutsummaryrefslogtreecommitdiff
path: root/lib/linux_compat.c
diff options
context:
space:
mode:
authorAKASHI Takahiro <takahiro.akashi@linaro.org>2019-11-13 09:44:47 +0900
committerTom Rini <trini@konsulko.com>2019-12-06 16:44:19 -0500
commit4839e86892a6f9f8bd2449f4c622639a1ca5ea62 (patch)
treec1bec504fd9c4c9acc652678ff6277e44cd3582e /lib/linux_compat.c
parent31839dc2d2bb0ecfe0ec0d736e09c8d9d3020977 (diff)
downloadu-boot-4839e86892a6f9f8bd2449f4c622639a1ca5ea62.zip
u-boot-4839e86892a6f9f8bd2449f4c622639a1ca5ea62.tar.gz
u-boot-4839e86892a6f9f8bd2449f4c622639a1ca5ea62.tar.bz2
linux_compat: move kmemdup() from ubifs.c to linux_compat.c
linux_compat.c is the best place for kmemdup(), which is currenly used only in ubifs.c, but will also be used when other kernel files (in my case, lib/crypto/x509_cert_parser.c and pkcs7_parser.c) will be imported. So just move it. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Diffstat (limited to 'lib/linux_compat.c')
-rw-r--r--lib/linux_compat.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/linux_compat.c b/lib/linux_compat.c
index 81ea8fb..3f440de 100644
--- a/lib/linux_compat.c
+++ b/lib/linux_compat.c
@@ -40,3 +40,22 @@ void *kmem_cache_alloc(struct kmem_cache *obj, int flag)
{
return malloc_cache_aligned(obj->sz);
}
+
+/**
+ * kmemdup - duplicate region of memory
+ *
+ * @src: memory region to duplicate
+ * @len: memory region length
+ * @gfp: GFP mask to use
+ *
+ * Return: newly allocated copy of @src or %NULL in case of error
+ */
+void *kmemdup(const void *src, size_t len, gfp_t gfp)
+{
+ void *p;
+
+ p = kmalloc(len, gfp);
+ if (p)
+ memcpy(p, src, len);
+ return p;
+}