Of course, you must free the allocated slab memory you allocated at some point in the future (thus not leaking memory); the kfree() routine serves this purpose. Analogous to the user space free(3) API, kfree() takes a single parameter – the pointer to the memory chunk to free. It must be a valid kernel logical (or virtual) address and must have been initialized by, that is, the return value of, one of the slab layer APIs (k[m|z]alloc() or one of its helpers). Its API signature is simple:
void kfree(const void *);
Just as with free(3), there is no return value. As mentioned before, take care to ensure that the parameter to kfree() is the precise value returned by k[m|z]alloc(). Passing an incorrect value will result in memory corruption, ultimately leading to an unstable system.
There are a few additional points to note.
Let's assume we have allocated some slab memory with kzalloc():
static char *kptr...