accel/ivpu: Enable HWS by default on all platforms
[drm/drm-misc.git] / tools / lib / slab.c
blob959997fb0652fa43df9398615ccab8d063506681
1 // SPDX-License-Identifier: GPL-2.0
3 #include <stdio.h>
4 #include <string.h>
6 #include <urcu/uatomic.h>
7 #include <linux/slab.h>
8 #include <malloc.h>
9 #include <linux/gfp.h>
11 int kmalloc_nr_allocated;
12 int kmalloc_verbose;
14 void *kmalloc(size_t size, gfp_t gfp)
16 void *ret;
18 if (!(gfp & __GFP_DIRECT_RECLAIM))
19 return NULL;
21 ret = malloc(size);
22 uatomic_inc(&kmalloc_nr_allocated);
23 if (kmalloc_verbose)
24 printf("Allocating %p from malloc\n", ret);
25 if (gfp & __GFP_ZERO)
26 memset(ret, 0, size);
27 return ret;
30 void kfree(void *p)
32 if (!p)
33 return;
34 uatomic_dec(&kmalloc_nr_allocated);
35 if (kmalloc_verbose)
36 printf("Freeing %p to malloc\n", p);
37 free(p);