Function register

Source
pub fn register<T, E>(
    dev: &Device<Bound>,
    data: impl PinInit<T, E>,
    flags: Flags,
) -> Result
where T: Send + 'static, Error: From<E>,
Expand description

Encapsulate data in a KBox and Drop::drop data once dev is unbound.

ยงExamples

use kernel::{device::{Bound, Device}, devres};

/// Registration of e.g. a class device, IRQ, etc.
struct Registration;

impl Registration {
    fn new() -> Self {
        // register

        Self
    }
}

impl Drop for Registration {
    fn drop(&mut self) {
       // unregister
    }
}

fn from_bound_context(dev: &Device<Bound>) -> Result {
    devres::register(dev, Registration::new(), GFP_KERNEL)
}