From patchwork Wed Jul 8 04:29:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 492720 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id A21BF140788 for ; Wed, 8 Jul 2015 14:32:24 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 56C5A4B9DD; Wed, 8 Jul 2015 06:31:46 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tnE_Cggz_iDK; Wed, 8 Jul 2015 06:31:46 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1BFE34B9AF; Wed, 8 Jul 2015 06:31:19 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E766A4B98A for ; Wed, 8 Jul 2015 06:31:11 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NiRkIHTEe8L5 for ; Wed, 8 Jul 2015 06:31:11 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from conuserg010-v.nifty.com (conuserg010.nifty.com [202.248.44.36]) by theia.denx.de (Postfix) with ESMTPS id 0D5E64B9A9 for ; Wed, 8 Jul 2015 06:30:50 +0200 (CEST) Received: from beagle.diag.org (KD111107182039.au-net.ne.jp [111.107.182.39]) (authenticated) by conuserg010-v.nifty.com with ESMTP id t684TmDj015410; Wed, 8 Jul 2015 13:29:58 +0900 X-Nifty-SrcIP: [111.107.182.39] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Wed, 8 Jul 2015 13:29:34 +0900 Message-Id: <1436329782-9179-5-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1436329782-9179-1-git-send-email-yamada.masahiro@socionext.com> References: <1436329782-9179-1-git-send-email-yamada.masahiro@socionext.com> Cc: Tom Rini , Anton Habegger , Kishon Vijay Abraham I Subject: [U-Boot] [RFC PATCH 04/12] linux_compat: handle __GFP_ZERO in kmalloc() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Currently, kzalloc() returns zero-filled memory, while kmalloc() simply ignores the second argument and never fills the memory area with zeros. I want kmalloc(size, __GFP_ZERO) to behave as kzalloc() does, which will make it easier to add more memory allocator variants. With the introduction of __GFP_ZERO flag, going forward, kzmalloc() variants can fall back to kmalloc() enabling the __GFP_ZERO flag. Signed-off-by: Masahiro Yamada Reviewed-by: Heiko Schocher Acked-by: Simon Glass --- include/linux/compat.h | 20 ++++++++++++-------- lib/linux_compat.c | 13 ++++++------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/include/linux/compat.h b/include/linux/compat.h index a3d136b..64988bf 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -36,8 +36,19 @@ extern struct p_current *current; #define KERN_INFO #define KERN_DEBUG +#define GFP_ATOMIC ((gfp_t) 0) +#define GFP_KERNEL ((gfp_t) 0) +#define GFP_NOFS ((gfp_t) 0) +#define GFP_USER ((gfp_t) 0) +#define __GFP_NOWARN ((gfp_t) 0) +#define __GFP_ZERO ((__force gfp_t)0x8000u) /* Return zeroed page on success */ + void *kmalloc(size_t size, int flags); -void *kzalloc(size_t size, int flags); + +static inline void *kzalloc(size_t size, gfp_t flags) +{ + return kmalloc(size, flags | __GFP_ZERO); +} #define vmalloc(size) kmalloc(size, 0) #define __vmalloc(size, flags, pgsz) kmalloc(size, flags) static inline void *vzalloc(unsigned long size) @@ -77,13 +88,6 @@ void *kmem_cache_alloc(struct kmem_cache *obj, int flag); /* drivers/char/random.c */ #define get_random_bytes(...) -/* idr.c */ -#define GFP_ATOMIC ((gfp_t) 0) -#define GFP_KERNEL ((gfp_t) 0) -#define GFP_NOFS ((gfp_t) 0) -#define GFP_USER ((gfp_t) 0) -#define __GFP_NOWARN ((gfp_t) 0) - /* include/linux/leds.h */ struct led_trigger {}; diff --git a/lib/linux_compat.c b/lib/linux_compat.c index 8c7a7b5..a936a7e 100644 --- a/lib/linux_compat.c +++ b/lib/linux_compat.c @@ -16,14 +16,13 @@ unsigned long copy_from_user(void *dest, const void *src, void *kmalloc(size_t size, int flags) { - return memalign(ARCH_DMA_MINALIGN, size); -} + void *p; -void *kzalloc(size_t size, int flags) -{ - void *ptr = kmalloc(size, flags); - memset(ptr, 0, size); - return ptr; + p = memalign(ARCH_DMA_MINALIGN, size); + if (flags & __GFP_ZERO) + memset(p, 0, size); + + return p; } struct kmem_cache *get_mem(int element_sz)