mirror of
https://github.com/brain-hackers/u-boot-brain
synced 2024-08-30 13:58:51 +09:00
![Masahiro Yamada](/assets/img/avatar_default.png)
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 <yamada.masahiro@socionext.com> Reviewed-by: Heiko Schocher <hs@denx.de> Acked-by: Simon Glass <sjg@chromium.org> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
42 lines
716 B
C
42 lines
716 B
C
|
|
#include <common.h>
|
|
#include <linux/compat.h>
|
|
|
|
struct p_current cur = {
|
|
.pid = 1,
|
|
};
|
|
__maybe_unused struct p_current *current = &cur;
|
|
|
|
unsigned long copy_from_user(void *dest, const void *src,
|
|
unsigned long count)
|
|
{
|
|
memcpy((void *)dest, (void *)src, count);
|
|
return 0;
|
|
}
|
|
|
|
void *kmalloc(size_t size, int flags)
|
|
{
|
|
void *p;
|
|
|
|
p = memalign(ARCH_DMA_MINALIGN, size);
|
|
if (flags & __GFP_ZERO)
|
|
memset(p, 0, size);
|
|
|
|
return p;
|
|
}
|
|
|
|
struct kmem_cache *get_mem(int element_sz)
|
|
{
|
|
struct kmem_cache *ret;
|
|
|
|
ret = memalign(ARCH_DMA_MINALIGN, sizeof(struct kmem_cache));
|
|
ret->sz = element_sz;
|
|
|
|
return ret;
|
|
}
|
|
|
|
void *kmem_cache_alloc(struct kmem_cache *obj, int flag)
|
|
{
|
|
return memalign(ARCH_DMA_MINALIGN, obj->sz);
|
|
}
|