From mboxrd@z Thu Jan 1 00:00:00 1970 From: AKASHI Takahiro Date: Fri, 11 Oct 2019 16:41:50 +0900 Subject: [U-Boot] [PATCH v1 01/11] linux_compat: add kmemdup() In-Reply-To: <20191011074200.30269-1-takahiro.akashi@linaro.org> References: <20191011074200.30269-1-takahiro.akashi@linaro.org> Message-ID: <20191011074200.30269-2-takahiro.akashi@linaro.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 --- 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