These two functions are defined in INCLUDE/LINUX/SLAB_DEF.H and are implemented as follows:
static inline void *kmalloc (size_t size, gfp_t flags)
{
if (__builtin_constant_p (size)) {
int i = 0;
#define CACHE (x)/
if (size <= x)/
Goto found; /
else/
i++;
#include "Kmalloc_sizes.h"
#undef CACHE
{
extern void __you_cannot_kmalloc_that_much (void);
__you_cannot_kmalloc_that_much ();
}
Found
#ifdef CONFIG_ZONE_DMA
if (Flags & GFP_DMA)
Return Kmem_cache_alloc (Malloc_sizes[i].cs_dmacachep,
Flags);
#endif
Return Kmem_cache_alloc (Malloc_sizes[i].cs_cachep, flags);
}
Return __kmalloc (size, flags);
}
static inline void *kzalloc (size_t size, gfp_t flags)
{
if (__builtin_constant_p (size)) {
int i = 0;
#define CACHE (x)/
if (size <= x)/
Goto found; /
else/
i++;
#include "Kmalloc_sizes.h"
#undef CACHE
{
extern void __you_cannot_kzalloc_that_much (void);
__you_cannot_kzalloc_that_much ();
}
Found
#ifdef CONFIG_ZONE_DMA
if (Flags & GFP_DMA)
Return Kmem_cache_zalloc (Malloc_sizes[i].cs_dmacachep,
Flags);
#endif
Return Kmem_cache_zalloc (Malloc_sizes[i].cs_cachep, flags);
}
Return __kzalloc (size, flags);
}
In both functions, depending on whether the size is a compile-time constant, but as VDSP5 does not support the __builtin_constant_p macro when porting, the two functions are changed directly to:
static inline void *kmalloc (size_t size, gfp_t flags)
{
if (__builtin_constant_p (size)) {
int i = 0;
#define CACHE (x)/
if (size <= x)/
Goto found; /
else/
i++;
#include "Kmalloc_sizes.h"
#undef CACHE
// {
extern void __you_cannot_kmalloc_that_much (void);
__you_cannot_kmalloc_that_much ();
// }
Found
#ifdef CONFIG_ZONE_DMA
if (Flags & GFP_DMA)
Return Kmem_cache_alloc (Malloc_sizes[i].cs_dmacachep,
Flags);
#endif
Return Kmem_cache_alloc (Malloc_sizes[i].cs_cachep, flags);
}
Return __kmalloc (size, flags);
}
static inline void *kzalloc (size_t size, gfp_t flags)
{
if (__builtin_constant_p (size)) {
int i = 0;
#define CACHE (x)/
if (size <= x)/
Goto found; /
else/
i++;
#include "Kmalloc_sizes.h"
#undef CACHE
// {
extern void __you_cannot_kzalloc_that_much (void);
__you_cannot_kzalloc_that_much ();
// }
Found
#ifdef CONFIG_ZONE_DMA
if (Flags & GFP_DMA)
Return Kmem_cache_zalloc (Malloc_sizes[i].cs_dmacachep,
Flags);
#endif
Return Kmem_cache_zalloc (Malloc_sizes[i].cs_cachep, flags);
}
Return __kzalloc (size, flags);
}
Although the performance will be slightly affected, but also to complete the correct function.