diff options
Diffstat (limited to 'include/linux/compat.h')
-rw-r--r-- | include/linux/compat.h | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/include/linux/compat.h b/include/linux/compat.h index fbebf910ad..59937de960 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -4,6 +4,7 @@ #include <malloc.h> #include <linux/types.h> #include <linux/err.h> +#include <linux/kernel.h> struct unused {}; typedef struct unused unused_t; @@ -49,22 +50,47 @@ static inline void *kzalloc(size_t size, gfp_t flags) { return kmalloc(size, flags | __GFP_ZERO); } + +static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags) +{ + if (size != 0 && n > SIZE_MAX / size) + return NULL; + return kmalloc(n * size, flags | __GFP_ZERO); +} + +static inline void *kcalloc(size_t n, size_t size, gfp_t flags) +{ + return kmalloc_array(n, 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) { return kzalloc(size, 0); } -#define kfree(ptr) free(ptr) -#define vfree(ptr) free(ptr) +static inline void kfree(const void *block) +{ + free((void *)block); +} +static inline void vfree(const void *addr) +{ + free((void *)addr); +} struct kmem_cache { int sz; }; struct kmem_cache *get_mem(int element_sz); #define kmem_cache_create(a, sz, c, d, e) get_mem(sz) void *kmem_cache_alloc(struct kmem_cache *obj, int flag); -#define kmem_cache_free(obj, size) free(size) -#define kmem_cache_destroy(obj) free(obj) +static inline void kmem_cache_free(struct kmem_cache *cachep, void *obj) +{ + free(obj); +} +static inline void kmem_cache_destroy(struct kmem_cache *cachep) +{ + free(cachep); +} #define DECLARE_WAITQUEUE(...) do { } while (0) #define add_wait_queue(...) do { } while (0) @@ -159,6 +185,8 @@ typedef unsigned long blkcnt_t; #define class_create(...) __builtin_return_address(0) #define class_create_file(...) 0 +#define class_register(...) 0 +#define class_unregister(...) #define class_remove_file(...) #define class_destroy(...) #define misc_register(...) 0 @@ -171,6 +199,7 @@ typedef unsigned long blkcnt_t; #define dev_set_name(...) do { } while (0) #define device_register(...) 0 +#define device_unregister(...) #define volume_sysfs_init(...) 0 #define volume_sysfs_close(...) do { } while (0) |