Errors and message printing
Error codes are interpreted either by the kernel or by the user space application (through theerrno
variable). Error handling is very important in software development, more than it is in kernel development. Fortunately, the kernel provides a couple of errors that cover almost every error you'll encounter, and sometimes you will need to print them out in order to help you debug.
Error handling
Returning the wrong error code for a given error will result in either the kernel or user space app producing unwanted behavior and making a wrong decision. To keep things clear, there are predefined errors in the kernel tree that cover almost every case you may face. Some of the errors (with their meanings) are defined in include/uapi/asm-generic/errno-base.h
, and the rest of the list can be found in include/uapi/asm-generic/errno.h.
The following is an excerpt from the list of errors, from include/uapi/asm-generic/errno-base.h
:
#define EPERM 1 /* Operation not...