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

Heinrich Schuchardt xypron.glpk at gmx.de
Sat Oct 12 11:22:15 UTC 2019


On 10/11/19 9:41 AM, AKASHI Takahiro wrote:
> 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);

kememdup() is already implemented in fs/ubifs/ubifs.c and used both in
drivers/mtd/ and in fs/ubifs/.

Why would you want to use a different signature than both the Linux
kernel and current U-Boot?

> +
>   #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)
> +{

You should not duplicate the implementation in the UBI filesystem.
Instead move the existing implementation to a place that can be linked
in your future work.

Best regards

Heinrich

> +	void *p;
> +
> +	p = kmalloc(size, flags);
> +	if (p)
> +		memcpy(p, src, size);
> +
> +	return p;
> +}
>



More information about the U-Boot mailing list