Conceptual
Login

Registering Your Driver with a Bus

Implementing the driver trait does nothing until the driver is registered with its bus, and it must be unregistered before the module unloads or the kernel will later call into code that no longer exists. In Rust the registration is a value: creating it registers, dropping it unregisters, and it is stored inside your module type so unloading the module drops it automatically. An adapter layer in between converts the C callback signatures the bus expects into the safe trait methods you wrote. This makes the register-without-unregister crash, one of the ugliest failures in C module code, structurally impossible.

Questions this Concept answers

  • Why does dropping the registration value unregister the driver?