mirror of
				https://github.com/smaeul/u-boot.git
				synced 2025-11-03 21:48:15 +00:00 
			
		
		
		
	At present dm/device.h includes the linux-compatible features. This requires including linux/compat.h which in turn includes a lot of headers. One of these is malloc.h which we thus end up including in every file in U-Boot. Apart from the inefficiency of this, it is problematic for sandbox which needs to use the system malloc() in some files. Move the compatibility features into a separate header file. Signed-off-by: Simon Glass <sjg@chromium.org>
		
			
				
	
	
		
			63 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			63 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
 | 
						|
#include <common.h>
 | 
						|
#include <malloc.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);
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
 * 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;
 | 
						|
}
 |