u-boot/lib/linux_compat.c
Marek Szyprowski 2ad98ab8f6 linux_compat: fix potential NULL pointer access
malloc_cache_aligned() might return zero, so fix potential NULL pointer
access if __GFP_ZERO flag is set.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Reviewed-by: Ralph Siemsen <ralph.siemsen@linaro.org>
2019-10-31 07:22:53 -04:00

42 lines
729 B
C

#include <common.h>
#include <memalign.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 = malloc_cache_aligned(size);
if (p && 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 malloc_cache_aligned(obj->sz);
}