diff mbox series

[U-Boot,v3,01/16] linux_compat: move kmemdup() from ubifs.c to linux_compat.c

Message ID 20191113004502.29986-2-takahiro.akashi@linaro.org
State Accepted
Commit 4839e86892a6f9f8bd2449f4c622639a1ca5ea62
Delegated to: Tom Rini
Headers show
Series import x509/pkcs7 parsers from linux | expand

Commit Message

AKASHI Takahiro Nov. 13, 2019, 12:44 a.m. UTC
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>
---
 fs/ubifs/ubifs.c   | 19 +------------------
 lib/linux_compat.c | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 18 deletions(-)

Comments

Heinrich Schuchardt Nov. 26, 2019, 3:20 a.m. UTC | #1
On 11/13/19 1:44 AM, AKASHI Takahiro wrote:
> 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>

km_kirkwood_defconfig with CONFIG_UBIFS=y compiles.

Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tom Rini Dec. 6, 2019, 9:48 p.m. UTC | #2
On Wed, Nov 13, 2019 at 09:44:47AM +0900, AKASHI Takahiro wrote:

> 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>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c
index 67a0e8caae70..1ffdfe0d9089 100644
--- a/fs/ubifs/ubifs.c
+++ b/fs/ubifs/ubifs.c
@@ -18,6 +18,7 @@ 
 #include "ubifs.h"
 #include <u-boot/zlib.h>
 
+#include <linux/compat.h>
 #include <linux/err.h>
 #include <linux/lzo.h>
 
@@ -70,24 +71,6 @@  struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT];
 
 
 #ifdef __UBOOT__
-/* from mm/util.c */
-
-/**
- * kmemdup - duplicate region of memory
- *
- * @src: memory region to duplicate
- * @len: memory region length
- * @gfp: GFP mask to use
- */
-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;
-}
 
 struct crypto_comp {
 	int compressor;
diff --git a/lib/linux_compat.c b/lib/linux_compat.c
index 81ea8fb126fa..3f440deaa0d8 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;
+}