Conceptual
Login

Sharing Driver State with the Kernel Arc

Several parts of a driver often need to hold the same state at once: the probe function, an interrupt handler, an open device file. The kernel's own reference-counted pointer lets each of them hold a handle, counts the handles safely across processors, and frees the state exactly when the last one goes away. It differs from the standard-library version in two ways that matter: creating it can fail, because it allocates, and it is built to work with pinned contents. Getting this wrong by hand in C is how drivers end up using freed memory after a device is unplugged.

Questions this Concept answers

  • Why does driver state shared with an interrupt handler live behind a reference-counted handle rather than behind a borrow?