Skip to content

Commit

Permalink
Keep ownership of spi::DriverRegistration (#46)
Browse files Browse the repository at this point in the history
* rust-module: Keep ownership of spi::DriverRegistration

* rust-module: Remove use of builder pattern
  • Loading branch information
CohenArthur authored May 4, 2021
1 parent 134ede6 commit 959ca1a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions rust-module/mfrc522.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,15 @@ impl FileOperations for Mfrc522FileOps {
Err(_) => Err(Error::EINVAL),
// FIXME: Once the Command API is reworked, this will make more sense
Ok(CommandSuccess::BytesWritten(amount)) => Ok(amount),
NoAnswer => Ok(0),
Ok(CommandSuccess::NoAnswer) => Ok(0),
_ => Err(Error::EINVAL),
}
}
}

struct Mfrc522Driver {
misc: Pin<Box<miscdev::Registration>>,
// FIXME: We need to keep ownership of our SPI registration, or else it will get dropped
// when we'll return from the init() function
_spi: Pin<Box<spi::DriverRegistration>>,
_misc: Pin<Box<miscdev::Registration>>,
}

impl KernelModule for Mfrc522Driver {
Expand All @@ -122,11 +121,12 @@ impl KernelModule for Mfrc522Driver {
let misc =
miscdev::Registration::new_pinned::<Mfrc522FileOps>(cstr!("mfrc522_chrdev"), None, ())?;

let mut spi =
spi::DriverRegistration::new(&THIS_MODULE, cstr!("mfrc522")).with_probe(mfrc522_probe);
spi.register()?;
let mut spi = spi::DriverRegistration::new_pinned(&THIS_MODULE, cstr!("mfrc522"))?;

Ok(Mfrc522Driver { misc })
Ok(Mfrc522Driver {
_spi: spi,
_misc: misc,
})
}
}

Expand Down

0 comments on commit 959ca1a

Please sign in to comment.