Driver in kernel::auxiliary
A Rust driver in Linux is just a type that implements a Driver trait, and this page shows that trait for the auxiliary bus. Probe runs when matching hardware appears; instead of stashing state in a g…
A driver is a type that implements a trait with two moments: probe, which runs when matching hardware appears and either sets everything up or returns an error, and unbind, which runs when the hardware or the driver goes away. Probe returns your driver's state as a pinned, reference-counted value that the kernel stores and hands back on every later callback, so there is no global variable and no manual free. Because that state is owned, its Drop implementation is the real teardown, and unbind is reserved for the few things that must happen while the device is still bound. The C bug this kills is the remove function that forgets one of the eight things probe did.
A Rust driver in Linux is just a type that implements a Driver trait, and this page shows that trait for the auxiliary bus. Probe runs when matching hardware appears; instead of stashing state in a g…