The kernel module's init function is to return a value of type int; this is a key aspect. The Linux kernel has evolved a style or convention, if you will, with regard to returning values from it (meaning from the kernel space to the user space process). The LKM framework follows what is colloquially referred to as the 0/-E convention:
- Upon success, return integer value 0.
- Upon failure, return the negative of the value you would like the user space global uninitialized integer errno to be set to.
Be aware that errno is a global residing in a user process VAS within the uninitialized data segment. With very few exceptions, whenever a Linux system call fails, -1 is returned and errno is set to a positive value, representing the failure code; this work is carried out by glibc "glue" code on the syscall return path.
Furthermore, the errno value is actually an index into...
Furthermore, the errno value is actually an index into...