Return Conventions
Prev | Chapter 10. Routines and Conventions | Next

## Return Conventions

For code called in user context, it's very common to defy C convention, and return 0 for success, and a negative error number (eg. -EFAULT) for failure. This can be unintuitive at first, but it's fairly widespread in the kernel.

Using `ERR_PTR()` `include/linux/err.h`; to encode a negative error number into a pointer, and `IS_ERR()` and `PTR_ERR()` to get it back out again: avoids a separate pointer parameter for the error number. Icky, but in a good way.

Prev | Up | Next
Chapter 10. Routines and Conventions | Home | Breaking Compilation