Interface-Specific Types
Most of the commonly used data types in the kernel have their own
typedef statements, thus preventing any portability
problems. For example, a process identifier (pid) is usually
pid_t instead of int. Using
pid_t masks any possible difference in the actual
data typing. We use the expression
interface-specific to refer to a type defined by a
library in order to provide an interface to a specific data structure.
Even when no interface-specific type is defined, it’s always important
to use the proper data type in a way consistent with the rest of the
kernel. A jiffy count, for instance, is always unsigned long, independent of its actual size, so the
unsigned long type should always be used when
working with jiffies. In this section we concentrate on use of
“_t” types.
The complete list of _t types appears in
<linux/types.h>, but the list is rarely
useful. When you need a specific type, you’ll find it in the
prototype of the functions you need to call or in the data structures
you use.
Whenever your driver uses functions that require such “custom” types and you don’t follow the convention, the compiler issues a warning; if you use the -Wall compiler flag and are careful to remove all the warnings, you can feel confident that your code is portable.
The main problem with _t data items is that when
you need to print them, it’s not always easy to choose the right
printk or printf format, and warnings you resolve on one architecture reappear on another. ...