On the discussion of return values, you now understand that the kernel module's init routine must return an integer. What if you wish to return a pointer instead? The ERR_PTR() inline function comes to our rescue, allowing us to return a pointer disguised as an integer simply by typecasting it as void *. It actually gets better: you can check for an error using the IS_ERR() inline function (which really just figures out whether the value is in the range [-1 to -4095]), encodes a negative error value into a pointer via the ERR_PTR() inline function, and retrieves this value from the pointer using the converse routine PTR_ERR().
As a simple example, see the callee code given here. This time, we have the (sample) function myfunc() return a pointer (to a structure named mystruct) and not an integer:
struct mystruct * myfunc(void)
{
struct mystruct *mys = NULL;
mys = kzalloc(sizeof(struct mystruct), GFP_KERNEL);
if (!mys)
return ERR_PTR...