Specifications
Driver Testing and Debugging
15-5
Common Driver Problems 15
Following is a discussion of some common driver bugs, with possible symptoms. These
should be used only as suggestions. Each driver is unique and can have unique bugs.
Coding Problems 15
Simple coding problems usually show up when you try to compile the driver. In general,
these are similar to coding problems for any C program, such as failure to #include nec-
essary header files, define all data structures, or properly delineate comment lines. Specific
coding errors unique to driver code include the following:
• #ifdef-related problems, such as not providing for certain combinations
• inadequate handling of error cases
• failure to use volatile where necessary
Memory-mapped device registers must be declared volatile so the compiler knows the
values might change outside of program control. Otherwise, it might cache the values in
local registers and not see changes in hardware state.
Installation Problems 15
Installation problems refer to problems that prevent a system boot with your device con-
figured. If the system won't boot, first try to boot it without the driver to verify that the
driver is the problem. Some driver problems that prevent a system boot include:
• Errors in the init or start routine. You can check that the initialization
routine is being entered by inserting an unconditional cmn_err statement
at the beginning of the routine.
• Null pointer dereferences or other use of improperly initialized pointers.
Data Structure Problems 15
A driver can corrupt the kernel data structures. If the driver is setting or clearing the wrong
bits in a device register, a write operation can put bad data on the device and a read
operation can put bad data anywhere in the kernel. Such errors can affect other drivers on
the system. Finding this bug involves painstaking walk-throughs of the code. Look for a
place where perhaps a pointer is freed (or never set) before the driver tries to access it, or
places where the code forgets to check a flag before accessing a certain structure. Other
symptoms of data structure problems are panics due to kernel data access exceptions or
misaligned data access exceptions. This can usually be traced to use of an illegal pointer.